Skip to content

Commit

Permalink
Merge pull request #1 from runtrizapps/fork/jison-es
Browse files Browse the repository at this point in the history
Fork jison to jison-es
  • Loading branch information
davidgovea authored Aug 21, 2019
2 parents bcf986e + 3022307 commit 491172a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Jison
jison-es
=====
* [issues](http://github.com/zaach/jison/issues)
* [discuss](mailto:[email protected])

[![build status](https://secure.travis-ci.org/zaach/jison.png)](http://travis-ci.org/zaach/jison)
A minimal fork of [Jison](https://github.com/zaach/jison) for generating ES module parser files.

---

https://github.com/zaach/jison

An API for creating parsers in JavaScript
-----------------------------------------
Expand Down Expand Up @@ -50,7 +52,7 @@ Full cli option list:
-j, --json force jison to expect a grammar in JSON format
-o FILE, --outfile FILE Filename and base module name of the generated parser
-t, --debug Debug mode
-m TYPE, --module-type TYPE The type of module to generate (commonjs, amd, js)
-m TYPE, --module-type TYPE The type of module to generate (**es**, commonjs, amd, js)
-p TYPE, --parser-type TYPE The type of algorithm to use for the parser (lr0, slr, lalr, lr)
-V, --version print version and exit

Expand Down
4 changes: 2 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ function getCommandlineOptions () {
.option('module-type', {
abbr : 'm',
default:
'commonjs',
'es',
metavar : 'TYPE',
help : 'The type of module to generate (commonjs, amd, js)'
help : 'The type of module to generate (es, commonjs, amd, js)'
})
.option('parser-type', {
abbr : 'p',
Expand Down
22 changes: 22 additions & 0 deletions lib/jison.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,9 @@ lrGeneratorMixin.generate = function parser_generate (opt) {
case "amd":
code = this.generateAMDModule(opt);
break;
case "es":
code = this.generateESModule(opt);
break;
default:
code = this.generateCommonJSModule(opt);
break;
Expand All @@ -962,6 +965,25 @@ lrGeneratorMixin.generateAMDModule = function generateAMDModule(opt){
return out;
};

lrGeneratorMixin.generateESModule = function generateESModule(opt){
opt = typal.mix.call({}, this.options, opt);
var module = this.generateModule_();
var out = module.commonCode
+ '\nvar parser = '+ module.moduleCode
+ "\n"+this.moduleInclude
+ (this.lexer && this.lexer.generateModule ?
'\n' + this.lexer.generateModule() +
'\nparser.lexer = lexer;' : '')
+ '\nfunction Parser() { this.yy = {} };'
+ '\nParser.prototype = parser;'
+ '\nparser.Parser = Parser;'
+ '\nexport {parser, Parser};'
;

return out;
};


lrGeneratorMixin.generateCommonJSModule = function generateCommonJSModule (opt) {
opt = typal.mix.call({}, this.options, opt);
var moduleName = opt.moduleName || "parser";
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"author": "Zach Carter <[email protected]> (http://zaa.ch)",
"name": "jison",
"description": "A parser generator with Bison's API",
"contributors": ["David Govea <[email protected]>"],
"name": "jison-es",
"description": "Fork of jison that emits parsers as ES modules",
"version": "0.4.18",
"license": "MIT",
"keywords": [
Expand All @@ -18,11 +19,10 @@
"preferGlobal": true,
"repository": {
"type": "git",
"url": "git://github.com/zaach/jison.git"
"url": "git://github.com/runtrizapps/jison-es.git"
},
"bugs": {
"email": "[email protected]",
"url": "http://github.com/zaach/jison/issues"
"url": "http://github.com/runtrizapps/jison-es/issues"
},
"main": "lib/jison",
"bin": "lib/cli.js",
Expand Down

0 comments on commit 491172a

Please sign in to comment.