Syntax-Error for LessThan-Keyword [message #1850778] |
Wed, 16 March 2022 18:43  |
Eclipse User |
|
|
|
Hi,
given the grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "org/example/mydsl/MyDsl"
Model:
{Model}
'{' statements+=Statement* '}';
Statement:
expr=Expression;
Expression:
AssignmentExpression;
AssignmentExpression:
ComparisonExpression (=>({BinaryExpression.lhs=current} operator=OpAssign)
rhs=AssignmentExpression)*;
OpAssign:
'=' | '<' '<' '=';
ComparisonExpression:
Primary (=>({BinaryExpression.lhs=current} operator=OpComp)
rhs=Primary)*;
OpComp:
'<' | '>' | '<' '=' | '>=' | '==';
Primary:
name=ID;
Following inputs result in different syntax errors:
Syntax-Error on '<': "extraneous input '<' expecting '}'"
Syntax-Error on '}': "missing RULE_ID at '}'"
The problematic thing for me about this is, that in the first case an instance of "Model" is available as the "currentModel" in the ContentAssistContext. In the second case an instance of "BinaryExpression" is available as the "currentModel" in the ContentAssistContext. I'd like to always have "BinaryExpression" as the "currentModel" so I can sort the proposals according to the right-hand-side of the BinaryOperation.
In Xtend the syntax error is issued always like in the second case here. So I compared my grammar with the XBase Grammar but could not find the difference. How was it solved there or what other solutions exists?
Thank you very much in advance!
Best regards,
Sebastian
|
|
|
|
Re: Syntax-Error for LessThan-Keyword [message #1850799 is a reply to message #1850781] |
Thu, 17 March 2022 09:42  |
Eclipse User |
|
|
|
Hi
From a quick scan of the grammar, I see
OpAssign:
'=' | '<' '<' '=';
OpComp:
'<' | '>' | '<' '=' | '>=' | '==';
rather than
OpAssign:
'=' | '<<=';
OpComp:
'<' | '>' | '<=' | '>=' | '==';
The latter allows a lexer to use its normal greedy policy to tokenize directly.
The former shifts the problem to the parser and its backtracking capabilities.
Do you really want to support such free form entry that a <<= assignment can be written
<
/* wait for it*/
< // more on the way
/* here is comes */
=
The difference between Xtend and Xbase is probably due to the differing lexer greediness / backtracking.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.03440 seconds