Closed lijunchen closed 1 year ago
There is no automatic indentation or location handling. You can have a rule with tags surrounding indentation, like this:
@x space* @y something { indent = (y - x) / 4; ... }
The way many parsers handle things like this is to keep track of the indentation levels in some state variable and to issue synthetic indent
and unindent
tokens whenever whitespace at the start of line is encountered that does not conform to the previous indentation level.
Thanks all, I find a solution by using indent stack and tags, it works but there are many corner cases. When I can fully support tokenizing Python3.10, I will update this issue.
My current solution: https://github.com/lijunchen/pyser/blob/ead8f46a2847905d4757ed194c604d0ca493c2f0/src/tokenizer.re2c Indent stack: https://matt.might.net/articles/standalone-lexers-with-lex/)
Are there any examples of handling indentation?
For example: test.py