zaach / jison-lex

generates lexical analyzers. used by jison.
57 stars 33 forks source link

Not able to use INITIAL and an exclusive state #19

Open vihanb opened 7 years ago

vihanb commented 7 years ago

I have this line which causes an error:

<INITIAL,MULTILINE_COMMENT>"/*"                    this.begin("MUTLILINE_COMMMENT");

where MULTILINE_COMMENT is successfully defined with %x MULTILINE_COMMENT

/usr/local/lib/node_modules/jison/node_modules/jison-lex/regexp-lexer.js:42
                startConditions[conditions[k]].rules.push(i);
                                              ^

TypeError: Cannot read property 'rules' of undefined
    at prepareRules (/usr/local/lib/node_modules/jison/node_modules/jison-lex/regexp-lexer.js:42:47)
    at Object.buildActions (/usr/local/lib/node_modules/jison/node_modules/jison-lex/regexp-lexer.js:112:18)
    at processGrammar (/usr/local/lib/node_modules/jison/node_modules/jison-lex/regexp-lexer.js:484:39)
    at RegExpLexer (/usr/local/lib/node_modules/jison/node_modules/jison-lex/regexp-lexer.js:122:16)
    at o.constructor.Jison_Generator [as constructor] (/usr/local/lib/node_modules/jison/lib/jison.js:111:22)
    at o.constructor.(anonymous function) [as constructor] (/usr/local/lib/node_modules/jison/lib/util/typal.js:23:28)
    at new o.constructor (/usr/local/lib/node_modules/jison/lib/util/typal.js:77:70)
    at new Jison_Generator (/usr/local/lib/node_modules/jison/lib/jison.js:1910:20)
    at Object.generateParserString (/usr/local/lib/node_modules/jison/lib/cli.js:153:21)
    at processGrammar (/usr/local/lib/node_modules/jison/lib/cli.js:72:22)
GerHobbelt commented 7 years ago

2 typos in your code:

this.begin("MUTLILINE_COMMMENT");

should be

this.begin("MULTILINE_COMMENT");

Thought: For improved robustness, jison should maybe check/test for this type of user-coder error in the lexer generator, so that this type of error is easier to diagnose for everyone.

vihanb commented 7 years ago

Oh my god how did I miss this. (This is not first time I have made such mistake)

GerHobbelt commented 7 years ago

No sweat; as said, the current lexer engine doesn't exactly help to catch this type of mistake when using the jison tool.

A stop-gap change in the engine is coming up to help catch this type of mistake at runtime at least as it happens quite easily during grammar development. Should surface in about a week in the GerHobbelt/jison fork + a pull req here: https://github.com/GerHobbelt/jison