jison icon indicating copy to clipboard operation
jison copied to clipboard

Getting "this.performAction.call is not a function" when trying to parse text

Open jdvorak2001 opened this issue 8 years ago • 3 comments

I have the grammar in the attached file and input the following text for parsing: define mc with orientation=horizontal as stem text is "this is a test" option text = "option 1" and is correct option text = "option 2" option text = "option 3" score 1 point for all correct

mcmsDeclarativeGrammar.txt

I am getting "this.performAction.call is not a function" when trying to parse the above text.

Does anyone know why this is happening?

Thanks in advance.

Joe

jdvorak2001 avatar Mar 24 '17 04:03 jdvorak2001

Looks like you're using my jison fork. You're triggering a bug in the parser generator feature-analysis/optimization code, where jison detects your grammar doesn't have any custom action code, hence the entire performAction function can be discarded (as nothing will be happening in there) and thus speed up parsing as that's one less function call+parameters-passing activity per reduce state at run-time.

Looks like the 'code stripper' doesn't properly remove the this.performAction.call(...) code from the generated parser, produced by jison.

GerHobbelt avatar Mar 26 '17 11:03 GerHobbelt

Assuming of course that I guessed correct above and you are using my fork/clone, which version are you running?

Latest = 0.4.18-174

GerHobbelt avatar Mar 26 '17 12:03 GerHobbelt

forget what I said

Had a look while I was working on https://github.com/GerHobbelt/jison and found that the grammar you attached at least it not a viable jison grammar.

First of all, the (...) parts in the grammar make this an EBNF grammar, so the %ebnf should be specified or you'ld get this:

...\tooling\jison\lib\jison.js:179
            throw err;
            ^

Error: unsupported parser input: "(" @ line 45, column 12 while lexing in bnf state:
     : %empty | (at...
    ------------^
    at Object.lexer__performAction [as performAction] (C:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\lib\util\parser.js:9464:51)
    at Object.lexer_test_match [as test_match] (C:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\lib\util\parser.js:3722:36)
    at Object.lexer_next [as next] (C:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\lib\util\parser.js:3821:26)
    at Object.lexer_lex [as lex] (C:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\lib\util\parser.js:3852:22)
    at lex (C:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\lib\util\parser.js:2630:27)
    at Object.parse (C:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\lib\util\parser.js:2729:30)
    at Object.parse (C:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\lib\util\ebnf-parser.js:6:16)
    at autodetectAndConvertToJSONformat (C:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\lib\jison.js:169:32)
    at new Jison_Generator (C:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\lib\jison.js:6451:15)
    at Object.generateParserString (C:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\lib\cli.js:313:21)

After adding this option, several other things show up as faulty/unsupported and error out:

  • actions within a (...) part are not supported
  • you're using action code which references yytext but I wonder if you truly know what you're doing there; it's far better and safer (when you maintain the grammar) to use $n-named references, such as $stem or $STRING :: jison supports implicit named references for tokens, so if a rule has a terminal STRING, you can access the yyvalue/yytext value of that token via $STRING
  • your lexer spec isn't jison-lex compatible: jison doesn't support whitespace as part of the lexer regex rule, hence no spaces allowed around the | in the mc|mr lexer lexer rule.
  • also, jison-lex matches on the first matching rule: the mc|mr lexer rule is completely obscured by the lexer rule for STRING. flex wouldn't have saved your bacon here either, despite it testing all rules and picking the longest match.
  • jison does not support lexer token strings which happen to be defined in the grammar spec itself. PEG et al don't separate the lexing and parsing task, so you can pull tricks like that there, but not in jison you can't.

Overall it looks like a grammar in transition; a preliminary working version of the same is available at https://github.com/GerHobbelt/jison/blob/master/examples/issue-348.jison for your perusal, while your posted grammar is stored at https://github.com/GerHobbelt/jison/blob/master/examples/issue-348-grammar.txt for comparison.

GerHobbelt avatar Mar 27 '17 20:03 GerHobbelt