Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext definition and instance in same grammar
Xtext definition and instance in same grammar [message #1303442] Sat, 19 April 2014 08:37 Go to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 921
Registered: July 2009
Senior Member
Hi,

I have this grammar which has definition of types and instance of them
in the same grammar.


This would be the type definition or Macro in this case:

*********

OBJECT-IDENTITY MACRO ::=
BEGIN
TYPE NOTATION ::=
"STATUS" Status
"DESCRIPTION" Text

VALUE NOTATION ::=
value(VALUE OBJECT IDENTIFIER)

Status ::=
"current"
| "deprecated"
| "obsolete"

ReferPart ::=
"REFERENCE" Text
| empty

-- a character string as defined in section 3.1.1
Text ::= value(IA5String)
END

*********

....and further down an instanceof of it. How do I deal with this?
I can reference the [MACRO] of course, but how does the parser know the
possible attributes and values for the Macro type? Do I need parser
rules in code?


******************

zeroDotZero OBJECT-IDENTITY
STATUS current
DESCRIPTION
"A value used for null identifiers."
::= { 0 0 }

**********************

Thanks ! Christophe
Re: Xtext definition and instance in same grammar [message #1303630 is a reply to message #1303442] Sat, 19 April 2014 11:05 Go to previous message
Christian Dietrich is currently online Christian Dietrich
Messages: 6325
Registered: July 2009
Senior Member
Hi,

i cant follow the "domain specific" part of your DSL (what is a macro, what can it do, and where are the attributes and values)
so let us simplify

Model:
	entities+=Entity
	instances+=Instance
;

Entity:
	"entity" name=ID "{"
		attributes+=Attribute*
	"}"
;

Attribute:
	name=ID ":" type=Type 
;

enum Type :
	string | int | Boolean
;

Instance:
	"instance" name=ID ":" type=[Entity] "{"
		attributeInstances+=AttributeInstance*
	"}"
;

AttributeInstance:
	attribute=[Attribute] "=" value=Literal //or expression 
;

Literal:
	IntLiteral | StringLiteral | BooleanLiteral
;

IntLiteral:
	value=INT
;

StringLiteral:
	value=STRING
;

BooleanLiteral:
	{BooleanLiteral}"false" |(value?="true")
;


with scoping, a type system and a bunch of checks this should work with your case too (if i understood it correct)
Previous Topic:Literal string conflict
Next Topic:Weird marker error in Domain-Model example
Goto Forum:
  


Current Time: Tue Sep 30 12:06:35 GMT 2014

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

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