-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8132b7d
Showing
7 changed files
with
1,476 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# jison-lex | ||
A lexical analyzer generator used by [jison](http://jison.org). | ||
|
||
## install | ||
npm install jison-lex -g | ||
|
||
## usage | ||
``` | ||
Usage: jison-lex [file] [options] | ||
file file containing a lexical grammar | ||
Options: | ||
-o FILE, --outfile FILE Filename and base module name of the generated parser | ||
-t TYPE, --module-type TYPE The type of module to generate (commonjs, js) | ||
--version print version and exit | ||
``` | ||
|
||
## license | ||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env node | ||
|
||
var version = require('./package.json').version; | ||
|
||
var path = require('path'); | ||
var fs = require('fs'); | ||
var lexParser = require('lex-parser'); | ||
var RegExpLexer = require('./regexp-lexer.js'); | ||
|
||
|
||
var opts = require("nomnom") | ||
.script('jison-lex') | ||
.option('file', { | ||
flag: true, | ||
position: 0, | ||
help: 'file containing a lexical grammar' | ||
}) | ||
.option('outfile', { | ||
abbr: 'o', | ||
metavar: 'FILE', | ||
help: 'Filename and base module name of the generated parser' | ||
}) | ||
.option('module-type', { | ||
abbr: 't', | ||
default: 'commonjs', | ||
metavar: 'TYPE', | ||
help: 'The type of module to generate (commonjs, js)' | ||
}) | ||
.option('version', { | ||
flag: true, | ||
help: 'print version and exit', | ||
callback: function() { | ||
return version; | ||
} | ||
}) | ||
.parse(); | ||
|
||
exports.main = function () { | ||
if (opts.file) { | ||
var raw = fs.readFileSync(path.normalize(opts.file), 'utf8'), | ||
name = path.basename((opts.outfile||opts.file)).replace(/\..*$/g,''); | ||
|
||
fs.writeFileSync(opts.outfile||(name + '.js'), processGrammar(raw, name)); | ||
} else { | ||
readin(function (raw) { | ||
console.log(processGrammar(raw)); | ||
}); | ||
} | ||
}; | ||
|
||
function processGrammar (file, name) { | ||
var grammar; | ||
try { | ||
grammar = lexParser.parse(file); | ||
} catch (e) { | ||
try { | ||
grammar = JSON.parse(file); | ||
} catch (e2) { | ||
throw e; | ||
} | ||
} | ||
|
||
var settings = grammar.options || {}; | ||
if (!settings.moduleType) settings.moduleType = opts.moduleType; | ||
if (!settings.moduleName && name) settings.moduleName = name.replace(/-\w/g, function (match){ return match.charAt(1).toUpperCase(); }); | ||
|
||
grammar.options = settings; | ||
|
||
var lexer = new RegExpLexer(grammar); | ||
return lexer.generate(settings); | ||
} | ||
|
||
function readin (cb) { | ||
var stdin = process.openStdin(), | ||
data = ''; | ||
|
||
stdin.setEncoding('utf8'); | ||
stdin.addListener('data', function (chunk) { | ||
data += chunk; | ||
}); | ||
stdin.addListener('end', function () { | ||
cb(data); | ||
}); | ||
} | ||
|
||
if (require.main === module) | ||
exports.main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"author": "Zach Carter <[email protected]> (http://zaa.ch)", | ||
"name": "jison-lex", | ||
"description": "lexical analyzer generator used by jison", | ||
"version": "0.0.1", | ||
"keywords": [ | ||
"jison", | ||
"parser", | ||
"generator", | ||
"lexer", | ||
"flex", | ||
"tokenizer" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/zaach/jison-lex.git" | ||
}, | ||
"bugs": { | ||
"email": "[email protected]", | ||
"url": "http://github.com/zaach/jison-lex/issues" | ||
}, | ||
"main": "regexp-lexer", | ||
"bin": "cli.js", | ||
"engines": { | ||
"node": ">=0.4" | ||
}, | ||
"dependencies": { | ||
"lex-parser": "0.0.1", | ||
"nomnom": "1.5.2" | ||
}, | ||
"devDependencies": { | ||
"test": "0.4.4" | ||
}, | ||
"scripts": { | ||
"test": "node tests/all-tests.js" | ||
}, | ||
"directories": { | ||
"lib": "lib", | ||
"tests": "tests" | ||
}, | ||
"homepage": "http://jison.org" | ||
} |
Oops, something went wrong.