Replies: 3 comments 1 reply
-
Yes, it's the entire character stream that any token points to is the text for the tree. For a sub-tree, you have two options.
Having lexer rules marked "skip" can make text reconstruction impossible from just the token stream text because there won't be any tokens in the token stream for the string. You have to go to the char stream buffer. |
Beta Was this translation helpful? Give feedback.
-
In theory it's possible but not ideally:
|
Beta Was this translation helpful? Give feedback.
-
Thanks guys, I will read up on this as suggested. FYI the motive here is to replace all keywords with their equivalent in some other language. The language I'm designing (named recently as "Imperium") makes it trivial to use keywords from any supported language like English, French, Spanish, Dutch etc. I'd like to parse a source file that uses say English keywords and replace those with say Dutch and the generate a new source file that contains only the Dutch keywords. This is not an important thing, but something that would be useful to have around, certainly for testing but also as a useful tool when working with the language. |
Beta Was this translation helpful? Give feedback.
-
I was wondering if there's enough metadata in the parse tree to be able to recreate the original source text from it, right down to the same line numbers and offsets within lines, of the various tokens.
Could one recreate an exact replica of the original source file, from the tree?
Beta Was this translation helpful? Give feedback.
All reactions