Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Same rule multiple times
Same rule multiple times [message #1710087] Sun, 04 October 2015 06:45 Go to next message
Mihael Schmidt is currently offline Mihael SchmidtFriend
Messages: 81
Registered: August 2010
Member
Hi,

sorry for this beginner questions but I can't wrap my head around it.

I have the following dsl:

/* this is a comment */
/* another comment*/

start
/* comment */
statements
split +
  statement
/* comment */
another_statement
end 


Comments can occur almost everywhere, before the start, between statements, ...

I started with the grammar:

Program:
	'start'
	statements+=Statement*
	'end';

Statement:
	Comment |
	Command;

Command:
	name=ID;

Comment:
	'/*' content=ID '*/';


But this doesn't cover the cases where the comments are before the start or even after the end.

Thanx in advance.

Mihael
Re: Same rule multiple times [message #1710101 is a reply to message #1710087] Sun, 04 October 2015 08:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14718
Registered: July 2009
Senior Member
is it intended to have the comments explicitely?

Program:
         statements+=Comment*
	'start'
	statements+=Statement*
	'end'
        statements+=Comment*
;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Same rule multiple times [message #1710141 is a reply to message #1710101] Mon, 05 October 2015 06:09 Go to previous messageGo to next message
Mihael Schmidt is currently offline Mihael SchmidtFriend
Messages: 81
Registered: August 2010
Member
Yes. I need the comments (explicitly? any other option?).

Syntax for comments is /* some text */. But /* -> */ is added to the hidden terminals (ML_COMMENT) . Does that mean that these terminals are excluded? How would I "unhide" it?

Thanx in advance

Mihael
Re: Same rule multiple times [message #1710144 is a reply to message #1710141] Mon, 05 October 2015 06:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14718
Registered: July 2009
Senior Member
you can list the hidden token in the hidden(TOKEN1,.....,TOKENN) clause on grammar or rules

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Same rule multiple times [message #1710149 is a reply to message #1710144] Mon, 05 October 2015 06:32 Go to previous messageGo to next message
Mihael Schmidt is currently offline Mihael SchmidtFriend
Messages: 81
Registered: August 2010
Member
Sorry for being a little bit dumb on this but adding the ML_COMMENT to hidden would actually hide it (as it is by default). I need to not have it hidden. Do I have to use my own grammar for this?
Re: Same rule multiple times [message #1710152 is a reply to message #1710149] Mon, 05 October 2015 06:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14718
Registered: July 2009
Senior Member
no simply remove ML_COMMENT from the hidden list of the grammar

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Same rule multiple times [message #1710155 is a reply to message #1710152] Mon, 05 October 2015 06:56 Go to previous messageGo to next message
Mihael Schmidt is currently offline Mihael SchmidtFriend
Messages: 81
Registered: August 2010
Member
declaring a new set of hidden tokens on the top rule did the trick thanks. also now found the section "Hidden Terminal Symbols" in the documenation. =)
Re: Same rule multiple times [message #1710402 is a reply to message #1710155] Tue, 06 October 2015 12:47 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Note that you can also leave the ML_COMMENT rule hidden so you can have comments everywhere and don't need to deal with them throughout the grammar.
Although in that case the comments won't be part of the AST (i.e. the resulting EMF model), there is the parse tree (the node model) that still contains them. So you can obtain them from there when needed.
There is for instance the DocumentationProvider that gives you the comment preceding a given element.

Sven
Re: Same rule multiple times [message #1710444 is a reply to message #1710402] Tue, 06 October 2015 17:00 Go to previous message
Mihael Schmidt is currently offline Mihael SchmidtFriend
Messages: 81
Registered: August 2010
Member
Thank you very much for pointing me to the DocumentationProvider. I think I will go that way.
Previous Topic:SVG export for Xtext Syntax Graph
Next Topic:[Xtext] How to set lower bound?
Goto Forum:
  


Current Time: Thu Sep 26 18:00:12 GMT 2024

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

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

Back to the top