Skip to content

Identation defining the scope #782

Answered by msujew
JoanGi asked this question in Q&A
Nov 24, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hey @JoanGi,

So, this can be done in theory, by using whitespace sensitive approach to parsing. You would introduce "decoy" terminal rules INDENT and DEDENT, then you override their pattern in the TokenBuilder class to look something like this chevrotain python example. You would then use these tokens in your grammar whenever you need to increase/decrease the indentation of your text. This approach works best, when you enter a new parser rule/create a new AST node for each level of indentation, as that later on massively helps you with validation and cross reference resolution.

Note that whitespace sensitive languages in EBNF style grammars are always a pain to deal with, and there's no e…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aabounegm
Comment options

Answer selected by JoanGi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants