Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Same end tag at multiple level and load referenced model
Same end tag at multiple level and load referenced model [message #660914] Tue, 22 March 2011 10:31 Go to next message
Melanie Bats is currently offline Melanie BatsFriend
Messages: 35
Registered: July 2009
Member
Hello,

My purpose by using Xtext is to handle existing Rhpasody/UML file '.sbs' in order to extract information to an ecore file. So I can't change the language as it is not defined by me. Trying to write the grammar, I encountered two main problems.

The language looks like this :
{ IProject
- _id = GUID 3403c061-230c-4721-b31a-77c4b12d800c;
- _myState = 8192;
- _properties = { IPropertyContainer
- Subjects = { IRPYRawContainer
- size = 8;
- value =
{ IPropertySubject
- _Name = "Collaboration_Diagram";
- Metaclasses = { IRPYRawContainer
- size = 1;
- value =
{ IPropertyMetaclass
- _Name = "Complete";
- Properties = { IRPYRawContainer
- size = 1;
- value =
{ IProperty
- _Name = "Complete_Relation";
- _Value = "True";
- _Type = Bool;
}
}
}
}
}
}
}
- Subsystems = { IRPYRawContainer
- size = 22;
- value = { ISubsystem
- fileName = "MySubSystem";
- _persistAs = "MySubSystem";
- _id = GUID e56f0a78-9565-4726-972c-0a440e64bd89;
}
}
}
}
'
* My first problem is that I want to ignore all the elements defined between : '{ IPropertyContainer' and }'. So I wrote this rule in order to consider all the content of this element as a comment:
terminal ML_COMMENT:
'- _properties = { IPropertyContainer' ->'}';
But as you can see above, my language use the same end tag '}' for each element. So how could I write my rule in order that it considers the "good" end tag '}' associated to the element '{ IPropertyContainer'.

* Second question, the language allows references to other '.sbs' files :
- Subsystems = { IRPYRawContainer
- size = 22;
- value = { ISubsystem
- fileName = "MySubSystem";
- _persistAs = "MySubSystemFolder";
- _id = GUID e56f0a78-9565-4726-972c-0a440e64bd89;
}
}
}
On the disk I have one first main file MainSystem.sbs and under a it a folder wich contains the sbs file describing the sub system:
MainSystem.sbs
MySubSystemFolder
MysubSystem.sbs
So as entry point I have two different 'sbs' files but at the end I expect only one 'ecore' file. In my process, I will use some ATL transformation after Xtext on the result ecore file.

I found in user manual that to load referenced model with same DSL I have to declare a rule that matches the URI token. But in my language, the URI is defined in by two attributes '_persistAs' for the folder and 'filename' for the file. How to use the URI mechanism in this case?

Thanks for your help,
Mélanie
Re: Same end tag at multiple level and load referenced model [message #660980 is a reply to message #660914] Tue, 22 March 2011 14:31 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Hi, I can help with your first question...

On 3/22/11 11:31 AM, Melanie Bats wrote:

> * My first problem is that I want to ignore all the elements defined
> between : '{ IPropertyContainer' and }'. So I wrote this rule in order
> to consider all the content of this element as a comment:
> terminal ML_COMMENT:
> '- _properties = { IPropertyContainer' ->'}';
> But as you can see above, my language use the same end tag '}' for each
> element. So how could I write my rule in order that it considers the
> "good" end tag '}' associated to the element '{ IPropertyContainer'.
>
AFAIK, the -> operator is non greedy. Naturally, if there are '{' '}'
pairs until the end '}' is found they it will not work as the first '}'
would be used.

You can approach this in two ways:
a) Use data type rules instead of terminals to enable describing a
grammar that finds balanced braces and thus understands when the
statement ends.
b) Use an external lexer where you have the flexibility to detect
balanced braces.

a) is easier (less work), but not if there are constructs that are
difficult to parse in the section you want to "skip"

b) more work, but also a lot more flexibility - you write an antlr lexer
and add it to the mwe2 workkflow - keeping this lexer in sync with an
evolving grammar takes a bit of work, but it is otherwise quite straight
forward.

I recommend against using an overridden ML_COMMENT terminal for this.
There are featured tied to ML_COMMENTS that are not suitable in this
case (auto edits that inserts * at the left margin etc). Suggest you use
a different terminal and make it hidden in the grammar.

Regards
- henrik
Previous Topic:Does XText 1.0.1 support syntactic predicates?
Next Topic:IScope provider Question
Goto Forum:
  


Current Time: Fri Apr 26 15:19:34 GMT 2024

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

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

Back to the top