Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Syntax-Error for LessThan-Keyword
Syntax-Error for LessThan-Keyword [message #1850778] Wed, 16 March 2022 18:43 Go to next message
Sebastian Waldhauser is currently offline Sebastian WaldhauserFriend
Messages: 17
Registered: March 2022
Junior Member
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:
{
	a <
}

Syntax-Error on '<': "extraneous input '<' expecting '}'"

{
	a =
}

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 #1850781 is a reply to message #1850778] Wed, 16 March 2022 20:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I have no idea. Did you also check with Xbase / Domainmodel example
Xtend uses flex as lexer, Xbase does not


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Syntax-Error for LessThan-Keyword [message #1850799 is a reply to message #1850781] Thu, 17 March 2022 09:42 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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
Previous Topic:How to avoid ambiguity
Next Topic:Xtext LSP - Validation - @Check annotations
Goto Forum:
  


Current Time: Thu Apr 25 17:56:30 GMT 2024

Powered by FUDForum. Page generated in 5.04907 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top