Simple Xtext example generates grammar that Antlr4 doesn't like - who's to blame? -
while using xtext, have come across problem , not sure if antlr4 or xtext @ fault or if i'm missing something. understand antlr4 not supported xtext, seems particular case should not cause problem.
here simple xtext file:
grammar com.github.jsculley.antlr4.test org.eclipse.xtext.common.terminals generate test "http://www.github.com/jsculley/antlr4/test" arule: name=string ;
string defined in xtext rule org.eclipse.xtext.common.terminals:
terminal string : '"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"' | "'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'" ;
the generated antlr grammar has following rule:
rule_string : ('"' ('\\' .|~(('\\'|'"')))* '"'|'\'' ('\\' .|~(('\\'|'\'')))* '\'');
the antlr 3.5.2 tool has no problem rule, antlr4 tool spits out following errors:
error(50): internaltest.g:102:29: syntax error: '(' came complete surprise me while looking lexer rule element error(50): internaltest.g:102:62: syntax error: '(' came complete surprise me while looking lexer rule element error(50): internaltest.g:102:74: syntax error: mismatched input ')' expecting semi while matching lexer rule error(50): internaltest.g:106:25: syntax error: '(' came complete surprise me while looking lexer rule element error(50): internaltest.g:106:36: syntax error: mismatched input ')' expecting semi while matching lexer rule
antlr4 doesn't (and seemingly uneccessary) sets of parentheses around group after each '~' operator. question is, xtext generating bad grammar, or antlr4 not handling valid construct?
it seems antlr 4 not handle parenthesis correctly: parser issues mutual left recursion error when left-recursive part of rule in parenthesis.
so, remove useless parenthesis , antlr 4 should generate anltr 3 compatible parser. ported pl/sql grammar antlr 3 -> antlr 4. moreover, anltr 4 have more powerfull parsing algorithm compare previous version.
Comments
Post a Comment