update grammar for latest jison
This commit is contained in:
@@ -9,7 +9,7 @@ performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
|
|||||||
|
|
||||||
var $0 = $$.length - 1;
|
var $0 = $$.length - 1;
|
||||||
switch (yystate) {
|
switch (yystate) {
|
||||||
case 1:this.$ = yytext;
|
case 1:this.$ = yytext.replace(/\\\\/g, "\\");
|
||||||
break;
|
break;
|
||||||
case 2:this.$ = Number(yytext);
|
case 2:this.$ = Number(yytext);
|
||||||
break;
|
break;
|
||||||
@@ -86,7 +86,7 @@ parse: function parse(input) {
|
|||||||
token = self.symbols_[token] || token;
|
token = self.symbols_[token] || token;
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
};
|
}
|
||||||
|
|
||||||
var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected;
|
var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected;
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -104,6 +104,7 @@ parse: function parse(input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handle parse error
|
// handle parse error
|
||||||
|
_handle_error:
|
||||||
if (typeof action === 'undefined' || !action.length || !action[0]) {
|
if (typeof action === 'undefined' || !action.length || !action[0]) {
|
||||||
|
|
||||||
if (!recovering) {
|
if (!recovering) {
|
||||||
@@ -114,7 +115,7 @@ parse: function parse(input) {
|
|||||||
}
|
}
|
||||||
var errStr = '';
|
var errStr = '';
|
||||||
if (this.lexer.showPosition) {
|
if (this.lexer.showPosition) {
|
||||||
errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+'\nExpecting '+expected.join(', ');
|
errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'";
|
||||||
} else {
|
} else {
|
||||||
errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
|
errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
|
||||||
(symbol == 1 /*EOF*/ ? "end of input" :
|
(symbol == 1 /*EOF*/ ? "end of input" :
|
||||||
@@ -228,8 +229,10 @@ parse: function parse(input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}};/* Jison generated lexer */
|
}};
|
||||||
var lexer = (function(){var lexer = ({EOF:1,
|
/* Jison generated lexer */
|
||||||
|
var lexer = (function(){
|
||||||
|
var lexer = ({EOF:1,
|
||||||
parseError:function parseError(str, hash) {
|
parseError:function parseError(str, hash) {
|
||||||
if (this.yy.parseError) {
|
if (this.yy.parseError) {
|
||||||
this.yy.parseError(str, hash);
|
this.yy.parseError(str, hash);
|
||||||
@@ -265,6 +268,9 @@ more:function () {
|
|||||||
this._more = true;
|
this._more = true;
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
less:function (n) {
|
||||||
|
this._input = this.match.slice(n) + this._input;
|
||||||
|
},
|
||||||
pastInput:function () {
|
pastInput:function () {
|
||||||
var past = this.matched.substr(0, this.matched.length - this.match.length);
|
var past = this.matched.substr(0, this.matched.length - this.match.length);
|
||||||
return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
|
return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
|
||||||
@@ -289,6 +295,8 @@ next:function () {
|
|||||||
|
|
||||||
var token,
|
var token,
|
||||||
match,
|
match,
|
||||||
|
tempMatch,
|
||||||
|
index,
|
||||||
col,
|
col,
|
||||||
lines;
|
lines;
|
||||||
if (!this._more) {
|
if (!this._more) {
|
||||||
@@ -297,26 +305,31 @@ next:function () {
|
|||||||
}
|
}
|
||||||
var rules = this._currentRules();
|
var rules = this._currentRules();
|
||||||
for (var i=0;i < rules.length; i++) {
|
for (var i=0;i < rules.length; i++) {
|
||||||
match = this._input.match(this.rules[rules[i]]);
|
tempMatch = this._input.match(this.rules[rules[i]]);
|
||||||
if (match) {
|
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
|
||||||
lines = match[0].match(/\n.*/g);
|
match = tempMatch;
|
||||||
if (lines) this.yylineno += lines.length;
|
index = i;
|
||||||
this.yylloc = {first_line: this.yylloc.last_line,
|
if (!this.options.flex) break;
|
||||||
last_line: this.yylineno+1,
|
|
||||||
first_column: this.yylloc.last_column,
|
|
||||||
last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
|
|
||||||
this.yytext += match[0];
|
|
||||||
this.match += match[0];
|
|
||||||
this.matches = match;
|
|
||||||
this.yyleng = this.yytext.length;
|
|
||||||
this._more = false;
|
|
||||||
this._input = this._input.slice(match[0].length);
|
|
||||||
this.matched += match[0];
|
|
||||||
token = this.performAction.call(this, this.yy, this, rules[i],this.conditionStack[this.conditionStack.length-1]);
|
|
||||||
if (token) return token;
|
|
||||||
else return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (match) {
|
||||||
|
lines = match[0].match(/\n.*/g);
|
||||||
|
if (lines) this.yylineno += lines.length;
|
||||||
|
this.yylloc = {first_line: this.yylloc.last_line,
|
||||||
|
last_line: this.yylineno+1,
|
||||||
|
first_column: this.yylloc.last_column,
|
||||||
|
last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
|
||||||
|
this.yytext += match[0];
|
||||||
|
this.match += match[0];
|
||||||
|
this.yyleng = this.yytext.length;
|
||||||
|
this._more = false;
|
||||||
|
this._input = this._input.slice(match[0].length);
|
||||||
|
this.matched += match[0];
|
||||||
|
token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
|
||||||
|
if (this.done && this._input) this.done = false;
|
||||||
|
if (token) return token;
|
||||||
|
else return;
|
||||||
|
}
|
||||||
if (this._input === "") {
|
if (this._input === "") {
|
||||||
return this.EOF;
|
return this.EOF;
|
||||||
} else {
|
} else {
|
||||||
@@ -340,7 +353,14 @@ popState:function popState() {
|
|||||||
},
|
},
|
||||||
_currentRules:function _currentRules() {
|
_currentRules:function _currentRules() {
|
||||||
return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
|
return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
|
||||||
|
},
|
||||||
|
topState:function () {
|
||||||
|
return this.conditionStack[this.conditionStack.length-2];
|
||||||
|
},
|
||||||
|
pushState:function begin(condition) {
|
||||||
|
this.begin(condition);
|
||||||
}});
|
}});
|
||||||
|
lexer.options = {};
|
||||||
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
|
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
|
||||||
|
|
||||||
var YYSTATE=YY_START
|
var YYSTATE=YY_START
|
||||||
@@ -375,8 +395,12 @@ case 13:return 'INVALID'
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
lexer.rules = [/^\s+/,/^-?([0-9]|[1-9][0-9]+)(\.[0-9]+)?([eE][-+]?[0-9]+)?\b/,/^"(\\["bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^\0-\x09\x0a-\x1f"\\])*"/,/^\{/,/^\}/,/^\[/,/^\]/,/^,/,/^:/,/^true\b/,/^false\b/,/^null\b/,/^$/,/^./];
|
lexer.rules = [/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/];
|
||||||
lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}};return lexer;})()
|
lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}};
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
return lexer;})()
|
||||||
parser.lexer = lexer;
|
parser.lexer = lexer;
|
||||||
return parser;
|
return parser;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1,23 +1,24 @@
|
|||||||
esc "\\"
|
|
||||||
int "-"?([0-9]|[1-9][0-9]+)
|
int "-"?([0-9]|[1-9][0-9]+)
|
||||||
exp ([eE][-+]?[0-9]+)
|
exp [eE][-+]?[0-9]+
|
||||||
frac ("."[0-9]+)
|
frac "."[0-9]+
|
||||||
|
|
||||||
%%
|
%%
|
||||||
\s+ {/* skip whitespace */}
|
\s+ /* skip whitespace */
|
||||||
{int}{frac}?{exp}?\b {return 'NUMBER';}
|
|
||||||
'"'("\\"["bfnrt/{esc}]|"\\u"[a-fA-F0-9]{4}|[^\0-\x09\x0a-\x1f"{esc}])*'"' {yytext = yytext.substr(1,yyleng-2); return 'STRING';}
|
{int}{frac}?{exp}?\b return 'NUMBER'
|
||||||
"{" %{ return '{' %}
|
\"(?:'\\'[\\"bfnrt/]|'\\u'[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*\" yytext = yytext.substr(1,yyleng-2); return 'STRING'
|
||||||
"}" %{ return '}' %}
|
|
||||||
"[" {return '['}
|
"{" return '{'
|
||||||
"]" {return ']'}
|
"}" return ''
|
||||||
"," {return ','}
|
"[" return '['
|
||||||
":" {return ':'}
|
"]" return ']'
|
||||||
"true" {return 'TRUE'}
|
"," return ','
|
||||||
"false" {return 'FALSE'}
|
":" return ':'
|
||||||
"null" {return 'NULL'}
|
"true" return 'TRUE'
|
||||||
<<EOF>> {return 'EOF'}
|
"false" return 'FALSE'
|
||||||
. {return 'INVALID'}
|
"null" return 'NULL'
|
||||||
|
<<EOF>> return 'EOF'
|
||||||
|
. return 'INVALID'
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
|
%start JSONText
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ECMA-262 5th Edition, 15.12.1 The JSON Grammar.
|
ECMA-262 5th Edition, 15.12.1 The JSON Grammar.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* author: Zach Carter */
|
|
||||||
|
|
||||||
|
|
||||||
%start JSONText
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
JSONString
|
JSONString
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user