Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Import built-in types as qualified names
Import built-in types as qualified names [message #1407392] Tue, 12 August 2014 13:51 Go to next message
Pavlina Temelakieva is currently offline Pavlina TemelakievaFriend
Messages: 10
Registered: July 2014
Junior Member
Hey everyone,

My model language requires for built-in types to be imported in the file where they are used. The problem is that those types looks like this: 'com.type.ID' 'com.type.Binary' 'com.type.DynamicStructure' etc. I tried making grammar for that and here is what I could think of:

DomainModel:
packageDeclaration=PackageDeclaration;

PackageDeclaration:
"package" name=QualifiedName ";" importDeclarations+=ImportDeclaration*
abstractTypeDeclarations+=AbstractTypeDeclaration+;

ImportDeclaration:
"import" importedNamespace=QualifiedName ";";

AbstractTypeDeclaration:
modifier+=ClassOrInterfaceModifier* typeDeclaration=TypeDeclaration;

TypeDeclaration:
ClassDeclaration |
EnumDeclaration | InterfaceDeclaration
....

TypeRef:
SimpleTypeRef | Type;

SimpleTypeRef:
DynamicStructure;

DynamicStructure:
{DynamicStructure} 'com.type.DynamicStructure' (also tried with name='com.type.DynamicStructure');

Type:
referencedType=[TypeDeclaration|QualifiedName];


I am able to reference TypeRef for field parameter types for example:
FieldDeclaration:
type=TypeRef variableName=ValidID ';';

and it works. But when I try to use it as part of import statements it says 'Mismatch input 'com.type.DynamicStruture' expects 'RULE_ID'' and I suspect it is because of the QualifiedName definition of the ImportStatement.

Is it possible what I am trying to do? Or is it wrong?

Thanks a lot in advance!

Re: Import built-in types as qualified names [message #1407397 is a reply to message #1407392] Tue, 12 August 2014 13:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
Hi,

lexing and parsing is done in two steps

=> com.type.DynamicStructure is always lexed as a keyword and not as an ID.

you can introduce an

XID: 'com.type.DynamicStructure' | ID; and use that instead of id

of you do not hardcode this packages


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import built-in types as qualified names [message #1408054 is a reply to message #1407397] Thu, 14 August 2014 05:59 Go to previous messageGo to next message
Pavlina Temelakieva is currently offline Pavlina TemelakievaFriend
Messages: 10
Registered: July 2014
Junior Member
Hey Christian,

Thanks for your response but I still can't make it work. What do you mean by use XID: 'com.type.DynamicStructure' | ID istead of id? Does this mean I have to create new rule for QualifiedName as well? If so, wouldn't that break my current functionallity, because I want to be able to import other types as well (not only built-in types)?
I tried changing my grammar to:


....

TypeRef:
SimpleTypeRef | Type;

SimpleTypeRef:
name=(DynamicStructure | ID);


DynamicStructure:
{DynamicStructure} 'com.type.DynamicStructure'

Type:
referencedType=[TypeDeclaration|QualifiedName];

but there wasn't much of a difference.

Could you elaborate a bit more on that?Thanks.
Re: Import built-in types as qualified names [message #1408064 is a reply to message #1408054] Thu, 14 August 2014 06:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
Hi,

your QualifiedName rule (that may be ID ("." ID)* and the com.type.DynamicStructure conflict.

why do you hardcode this com.type.DynamicStructure thing.

id replace that with quailifiedName in the first place.

or you have to take care that com.type.DynamicStructure is parsed by the quailifiedName rule a well (wich might be very hard)

i dont know if it help to replace

com.type.DynamicStructure with a datatype rule

WiredStuffYouShouldNotDo : "com" "." "type" "." "DynamicStructure"

and

XID: "com" | "type" | "DynamicStructure" | ID;

QualifiedNAme: XID ("." XID)*



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import built-in types as qualified names [message #1408091 is a reply to message #1408064] Thu, 14 August 2014 07:56 Go to previous message
Pavlina Temelakieva is currently offline Pavlina TemelakievaFriend
Messages: 10
Registered: July 2014
Junior Member
I understood now. Thank you! I was trying to make the whole 'com.type.DynamicStructure' to be a QualifiedName (unsuccessfully), but your solution is cool. Thanks!
Previous Topic:Building Xtext Languages with Maven and Gradle
Next Topic:Implicit imports and and plug-in resources
Goto Forum:
  


Current Time: Thu Dec 05 21:46:52 GMT 2019

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

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

Back to the top