I want to create a very simple grammar with space indentation. Each line consists of 1 or more words but indentation like python (4 spaces or a tab is one indent) and there is no close for indentation, for example:
if something cool occurs
do this
else
otherwise do this
loop around something
each time doing this
and do that
say good byte
Rather than read each line, calculate the indentation and build a tree manually is it possible to do all of that in ANTLR grammar? My target language is Java.
This is possible. All you do is define a rule and let it be skipped.
Here you go:
Ignore : (' ' | '\t' | '\n' | '\r')+ {skip();};
Or if you need to recognize \n or \r
Ignore : (' ' | '\t')+ {skip();};
Add this to your gramar and all spaces and tabs will be ignored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With