Permalink
Browse files

seperate executable for narwhal

  • Loading branch information...
1 parent 4f27fcd commit cb91401b60f3f981304ab4c485e5edb03cc5d5ea @zaach committed Jul 31, 2011
Showing with 35 additions and 1 deletion.
  1. +35 −1 bin/jison
View
@@ -1,3 +1,37 @@
#!/usr/bin/env narwhal
-require('jison/cli-wrapper').main(system.args);
+var JISON = require('../lib/jison');
+ IO = require('../lib/jison/util/io');
+
+var main = function (argv) {
+ var args = argv.slice(1);
+
+ if (args.length) {
+ var raw = IO.read(IO.join(IO.cwd(),args[0])),
+ name = IO.basename(args[0]).replace(/\..*$/g,''),
+ lex;
+ if (args[1]) {
+ lex = IO.read(IO.join(IO.cwd(),args[1]));
+ }
+ IO.write(name+'.js', processGrammar(raw, lex, name));
+ } else {
+ IO.stdin(function (raw) {
+ read = true;
+ IO.stdout(processGrammar(raw));
+ });
+ }
+}
+
+function processGrammar (rawGrammar, lex, name) {
+ var grammar = require("../lib/jison/bnf").parse(rawGrammar);
+ var opt = grammar.options || {};
+ if (lex) grammar.lex = require("../lib/jison/jisonlex").parse(lex);
+ if (!opt.moduleType) opt.moduleType = "commonjs";
+ if (!opt.moduleName && name) opt.moduleName = name.replace(/-\w/g, function (match){ return match.charAt(1).toUpperCase(); });
+
+ var generator = new JISON.Generator(grammar, opt);
+ return generator.generate(opt);
+}
+
+main(IO.args);
+

0 comments on commit cb91401

Please sign in to comment.