Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-reference: a set of constants of Enum(Cross-reference: a set of constants of Enum)
Cross-reference: a set of constants of Enum [message #1738785] Sun, 24 July 2016 10:42 Go to next message
Rotem Ge is currently offline Rotem GeFriend
Messages: 1
Registered: July 2016
Junior Member

Hi,
I try to write new grammar and I wrote something like Enum in Java, that enables for Var (a type in my grammar) to be a set of predefined constants.

I want it to recognize the constants that include to this Var, but I didn't find a way how to do it (although I try to read the book "Implementing Domain-Specific Languages with Xtext and Xtend", and searched a lot on the internet)

So I made a little example on the Domainmodel grammar:


Domainmodel:
(elements+=AbstractElement)*;

PackageDeclaration:
'package' name=QualifiedName '{'
(elements+=AbstractElement)*
'}';

AbstractElement:
PackageDeclaration | Type | Import;

QualifiedName:
ID ('.' ID)*;

Import:
'import' importedNamespace=QualifiedNameWithWildcard;

QualifiedNameWithWildcard:
QualifiedName '.*'?;

Type:
DataType | Entity | Var;

DataType:
'datatype' name=ID;

Entity:
'entity' name=ID ('extends' superType=[Entity|QualifiedName])? '{'
(features+=Feature)*
'}';

Feature:
(many?='many')? name=ID ':' type=[VarDecl |QualifiedName];

Var:
kind='Var' var=VarDecl;

VarDecl:
type=VarType name=SimpleVarID;

SimpleVarID:
ID ('[' INT ']')*;

VarType:
name='boolean'
| '{' const+=TypeConstant (',' const+=TypeConstant)* '}';

TypeConstant:
ID | INT | 'FALSE' | 'TRUE';


So, the example is:

Var {LEFT,RIGHT} move

entity C {
content: move
side: LEFT //ERROR: couldn't resolve reference to VarDecl 'LEFT'
}

I know that LEFT it's not VarDecl, it's ID, but I don't know how to do it different.
What I need to do so that LEFT would be recognize like something that include to move?
comment: in my real grammar I actually try to do move==LEFT (boolean operator) and it's not recognize LEFT as constant of move (the same error appears) .


Thanks!
Re: Cross-reference: a set of constants of Enum [message #1738888 is a reply to message #1738785] Mon, 25 July 2016 17:31 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
you have the special prefix "^" which allows keywords to be used as IDs
Previous Topic:Xtext with content dependent grammar
Next Topic:IAE Exception when no type name.
Goto Forum:
  


Current Time: Sat Nov 09 02:19:33 GMT 2024

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

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

Back to the top