Skip to main content



      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 09:51 Go to next message
Eclipse UserFriend
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 09:57 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Import built-in types as qualified names [message #1408054 is a reply to message #1407397] Thu, 14 August 2014 01:59 Go to previous messageGo to next message
Eclipse UserFriend
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 02:31 Go to previous messageGo to next message
Eclipse UserFriend
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)*

Re: Import built-in types as qualified names [message #1408091 is a reply to message #1408064] Thu, 14 August 2014 03:56 Go to previous message
Eclipse UserFriend
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: Sun Jul 13 10:42:19 EDT 2025

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

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

Back to the top