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:

A KEYWORD
B KEYWORD this
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)

Model:
greetings+=Greeting*;

Greeting:
(name=ID) 'KEYWORD' ANY_OTHER*;


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: 12105
Registered: July 2009
Senior Member
ANY_OTHER actually means: NOT (ID | STRING | KEYWORD | WS | .......)

you could try

Greeting:
	name=ID 'KEYWORD' (ID | ANY_OTHER)*;


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.


	
Greeting:
	name=ID KEYWORD_AND_REST
;

terminal KEYWORD_AND_REST:
	'KEYWORD' !('\n'|'\r')* ('\r'? '\n')?
; 


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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: Tue Jul 17 17:31:05 GMT 2018

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

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

Back to the top