Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Issue generating a DSL grammar
Issue generating a DSL grammar [message #989920] Mon, 10 December 2012 02:18 Go to next message
John Castano is currently offline John CastanoFriend
Messages: 7
Registered: December 2012
Junior Member
Hi all,

I'm trying to generate a grammar to specify condition inside operations belonging to an entity, but i have some doubts because i want use attributes of an entity inside another one and these aren't visible. This is my grammar.


grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "/MyDsl"

MyDsl:
(elements+=AbstractElement)*;

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

AbstractElement:
PackageDeclaration | Type | Import;

QualifiedName:
ID ('.' ID)*;

Import:
'import' importedNamespace=QualifiedNameWithWildcard;

QualifiedNameWithWildcard:
QualifiedName '.*'?;

Type:
DataType | Entity;

DataType:
'datatype' name=ID;

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

Attributes:
name=ID ':' tipo=[Type];



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

Operations:
'define op ' name=ID '(' parameters=ID ':' type=[Type] ')' '{' (precondition+=Preconditions)* '}';

Preconditions:
'precondition :' entidad=[Entity] 'NOT IN' atri=[Attributes];



-----


Semantic Model.


package co.edu.eu{

import co.edu.eu.*


datatype String
datatype Numeric
datatype Boolean
datatype Date

entity Organizacion
{
nombre : String
nit : String
pais : String

listaUsuarios : Usuario


define op InsertarUsuario (usuario: Usuario){

//precondition = usuario not in listaUsuarios
//postcondition = usuario not in listaUsuarios and organizacion.pais = usuario.pais

}
}

entity Usuario
{
nombre: String
cedula:String
Pais:String

}

entity empleados extends co.edu.eu.Usuario{
nombre: Date
}

entity Dependencia
{
nombre: String
}

}





Thanks in advance.

Re: Issue generating a DSL grammar [message #989929 is a reply to message #989920] Mon, 10 December 2012 06:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi Xtext builds hierarchical qualified names by default.
You can

(1) change Iqualifiednameprovider
(2) change grammar
Attributes=[Attributes|FQN] ...
FQN:ID ('." ID)*;
(3) introduce a local scoping method
IScope scope_ Preconditions_atri(Preconditions CTX, ereference ref) {
List attr = ...
Return Scopes.scopefor(attr);
}

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Issue generating a DSL grammar [message #990132 is a reply to message #989929] Tue, 11 December 2012 03:27 Go to previous message
John Castano is currently offline John CastanoFriend
Messages: 7
Registered: December 2012
Junior Member
Thank you so much.

I changed the grammar as follows, And I solved the problem , Is this the solution you propose me? :


grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "MyDsl"

MyDsl:
(elements+=AbstractElement)*;

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

AbstractElement:
PackageDeclaration | Type | Import;

QualifiedName:
ID ('.' ID)*;

Import:
'import' importedNamespace=QualifiedNameWithWildcard;

QualifiedNameWithWildcard:
QualifiedName '.*'?;

Type:
DataType | Entity;

DataType:
'datatype' name=ID;

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

/*Attributes:
name=ID ':' tipo=[Type];*/


/*Attributes: name = ID ('atribute' attribute = [Attributes|FQN])?;*/

/*
FQN:
ID ('.' ID)*;
*/

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

Attributes:
(many ?= 'many')? name = ID ':' type = [Type | QualifiedName];


Operations:
'define op ' name=ID '(' parameters=ID ':' type=[Type] ')' '{' (precondition+=Preconditions)* '}';

Preconditions:
'precondition :' entidad=[Entity] 'NOT IN' attribute=[Attributes|QualifiedName];
Previous Topic:[Syntactic predicates] Choosing alternative path 2
Next Topic:Is there an Xtend-Interpreter
Goto Forum:
  


Current Time: Fri Apr 19 18:38:20 GMT 2024

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

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

Back to the top