-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
When in the following program (which is a modification of the example in bin/parse3.js):
const fs = require('fs');
let input = ' ( ( ( 1) ) )';
const gruffalo = require('../gruffalo');
let grammar = new gruffalo.Grammar({ start: 'E' });
let rule = (left, right, f) => {
return grammar.add(new gruffalo.Rule(left, right, f));
};
rule('E', ['LP', 'E', 'RP'], (LP, E, RP) => [ E ]);
rule('E', ['ONE'], (one) => one);
rule('ONE', ['_', '1', '_'], (_, a) => a.type);
rule ('LP', ['_', '(', '_'], () => '');
rule ('RP', ['_', ')'], () => '');
// Substituting the former rule by this one produces an error. Seems to be a bug?
//rule ('RP', ['_', ')', '_'], () => '');
// whites
rule('_', []);
rule('_', ['_', ' ']);
let p = eval(gruffalo.compile(grammar))({});
var index = 0;
function lex() {
return { type: input[index++] || '$' };
}
console.log(JSON.stringify(p(lex)));I substitute the rule for 'RP' by the commented one (Intending to catch white spaces on the right side of the right parenthesis):
rule ('RP', ['_', ')', '_'], () => ''); I get this error:
/Users/casianorodriguezleon/localsrc/PL/1718/analisis-sintactico/GLR/gruffalo/gruffalo/lr1.js:239
call('p' + target.index),
^
TypeError: Cannot read property 'index' of undefinedIs this a bug in the grammar or is a bug in the gruffalo parser?
Metadata
Metadata
Assignees
Labels
No labels