Skip to content

Capturing unstructured text surrounded by structured code #4001

Answered by nedoxff
nedoxff asked this question in Q&A
Discussion options

You must be logged in to vote

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:

var start = [...].genericBlock().Start.StartIndex;
var end = [...].genericBlock().Stop.StopIndex;
var code = context.Start.InputStream.GetText(new Interval(start, end))[1..^1];

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nedoxff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant