Comparing version 0.4.11 to 0.4.13
@@ -287,9 +287,18 @@ // Jison, an LR(0), SLR(1), LARL(1), LR(1) Parser Generator | ||
for (i=0;i<rhs.length;i++) { | ||
if (names[rhs[i]]) { | ||
names[rhs[i]+(++count[rhs[i]])] = i+1; | ||
// check for aliased names, e.g., id[alias] | ||
var rhs_i = rhs[i].match(/\[[a-zA-Z][a-zA-Z0-9_-]*\]/); | ||
if (rhs_i) { | ||
rhs_i = rhs_i[0].substr(1, rhs_i[0].length-2); | ||
rhs[i] = rhs[i].substr(0, rhs[i].indexOf('[')); | ||
} else { | ||
names[rhs[i]] = i+1; | ||
names[rhs[i]+"1"] = i+1; | ||
count[rhs[i]] = 1; | ||
rhs_i = rhs[i]; | ||
} | ||
if (names[rhs_i]) { | ||
names[rhs_i + (++count[rhs_i])] = i+1; | ||
} else { | ||
names[rhs_i] = i+1; | ||
names[rhs_i + "1"] = i+1; | ||
count[rhs_i] = 1; | ||
} | ||
} | ||
@@ -316,2 +325,4 @@ action = action.replace(/\$([a-zA-Z][a-zA-Z0-9_]*)/g, function (str, pl) { | ||
// done with aliases; strip them. | ||
rhs = rhs.map(function(e,i) { return e.replace(/\[[a-zA-Z_][a-zA-Z0-9_-]*\]/g, '') }); | ||
r = new Production(symbol, rhs, productions.length+1); | ||
@@ -323,2 +334,4 @@ // precedence specified also | ||
} else { | ||
// no action -> don't care about aliases; strip them. | ||
rhs = rhs.map(function(e,i) { return e.replace(/\[[a-zA-Z_][a-zA-Z0-9_-]*\]/g, '') }); | ||
// only precedence specified | ||
@@ -331,2 +344,4 @@ r = new Production(symbol, rhs, productions.length+1); | ||
} else { | ||
// no action -> don't care about aliases; strip them. | ||
handle = handle.replace(/\[[a-zA-Z_][a-zA-Z0-9_-]*\]/g, ''); | ||
rhs = handle.trim().split(' '); | ||
@@ -945,2 +960,3 @@ for (i=0; i<rhs.length; i++) { | ||
+ '\nvar parser = '+ this.generateModule_(opt) | ||
+ "\n"+this.moduleInclude | ||
+ (this.lexer && this.lexer.generateModule ? | ||
@@ -947,0 +963,0 @@ '\n' + this.lexer.generateModule() + |
@@ -5,3 +5,3 @@ { | ||
"description": "A parser generator with Bison's API", | ||
"version": "0.4.11", | ||
"version": "0.4.13", | ||
"keywords": [ | ||
@@ -37,3 +37,3 @@ "jison", | ||
"jison-lex": "0.2.x", | ||
"ebnf-parser": "~0.1.8", | ||
"ebnf-parser": "~0.1.9", | ||
"lex-parser": "~0.1.3", | ||
@@ -44,5 +44,5 @@ "nomnom": "1.5.2", | ||
"devDependencies": { | ||
"test": "0.4.4", | ||
"test": "0.6.x", | ||
"jison": "0.4.x", | ||
"uglify-js": "1.3.3", | ||
"uglify-js": "~2.4.0", | ||
"browserify": "2.x.x" | ||
@@ -49,0 +49,0 @@ }, |
@@ -463,1 +463,45 @@ var Jison = require("../setup").Jison, | ||
}; | ||
exports["test symbol aliases"] = function() { | ||
var lexData = { | ||
rules: [ | ||
["a", "return 'a';"], | ||
["b", "return 'b';"], | ||
["c", "return 'c';"] | ||
] | ||
}; | ||
var grammar = { | ||
bnf: { | ||
"pgm" :[ ["expr[alice] expr[bob] expr[carol]", "return $alice+$bob+$carol;"] ], | ||
"expr" :[ ["a", "$$ = 'a';"], | ||
["b", "$$ = 'b';"], | ||
["c", "$$ = 'c';"] ] | ||
} | ||
}; | ||
var parser = new Jison.Parser(grammar); | ||
parser.lexer = new RegExpLexer(lexData); | ||
assert.equal(parser.parse('abc'), "abc", "should return original string"); | ||
}; | ||
exports["test symbol aliases in ebnf"] = function() { | ||
var lexData = { | ||
rules: [ | ||
["a", "return 'a';"], | ||
["b", "return 'b';"], | ||
["c", "return 'c';"] | ||
] | ||
}; | ||
var grammar = { | ||
ebnf: { | ||
"pgm" :[ ["expr[alice] (expr[bob] expr[carol])+", "return $alice+$2;"] ], | ||
"expr" :[ ["a", "$$ = 'a';"], | ||
["b", "$$ = 'b';"], | ||
["c", "$$ = 'c';"] ] | ||
} | ||
}; | ||
var parser = new Jison.Parser(grammar); | ||
parser.lexer = new RegExpLexer(lexData); | ||
assert.equal(parser.parse('abc'), "ab", "should tolerate aliases in subexpression"); | ||
}; |
@@ -326,1 +326,24 @@ var Jison = require("../setup").Jison, | ||
}; | ||
exports["test module include with each generator type"] = function () { | ||
var lexData = { | ||
rules: [ | ||
["y", "return 'y';"] | ||
] | ||
}; | ||
var grammar = { | ||
bnf: { | ||
"E" :[ ["E y", "return test();"], | ||
"" ] | ||
}, | ||
moduleInclude: "var TEST_VAR;" | ||
}; | ||
var gen = new Jison.Parser(grammar); | ||
gen.lexer = new Lexer(lexData); | ||
['generateModule', 'generateAMDModule', 'generateCommonJSModule'] | ||
.map(function(type) { | ||
var source = gen[type](); | ||
assert.ok(/TEST_VAR/.test(source), type + " supports module include"); | ||
}); | ||
}; |
3
144777
24
3902
Updatedebnf-parser@~0.1.9