Skip to content

Cannot read property 'index' of undefined #4

@crguezl

Description

@crguezl

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions