I need some help with ANTLR. I have the following rule:
datasource
@init{boolean joinexpr = false;}
:
(s1=datasourceelement (joinclause1=joinclause joinelement1=datasourceelement onclause1=onclause (multijoinexpression)* {joinexpr=true;})?)
-> {joinexpr}? ^(JOINEXPRESSION
^(LEFTEXPR $s1?)
$joinclause1?
^(RIGHTEXPR $joinelement1?) $onclause1? multijoinexpression*
)
-> $s1
;
multijoinexpression
:
joinclause datasourceelement onclause
->
^(MULTIJOINEXPRESSION
joinclause
^(RIGHTEXPR datasourceelement) onclause
)
;
Which is for parsing out join expressions: It eats up
(table/query) (join (table/query) on (field=field))*
but I need to handle the "( )" around each join, so It can parse something like this:
((( table1 JOIN table2 ON field1=field2) JOIN table3 ON field2=field3 ) JOIN...)
without the brackets it works fine, but i can't figure out how to add the left and right bracket to the rule, because of the multijoinexpression*