jison icon indicating copy to clipboard operation
jison copied to clipboard

Fail rules from actions

Open octavpo opened this issue 7 years ago • 1 comments

Is there a way to make a grammar rule fail from an action?

We have a grammar for propositional logic and in some contexts we'd like to only accept a fully parenthesized version of the language. Rather than maintaining a second grammar for that purpose, I'd prefer to be able to make some rules just fail when a 'strict' parameter is set and parentheses are missing. How can I do that? Thanks.

octavpo avatar May 31 '18 21:05 octavpo

Invoke yyerror(...) from within the action. Similar to bison.

If this doesnt work for jison as is, check out jison-gho fork (mine) which is also on npm: there yyerror works and is used extensively: see that fork's lex.y and bnf.y source files for examples of its use. yyerror() is also available in lexer actions if you need that too (jison-gho)

GerHobbelt avatar Jun 01 '18 02:06 GerHobbelt