Skip to main content
100%

Solution 2 for https://stackoverflow.com/questions/58891186/custom-location-tracking-in-jison-gho#58891186

✓ Published0🌍 Public
GGerHobbelt
Last edited Nov 17, 2019
Created on Nov 17, 2019

This example demonstrates a Jison grammar and lexer for parsing a custom "gifcode" language, with a focus on tracking token positions. The `post_lex` hook in the lexer overrides `first_column` and `last_column` to store an incrementing token counter, enabling the parser to track which token range corresponds to each grammar rule, while the underlying `range` member still tracks raw character positions. The lexer uses start conditions (`%x delimit`, `%x string_literal`) to manage delimiter and string states, and its error handling throws descriptions for invalid characters. The visible output is the parsed abstract syntax tree, built with the `Stmt.ProgramStmt` node, where location information is embedded in the `@$` attribute.

AI-generated description

Similar vizzes