If fighting an island grammar with antlr4, and while I can make it work, I still have doubts if this is the "proper" way.
I need to parse :
Some random text
{ }
@if(condition) {
more random text
@foobar
@if (condition2) {
random text {}
}
}
The problem lies within the context : An "wild" {} isn't anything, but if it's a { } behind a language operator, the { } become meaningful. (read : It opens and closes a block)
In the above case, it would return the following, assuming that condition and condition2 are both true :
Some random text
{}
more random text
random text {}
I'm confused on which route to pick, any advice on the above ?
The original implementation seems to be matching braces :
{ }
@if (true) {
{
foo
bar
} }
yields
{ }
{
foo
bar
}
while
{ }
@if (true) {
{
foo
bar
}
yields a parse error.
{
and}
in the inputrandom text {}
are rather ambiguous. How do you make a distinction between the}
inrandom text {}
and the}
that close a block? If they occur alone on a single line (as the last 2}
s), should they then becomeCURLY_CLOSE
? If you can explain it in plain English, I might be able to help :) – Bart Kiers