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: 11
Registered: March 2022
Junior Member

given the grammar:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "org/example/mydsl/MyDsl"

	'{' statements+=Statement* '}';



	ComparisonExpression (=>({BinaryExpression.lhs=current} operator=OpAssign)

	'=' | '<' '<' '=';

	Primary (=>({BinaryExpression.lhs=current} operator=OpComp)

	'<' | '>' | '<' '=' | '>=' | '==';


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,
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: 14424
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

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
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: 7564
Registered: July 2009
Senior Member

From a quick scan of the grammar, I see

	'=' | '<' '<' '=';

	'<' | '>' | '<' '=' | '>=' | '==';

rather than

	'=' | '<<=';

	'<' | '>' | '<=' | '>=' | '==';

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.


Ed Willink
Previous Topic:How to avoid ambiguity
Next Topic:Xtext LSP - Validation - @Check annotations
Goto Forum:

Current Time: Mon Jan 30 02:56:04 GMT 2023

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

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

Back to the top