| 
| Issue generating a DSL grammar [message #1016319] | Tue, 05 March 2013 21:41  |  | 
| Eclipse User  |  |  |  |  | Hi all, 
 I am trying of create a grammar in order to define the method body and then generate code in some programming languaje.  I want to do something like this :
 
 
 package example {
 
 import example.*
 
 
 datatype String
 datatype Numeric
 datatype Boolean
 datatype Date
 
 entity Organization
 {
 name : String
 id :  String
 country : String
 
 userList : User
 
 
 define op createUser (user: User){
 
 precondition : user.name NOT IN userList
 
 
 }
 }
 
 entity User
 {
 name: String
 govId:String
 country:String
 
 }
 
 
 entity Employee extends example.User{
 fecha: Date
 }
 
 entity Dependency
 {
 name: String
 
 }
 
 }
 
 
 I have a problem when i want to get the attributes of the input parameters of the Method as you can see in the image in red color . I dont know how i can modify my grammar with the purpose i can get the attributes of the objet used as input to the method.  My grammar is as follows
 
 
 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:
 (many ?= 'many')? name = ID ':' type = [Type | QualifiedName];
 
 
 Operations:
 'define op ' name=ID '(' parameter = Parameters ')' '{' (precondition+=Preconditions)* '}';
 
 
 Parameters:
 name=ID ':' type=[Type|QualifiedName];
 
 Preconditions:
 'precondition :' param=[Parameters|QualifiedName] 'NOT IN' attribute=[Attributes|QualifiedName];
 
 
 
 
 Thanks in Advance
 
 |  |  |  | 
|  | 
|  | 
| 
| Re: Issue generating a DSL grammar [message #1031015 is a reply to message #1016499] | Mon, 01 April 2013 00:12   |  | 
| Eclipse User  |  |  |  |  | Hi Christian, 
 I did what you recommended me and It Works partially.
 
 I put your instrutions (red color) with some changes (blue color) in the Scope   Class, but i have a problem trying to pass the arguments to the method named "scopeFor" when i translated the code "[Attributes a|QualifiedName::create(ctx.parameter.name, a.name)]"  because an argument type function is mandatory. If I omit this parameter , i can get the attributes of the entity without a Qualified part.
 
 
 public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
 
 IScope scope_Preconditions_param(Operations ctx, EReference ref) {
 //		if (ctx.parameter.type instanceof Entity) {
 //			Scopes.scopeFor((ctx.parameter.type as Entity).attribute, [Attributes a|QualifiedName::create(ctx.parameter.name, a.name)], IScope::NULLSCOPE)
 //		} else{
 //			IScope :: NULLSCOPE
 //		}
 if(ctx.getParameter().getType() instanceof Entity) {
 return Scopes.scopeFor (((Entity)(ctx.getParameter().getType())).getAttribute()/*,QualifiedName.create(ctx.getParameter().getName())*/, IScope.NULLSCOPE);
 } else {
 return IScope.NULLSCOPE;
 }
 }
 
 }
 
 Do you know how can i solve this issue?
 
 Thanks in advance for your help.
 
 |  |  |  | 
|  | 
|  | 
|  | 
|  | 
|  | 
Powered by 
FUDForum. Page generated in 0.05741 seconds