I'm parsing a script language that defines two types of statements; control statements and non control statements. Non control statements are always ended with ';'
, while control statements may end with ';'
or EOL
('\n'). A part of the grammar looks like this:
script
: statement* EOF
;
statement
: control_statement
| no_control_statement
;
control_statement
: if_then_control_statement
;
if_then_control_statement
: IF expression THEN end_control_statment
( statement ) *
( ELSEIF expression THEN end_control_statment ( statement )* )*
( ELSE end_control_statment ( statement )* )?
END IF end_control_statment
;
no_control_statement
: sleep_statement
;
sleep_statement
: SLEEP expression END_STATEMENT
;
end_control_statment
: END_STATEMENT
| EOL
;
END_STATEMENT
: ';'
;
ANY_SPACE
: ( LINE_SPACE | EOL ) -> channel(HIDDEN)
;
EOL
: [\n\r]+
;
LINE_SPACE
: [ \t]+
;
In all other aspects of the script language, I never care about EOL
so I use the normal lexer rules to hide white space.
This works fine in all cases but the cases where I need to use a EOL
to find a termination of a control statement, but with the grammar above, all EOL
is hidden and not used in the control statement rules.
Is there a way to change my grammar so that I can skip all EOL
but the ones needed to terminate parts of my control statements?