Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Same rule multiple times
Same rule multiple times [message #1710087] Sun, 04 October 2015 02:45 Go to next message
Eclipse UserFriend
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 04:49 Go to previous messageGo to next message
Eclipse UserFriend
is it intended to have the comments explicitely?

Program:
         statements+=Comment*
	'start'
	statements+=Statement*
	'end'
        statements+=Comment*
;
Re: Same rule multiple times [message #1710141 is a reply to message #1710101] Mon, 05 October 2015 02:09 Go to previous messageGo to next message
Eclipse UserFriend
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 02:16 Go to previous messageGo to next message
Eclipse UserFriend
you can list the hidden token in the hidden(TOKEN1,.....,TOKENN) clause on grammar or rules
Re: Same rule multiple times [message #1710149 is a reply to message #1710144] Mon, 05 October 2015 02:32 Go to previous messageGo to next message
Eclipse UserFriend
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 02:45 Go to previous messageGo to next message
Eclipse UserFriend
no simply remove ML_COMMENT from the hidden list of the grammar
Re: Same rule multiple times [message #1710155 is a reply to message #1710152] Mon, 05 October 2015 02:56 Go to previous messageGo to next message
Eclipse UserFriend
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 08:47 Go to previous messageGo to next message
Eclipse UserFriend
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 13:00 Go to previous message
Eclipse UserFriend
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: Sat Jul 05 01:50:18 EDT 2025

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

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

Back to the top