ちまちまと直しているが問題は解決していない。
grammar TwoWaySQL; options { language = Java; output = AST; ASTLabelType = CommonTree; } tokens { BEGINNODE; IFNODE; EXPRESSIONNODE; ELSENODE; } @header { package twowaysql.grammar; } @lexer::header { package twowaysql.grammar; } twowaySQL : txt EOF; txt : (IDENT | comment | WS | LT)+ ; // $<comment comment : begincomment | ifcomment | blockcomment | linecomment ; blockcomment : C_ST (IDENT | LT)+ C_ED ; linecomment : C_LN (IDENT)+ (LT|EOF) ; ifcomment : C_ST IF expression C_ED txt (elsecomment txt)* endcomment -> ^(IFNODE ^(EXPRESSIONNODE expression) txt (^(ELSENODE elsecomment txt))*) ; elsecomment : (C_ST ELSE expression? C_ED -> ^(EXPRESSIONNODE expression?) | C_LN ELSE lineexpression? LT -> ^(EXPRESSIONNODE lineexpression?) ) ; expression : (IDENT | WS | LT)+ ; lineexpression : (IDENT | WS)+ ; begincomment : (C_ST BEGIN C_ED txt endcomment | C_LN BEGIN LT txt endcomment ) -> ^(BEGINNODE txt) ; endcomment : C_ST END C_ED | C_LN END (LT|EOF) ; // $> C_ST : '/*'; C_ED : '*/'; C_LN : '--'; BEGIN : WS* ('b'|'B')('e'|'E')('g'|'G')('i'|'I')('n'|'N') WS*; IF : WS* ('i'|'I') ('f'|'F') WS*; ELSE : WS* ('e'|'E')('l'|'L')('s'|'S')('e'|'E') WS*; END : WS* ('e'|'E')('n'|'N')('d'|'D') WS*; // $<Charactors LT : '\n' // Line feed. | '\r' // Carriage return. | '\u2028' // Line separator. | '\u2029' // Paragraph separator. ; WS : '\t' | '\v' | '\f' | ' ' | '\u00A0'; IDENT : WS* CHAR+ WS*; fragment CHAR : ~( '*' | '/' | '-' | LT | WS) ; // $>
大体、こんな感じのテキストを食わせている。
ada.cec のしのし / 3 d/*aa hoge piro*/ ぎゃぼー -- BeGiN /* If aa - bb dd*/moge piro /*eLsE ccc + 44*/cccd -- elSE fuga < 0 dfdze -- ElSe zzz -- eNd -- moge うぼぁ zz /* EnD*/