Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Recognize trailing text as a comment
Recognize trailing text as a comment [message #1773947] Sat, 07 October 2017 04:25 Go to next message
Joseph Reynolds is currently offline Joseph ReynoldsFriend
Messages: 1
Registered: October 2017
Junior Member
I have a DSL that treats anything that follows the last recognized keyword token as a comment. I am having trouble creating a grammar for this.

Simplified example file:

C KEYWORD this is an error

Grammar thus far:

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

generate myDsl ... (cannot post the real link since I'm such a newbie)



The first two lines are error free - no comment and a single word comment.
For the third line, these errors are given:

Multiple markers at this line
- mismatched input '<EOF>' expecting 'KEYWORD'
- missing 'KEYWORD' at 'is'
- extraneous input 'C' expecting 'KEYWORD'
- missing 'KEYWORD' at 'error'
- missing 'KEYWORD' at 'an'

I am new to Xtext so hope that I have overlooked a simple solution.

The <EOF> message appears if I have pressed newline after the last line, but there is no <EOF> message if I do not press newline. I assume that when the file is ultimately parsed there will be an <EOF> so have to solve that issue too.

Thanks for your help.

Re: Recognize trailing text as a comment [message #1774113 is a reply to message #1773947] Tue, 10 October 2017 16:41 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12322
Registered: July 2009
Senior Member
ANY_OTHER actually means: NOT (ID | STRING | KEYWORD | WS | .......)

you could try


but depending on the complexity of the grammar that might not work

Xtext is not linebased.

you could try to introduce a terminal that eats up everything from the keyword till the end of the like e.g.


	'KEYWORD' !('\n'|'\r')* ('\r'? '\n')?

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Previous Topic:Xbase Initializing Values in XVariableDeclaration in (Method-) Body
Next Topic:Open an dsl file in xtext editor takes long time
Goto Forum:

Current Time: Thu Oct 18 00:15:02 GMT 2018

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

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

Back to the top