Permalink
Browse files

add commandline option to specify module type (issue #88)

  • Loading branch information...
1 parent 5cab11a commit 91d8ef3b5b8fa0cad22a2d370c00ee796cc18cb9 @zaach committed Mar 2, 2012
Showing with 11 additions and 4 deletions.
  1. +3 −2 lib/jison.js
  2. +8 −2 lib/jison/cli-wrapper.js
View
@@ -897,8 +897,9 @@ lrGeneratorMixin.generateAMDModule = function generateAMDModule(opt){
opt = typal.mix.call({}, this.options, opt);
var out = 'define([], function(){'
+ '\nvar parser = '+ this.generateModule_(opt)
- + '\n' + this.lexer.generateModule()
- + '\nparser.lexer = lexer;'
+ + (this.lexer && this.lexer.generateModule ?
+ '\n' + this.lexer.generateModule() +
+ '\nparser.lexer = lexer;' : '')
+ '\nreturn parser;'
+ '\n});'
return out;
View
@@ -22,6 +22,11 @@ var opts = [
"default": false,
help: 'Use debug mode'
},
+ { name: 'moduleType',
+ string: '-m, --module-type',
+ "default": "commonjs",
+ help: 'The type of module to generate (commonjs, amd, js)'
+ },
{ name: 'version',
string: '-V, --version',
help: 'Version number'
@@ -74,13 +79,14 @@ function processGrammar (rawGrammar, lex, name) {
try {
grammar = JSON.parse(rawGrammar);
} catch (e2) {
- throw e
+ throw e;
}
}
var opt = grammar.options || {};
if (lex) grammar.lex = require("./jisonlex").parse(lex);
opt.debug = args.debug;
- if (!opt.moduleType) opt.moduleType = "commonjs";
+ console.log(args);
+ if (!opt.moduleType) opt.moduleType = args.moduleType;
if (!opt.moduleName && name) opt.moduleName = name.replace(/-\w/g, function (match){ return match.charAt(1).toUpperCase(); });
var generator = new JISON.Generator(grammar, opt);

1 comment on commit 91d8ef3

Great! thanks so much.

Please sign in to comment.