Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Ignore All text between a scope(How can I ignore all text and characters in a specific scope?)
Ignore All text between a scope [message #1768585] Thu, 20 July 2017 09:26 Go to next message
Rodrigue Sandio is currently offline Rodrigue SandioFriend
Messages: 8
Registered: May 2017
Junior Member
Hi All,
I need to implement a model that will parse a state-machine and generate code from it. However, I am only interested in a specific part of the file.
The goal is to ignore all character that comes in between the keyword "behaviour" and "}" (see below)

interface Interface
{
in void function(const_char_ptr message);

behaviour
{
enum States {Initial};

States m_State = States.Initial;

[m_State.Initial]
{
on function: {}
}

}
}
How to achieve this? what is the best approached?

Thanks
Re: Ignore All text between a scope [message #1768737 is a reply to message #1768585] Sun, 23 July 2017 02:04 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

That's not possible, since the closing brace is also a terminal in the regular language. In order to "ignore" a chunk of text this has to be lexed as a single token and make it a hidden token:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
hidden(WS, ML_COMMENT, SL_COMMENT, BEHAVIOUR)

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID '!';

terminal BEHAVIOUR : 'behaviour' -> 'end_behaviour';



You could use the "end-statement" after your closing brace in a comment to make it look as a comment, but the closing keyword would be mandatory:
behaviour
{
 ... do code here
} // end_behaviour
Re: Ignore All text between a scope [message #1769252 is a reply to message #1768737] Fri, 28 July 2017 09:07 Go to previous message
Rodrigue Sandio is currently offline Rodrigue SandioFriend
Messages: 8
Registered: May 2017
Junior Member
Hi Thoms, Thanks for the hint. It does work pretty well.

However my teammates are a bit reluctant with the idea as they say it is a new constraint (to always include "// end_behaviour") they need to take care of when designing the state-machines in the original language.

For now we will use this while investigating workarounds.

Thanks again :)

Previous Topic:Automatic editor update
Next Topic:Couldn't resolve reference to FunctionblockModel 'RainSensor'.
Goto Forum:
  


Current Time: Tue Mar 19 03:55:47 GMT 2024

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

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

Back to the top