Xtext parser rules overlap problem [message #1772474] |
Mon, 11 September 2017 04:49  |
Eclipse User |
|
|
|
Hello,
I'm trying to create parser with Xtext/Xtend but i'm struggling with setting/resolving the grammar and my AST fail to map the input correctly.
In general Xtext seems to map the 1st match of possible match only, and didn't proceed checking if there are other viable options. This happens for example when i have the following 2 rules:
TypeArguments:
'<' args+=TypeArgument (',' args+=TypeArgument)* '>'
//catching declarations like "List<String, String>"
and
ComparisonOperationExpression:
ArithmeticalOperationExpression ({ComparisonOperationExpression.leftExpression=current} comments+=Comments =>operand=COMPARABLE_OPERANDS rightExpression=ArithmeticalOperationExpression)*
terminal COMPARABLE_OPERANDS:
('=='|'!='|'<='|'>='|'<'|'>')
In this case i'm just receiving warnings (hidden) that there are multiple matches, but always gets the first declaration for creating the AST.
There are other such clashes in the grammar and i'm not quite sure what is the best way to resolve them.
The Xtext grammar file is attached here. In the parser options i've set "backtracking" = true:
parserGenerator = {
options = {
backtrack = true
}
}
I've attached a screenshot of an example code where the parser cannot recognize the "<" operator. When change to "==" the problem disappears.
Please, can you help with a possible solution if you encountered problem like this before.
Regards,
Svilen :)
|
|
|
|
|
|
Re: Xtext parser rules overlap problem [message #1773090 is a reply to message #1772749] |
Thu, 21 September 2017 07:10  |
Eclipse User |
|
|
|
Hi Christian,
I've finally managed to fix the issue by simply pre-processing the java classes and replacing the <> symbols for Type declaration with another unique symbol. Ofc the grammar is changed too to parse the new symbols as type decl. Looks like my experience was too limited to utilize a proper solution, but anyway - workaround is also ok for me and the performance is not an issue.
Thank you for trying to help - it's much appreciated :)
Regards,
Svilen
|
|
|
Powered by
FUDForum. Page generated in 0.10530 seconds