Skip to main content
100%

JISON sample wrapper showcasing custom error handlers (stripped JavaScript, ... where more must be done)

✓ Published0🌍 Public
GGerHobbelt
Last edited Jul 6, 2016
Created on Jun 4, 2014

This example demonstrates a JavaScript wrapper around a JISON-generated parser, showcasing custom error handling and event-driven integration. The code overrides `parserWithTokens.yy.parseError` to distinguish and dispatch parser versus lexer errors, and hooks `lexer.post_lex` to log token strings and monitor input consumption. It also registers a `post_parse` extension to ensure full lexing even after errors, and uses a simple event system to allow user action code inside the lexer/parser to trigger handlers dynamically. The implementation relies on the JISON parser generator’s terminal identifier table and its generated parser class.

AI-generated description

This code is a stripped version of actual production code which employs this JISON clone:

(https://github.com/GerHobbelt/jison)

hence make sure to diff that one against vanilla to see differences/features.


code shows .yy.parseError, lexer.post_lex, parser.post_parser, how to get the token identifier strings from the JISON-generated parser class, etc.

Note that the event reg/unreg/trigger functions are quick replacements for this gist only, use your own event system here. The key is that this works, even when you fire events from user action code inside the lexer or parser itself, hence more powerful than simply hooking .yy.parseError only!

Similar vizzes