-
I am currently making a small compiled scripting language with ANTLR, and it's going great! However, I also wanted to implement embedding raw C++ code, and I got stuck a bit on how to parse this: raw { // structured (part of the scripting language)
while(true) { // unstructured (raw string)
} // unstructured (raw string)
} // structured (part of the scripting language) and I'm wondering if it's possible at all. I have tried:
StartRaw: 'raw {' -> pushMode(InRawBlock);
mode InRawBlock;
EndRaw: '}' -> popMode;
AnyRaw: .;
rawBlock: StartRaw AnyRaw* EndRaw; It fails because both the
Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It's saddening that I can't delete a discussion :( genericBlock: LeftBrace (. | genericBlock)*? RightBrace; And to get the text inside the block: var start = [...].genericBlock().Start.StartIndex;
var end = [...].genericBlock().Stop.StopIndex;
var code = context.Start.InputStream.GetText(new Interval(start, end))[1..^1]; |
Beta Was this translation helpful? Give feedback.
It's saddening that I can't delete a discussion :(
I found the solution in the documentation.
A recursive parser rule was enough:
genericBlock: LeftBrace (. | genericBlock)*? RightBrace;
And to get the text inside the block: