Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'index' of undefined #4

Open
crguezl opened this issue Dec 25, 2017 · 1 comment
Open

Cannot read property 'index' of undefined #4

crguezl opened this issue Dec 25, 2017 · 1 comment

Comments

@crguezl
Copy link

crguezl commented Dec 25, 2017

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 undefined

Is this a bug in the grammar or is a bug in the gruffalo parser?

@tjvr
Copy link
Collaborator

tjvr commented Dec 31, 2017

There are probably bugs! This isn’t production-ready yet, sorry :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants