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

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

Open
jdvorak2001 opened this issue Mar 24, 2017 · 3 comments

Comments

@jdvorak2001
Copy link

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

@GerHobbelt
Copy link
Contributor

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
Copy link
Contributor

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 added a commit to GerHobbelt/jison that referenced this issue Mar 26, 2017
…ection logic so that the Jison code itself delivers an 'empty call' to compare against. The bug in zaach#348 is most probably due to the replacements of comment start/end markers in `preprocessActionCode()` and `postprocessActionCode()` while the original comparison happens between these calls, screwing up the detection, which drives the code stripper which removes the `this.performAction.call` code. Still ho-hum, though, as I don't see this happen... Anyway, this bit of rework is necessary anyway as now we're better equipped to keep detecting empty performAction functions.
GerHobbelt added a commit to GerHobbelt/jison that referenced this issue Mar 26, 2017
GerHobbelt added a commit to GerHobbelt/jison that referenced this issue Mar 26, 2017
@GerHobbelt
Copy link
Contributor

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 added a commit to GerHobbelt/jison that referenced this issue Sep 12, 2017
…of affairs, where the default grammar production value assignment code `$$ = $1` (default-action-mode=classic) is injected also when there actually **is** an action block present, **IFF** said action block does not assign a value to `$$` itself.
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