Closed hamza1312 closed 1 year ago
There is no explicit support for indentation parsing in the generator, so the best thing you could do is preparse your text, and replace the indentation with special {INDENT}
and {DEDENT}
strings, and then do the parsing with peginator
. The algorithm itself should look something like this: https://stackoverflow.com/a/40960461
I guess newlines will be important in your grammar, so you should probably replace those with a special {NEWLINE}
string too, or use custom whitespace handling (by default newlines will be dropped between tokens).
Maybe some day peginator
will have out-of-box support for these, but not currently.
Can you show how ii can "pre-parse" Not the entire code, just how to handle the pre parsing in peginator.
Will "@extern" do the job ig?
To pre-parse, before giving your String
to peginator
, you first transform it with your own code:
let content = load_file("in.txt");
let transformed_content = detect_indent_dedent(&content); // <= You have to write this function, it's not part of peginator
let ast = GeneratedParser::parse(&transformed_content);
@extern
is for calling a specific parser while parsing. It's mostly for handling special-form literals or tokens that would be hard to describe in EBNF.
Alright i get it now thank you.
Closed.
So how to make indentation that will track when it's INDENT and DEDENT and can use it easily with the grammar?