Skip to content

Commit

Permalink
fix for #51 : arrow action code with C++-style comment included would…
Browse files Browse the repository at this point in the history
… not test-parse before.
  • Loading branch information
GerHobbelt committed Nov 15, 2020
1 parent df09ea9 commit f4d4686
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
7 changes: 6 additions & 1 deletion dist/cli-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,7 @@ function prettyPrintAST(ast, options) {
function checkActionBlock(src, yylloc, options) {
// make sure reasonable line numbers, etc. are reported in any
// potential parse errors by pushing the source code down:
console.error("checkActionBlock", {src, yylloc, options})
if (yylloc && yylloc.first_line > 0) {
let cnt = yylloc.first_line;
let lines = new Array(cnt);
Expand Down Expand Up @@ -3966,6 +3967,7 @@ case 61:


var srcCode = trimActionCode$1(yyvstack[yysp - 1]);
console.error("lexer 3970: arrow action", srcCode)
// add braces around ARROW_ACTION_CODE so that the action chunk test/compiler
// will uncover any illegal action code following the arrow operator, e.g.
// multiple statements separated by semicolon.
Expand Down Expand Up @@ -22181,7 +22183,7 @@ case 116:
this._$ = yylstack[yysp];
// END of default action (generated by JISON mode classic/merge :: 1/1,VT,VA,VU,-,LT,LA,-,-)


console.error("arrow action 22187:", yyvstack[yysp])
this.$ = '$$ = (' + yyvstack[yysp] + ');';
break;

Expand Down Expand Up @@ -27345,18 +27347,21 @@ var lexer$2 = function() {
/*! Conditions:: token bnf ebnf INITIAL */
/*! Rule:: ->.* */
yy_.yytext = yy_.yytext.substr(2, yy_.yyleng - 2).trim();
console.error("lexer recognized arrow action:", yy_.yytext)

return 38;
case 70:
/*! Conditions:: token bnf ebnf INITIAL */
/*! Rule:: →.* */
yy_.yytext = yy_.yytext.substr(1, yy_.yyleng - 1).trim();
console.error("lexer recognized arrow action:", yy_.yytext)

return 38;
case 71:
/*! Conditions:: token bnf ebnf INITIAL */
/*! Rule:: =>.* */
yy_.yytext = yy_.yytext.substr(2, yy_.yyleng - 2).trim();
console.error("lexer recognized arrow action:", yy_.yytext)

return 38;
case 72:
Expand Down
2 changes: 1 addition & 1 deletion packages/ebnf-parser/bnf.y
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ action
// add braces around ARROW_ACTION so that the action chunk test/compiler
// will uncover any illegal action code following the arrow operator, e.g.
// multiple statements separated by semicolon.
{ $$ = '$$ = (' + $ARROW_ACTION + ');'; }
{ $$ = '$$ = (\n' + $ARROW_ACTION + '\n);'; }
| %epsilon
{ $$ = ''; }
;
Expand Down
30 changes: 15 additions & 15 deletions packages/ebnf-parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4798,7 +4798,7 @@ let esp = recoveringErrorInfo.info_stack_pointer;

// try to recover from error
if (error_rule_depth < 0) {
ASSERT(recovering > 0, 'Line 1048');
ASSERT(recovering > 0, 'Line 4801');
recoveringErrorInfo.info_stack_pointer = esp;

// barf a fatal hairball when we're out of look-ahead symbols and none hit a match
Expand Down Expand Up @@ -4961,9 +4961,9 @@ r = this.performAction.call(yyval, yyloc, combineState, sp - 1, vstack, lstack);
// only a single parse loop, which handles everything. Our goal is
// to eke out every drop of performance in the main parse loop...

ASSERT(recoveringErrorInfo, 'Line 1204');
ASSERT(symbol === TERROR, 'Line 1205');
ASSERT(!action, 'Line 1206');
ASSERT(recoveringErrorInfo, 'Line 4964');
ASSERT(symbol === TERROR, 'Line 4965');
ASSERT(!action, 'Line 4966');
let errorSymbolFromParser = true;
for (;;) {
// retrieve state number from top of stack
Expand Down Expand Up @@ -5012,7 +5012,7 @@ r = this.performAction.call(yyval, yyloc, combineState, sp - 1, vstack, lstack);



ASSERT(recoveringErrorInfo, 'Line 1248');
ASSERT(recoveringErrorInfo, 'Line 5015');

// Prep state variables so that upon breaking out of
// this "slow parse loop" and hitting the `continue;`
Expand Down Expand Up @@ -5055,12 +5055,12 @@ switch (action) {
// Push a special value onto the stack when we're
// shifting the `error` symbol that is related to the
// error we're recovering from.
ASSERT(recoveringErrorInfo, 'Line 1305');
ASSERT(recoveringErrorInfo, 'Line 5058');
vstack[sp] = recoveringErrorInfo;
lstack[sp] = this.yyMergeLocationInfo(null, null, recoveringErrorInfo.loc, lexer.yylloc, true);
} else {
ASSERT(symbol !== 0, 'Line 1309');
ASSERT(preErrorSymbol === 0, 'Line 1310');
ASSERT(symbol !== 0, 'Line 5062');
ASSERT(preErrorSymbol === 0, 'Line 5063');
vstack[sp] = lexer.yytext;
lstack[sp] = this.copy_yylloc(lexer.yylloc);
}
Expand Down Expand Up @@ -5110,7 +5110,7 @@ switch (action) {
}
} else {
// error just occurred, resume old lookahead f/ before error, *unless* that drops us straight back into error mode:
ASSERT(recovering > 0, 'Line 1352');
ASSERT(recovering > 0, 'Line 5113');
symbol = preErrorSymbol;
preErrorSymbol = 0;

Expand Down Expand Up @@ -5157,7 +5157,7 @@ switch (action) {
// while the error symbol hasn't been shifted onto
// the stack yet. Hence we only exit this "slow parse loop"
// when *both* conditions are met!
ASSERT(preErrorSymbol === 0, 'Line 1383');
ASSERT(preErrorSymbol === 0, 'Line 5160');
if (recovering === 0) {
break;
}
Expand Down Expand Up @@ -5291,7 +5291,7 @@ r = this.performAction.call(yyval, yyloc, newState, sp - 1, vstack, lstack);
// i.e. did the parser already produce a parse result in here?!
// *or* did we hit an unsupported parse state, to be handled
// in the `switch/default` code further below?
ASSERT(action !== 2, 'Line 1509');
ASSERT(action !== 2, 'Line 5294');
if (!action || action === 1) {
continue;
}
Expand Down Expand Up @@ -5353,8 +5353,8 @@ switch (action) {

symbol = 0;

ASSERT(preErrorSymbol === 0, 'Line 1619'); // normal execution / no error
ASSERT(recovering === 0, 'Line 1620'); // normal execution / no error
ASSERT(preErrorSymbol === 0, 'Line 5356'); // normal execution / no error
ASSERT(recovering === 0, 'Line 5357'); // normal execution / no error

// Pick up the lexer details for the current symbol as that one is not 'look-ahead' any more:

Expand All @@ -5365,8 +5365,8 @@ switch (action) {

// reduce:
case 2:
ASSERT(preErrorSymbol === 0, 'Line 1631'); // normal execution / no error
ASSERT(recovering === 0, 'Line 1632'); // normal execution / no error
ASSERT(preErrorSymbol === 0, 'Line 5368'); // normal execution / no error
ASSERT(recovering === 0, 'Line 5369'); // normal execution / no error

this_production = this.productions_[newState - 1]; // `this.productions_[]` is zero-based indexed while states start from 1 upwards...
yyrulelen = this_production[1];
Expand Down

0 comments on commit f4d4686

Please sign in to comment.