Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » What i need to use for get entities-attributes in a variable?(var=entity ... var.atributte ??)
What i need to use for get entities-attributes in a variable? [message #771653] Tue, 27 December 2011 21:06 Go to next message
Federico Sellanes is currently offline Federico SellanesFriend
Messages: 71
Registered: November 2011
Member
Hi, suposse in my DSL y load variables with entities in a cross reference some like :

module MODULE_NAME{
    entity ENTITY_NAME {
         int code,
         text name
    }

    function FUNCTION_NAME(){
         var VAR_NAME as MODULE_NAME.ENTITY_NAME ; // Working
         var.code = 1 // How achieve this ?
    }
}


One of my rules is :

VarDeclaration :
    declaration='var' name='ID' ('as' type=[Entity|QualifiedName]) ('=' exp=Expression)?
;


Some suggestion about where i need to investigate?

Thanks and sorry for my lot of questions, read all the doc when you dont speak english is sometimes hard.

[Updated on: Wed, 28 December 2011 11:31]

Report message to a moderator

Re: What i need to use for get entities-attributes in a variable? [message #771656 is a reply to message #771653] Tue, 27 December 2011 21:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

there are a lot of possibilties for that
have a look at http://dslmeinte.wordpress.com/2010/08/16/path-expressions-in-entity-models/
to get one

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: What i need to use for get entities-attributes in a variable? [message #773750 is a reply to message #771653] Mon, 02 January 2012 12:58 Go to previous messageGo to next message
Federico Sellanes is currently offline Federico SellanesFriend
Messages: 71
Registered: November 2011
Member
Hi, i finally get it. Now i am trying to replace the slash '/' by a dot '.'

This is my example code:


grammar org.example.domainmodel.Domainmodel with org.eclipse.xtext.common.Terminals

generate domainmodel "http://www.example.org/domainmodel/Domainmodel"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

ModuleDeclaration:
	'module' name=QualifiedName '{'
	(elements+=AbstractElement)*
	'}';

AbstractElement:
	Import |Entity | ModuleFunction;

QualifiedName:
	ID ('.' ID)*;

Import:
	'import' importedNamespace=QualifiedNameWithWildcard ';';

QualifiedNameWithWildcard:
	QualifiedName '.*'?;

Type:
	DataType | Entity;

DataType:
	'int'
	| 'STRING';

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

Feature:
	name=ID featureType=[Type];

VariableDeclaration:
	name=ID 'as' variableType=[Entity] ('=' assignament=ID)?;

PathDefinition:
	PathHead ('=' assignament=ID)?;

PathHead:
	entity=[VariableDeclaration] (tail=PathTail)?;

PathTail:
	'/' feature=[Feature] (pathTail=PathTail)?;

ModuleFunction:
	'function' name=ID functionImplmenentation=FunctionImplementation;

FunctionImplementation:
	parameterDeclaration=FunctionParametersDeclaration codeBlock=CodeBlock;

FunctionParametersDeclaration:
	'(' (args+=ID (',' args+=ID)*)? ')';

CodeBlock:
	'{' (statements+=Statement)* '}';

Statement:
	(CallFunction | VariableDeclaration | PathDefinition) ';';

CallFunction:
	ModuleFunctionCall //|
;

ModuleFunctionCall:
	function=[ModuleFunction | QualifiedName] parametersInvocation=FunctionParametersInvocation;

FunctionParametersInvocation:
	'(' args+=Expression ((',' args+=Expression)*)? ')';

Expression:
	ID*;
	


And my scope provider :


	IScope scope_PathTail_feature(final EObject context, EReference ref) {
	    EObject parent = context.eContainer();
		
	    if( parent instanceof PathHead ) {
	        return org.eclipse.xtext.scoping.Scopes.scopeFor(((PathHead) parent).getEntity().getVariableType().getFeatures());
	    }
	    
	    if( parent instanceof PathTail ) {
	
	    	Type type = ((PathTail) parent).getFeature().getFeatureType();

	    	if(type instanceof Entity){
	    		return org.eclipse.xtext.scoping.Scopes.scopeFor(((Entity)type).getFeatures() );    			
	    	}else{
	    		EList<Feature> features = (EList<Feature>) new ArrayList<Feature>();
	        	return org.eclipse.xtext.scoping.Scopes.scopeFor(features);
	    	}	                
	    }
	   
	    // Fall-through? Probably a programmer error...
	    throw new RuntimeException("don't know how to compute scope for 'feature' of PathTail");
	}
	


Reading this http://dslmeinte.wordpress.com/2010/12/08/getting-alternative-cross-references-to-work-with-existing-epackages/ a lot of times I understand that I need to change my code and use [ecore::EObject] in some places, maybe in the PathTail rule but what i have to do in the scope if i use [ecore::EObject] ?.

If i change :


PathTail:
	'/' feature=[Feature] (pathTail=PathTail)?;



to :


PathTail:
	'.' feature=[ecore::EObject] (pathTail=PathTail)?;



I still having compile errors.

So, my conclusion is that the parser cant distinguish a 'module.function' / 'var.attribute', because if i replace the rule


ModuleFunctionCall:
	function=[ModuleFunction | QualifiedName] parametersInvocation=FunctionParametersInvocation;



to


ModuleFunctionCall:
	function=[ModuleFunction] parametersInvocation=FunctionParametersInvocation;



I lost the qualifiedNames but i haven't problems with the '.' in the PathTail rule.

Sincerely i can't understand the example and the solution provided by Meinte,and I dont know how implement the solution in my case.

Can you guide me, anything will help me.
Thanks.





[Updated on: Mon, 02 January 2012 13:53]

Report message to a moderator

Re: What i need to use for get entities-attributes in a variable? [message #773803 is a reply to message #773750] Mon, 02 January 2012 15:30 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Your suspicion seems right: the '.' in the PathTail rule and the '.''s in the QualifiedName rule interfere with each other. There's no way the parser can distinguish between an ID being part of a QualifiedName or being the name of a Feature. There's no way that you're going to solve this with =[ecore::EObject] trick as that only works with references for which the referring name has already been established and in your case the invocation of QualifiedName gobbles up the whole path.

The easiest way to get around this, is to switch to using another character for PathTail. Alternatively, Xbase solves the same problem since something like "java.util.ArrayList.get(0).someFeature" has the same problem.


Re: What i need to use for get entities-attributes in a variable? [message #774159 is a reply to message #771653] Tue, 03 January 2012 11:39 Go to previous messageGo to next message
Federico Sellanes is currently offline Federico SellanesFriend
Messages: 71
Registered: November 2011
Member
Thanks for save my time.

Unfortunately i cannot change the '.' by a '/' in the sintax of the dsl that i have been working, is not my desicion.

I need the '.' o forget the path expressions. So i will discard the "easy way".

Quote:

Alternatively, Xbase solves the same problem since something like "java.util.ArrayList.get(0).someFeature" has the same problem.


I not understand that, but, I will investigate more about xbase which I know very little.

Thanks. Anything you can suggest will be util.
Re: What i need to use for get entities-attributes in a variable? [message #784571 is a reply to message #771653] Fri, 27 January 2012 18:05 Go to previous messageGo to next message
Federico Sellanes is currently offline Federico SellanesFriend
Messages: 71
Registered: November 2011
Member
Hi again... Smile

This is my test grammar :


grammar org.xtext.example.eal.Eal with org.eclipse.xtext.common.Terminals

generate eal "http://www.xtext.org/example/eal/Eal"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

/**************************************/
/*************** Module ***************/
/**************************************/

ModuleModel:
	'module' name=QualifiedName '{'
	('description' description=STRING)? ';'
	(Entities+=Entity
	| Functions+=UserFunction
	| Imports+=Import)*
	'}';
	
Import:
	imp='import' importedNamespace=QualifiedNameWithWildcard ';' ;
	
QualifiedName:
	ID ('.' ID)*;
	
QualifiedNameWithWildcard:
	QualifiedName '.*'?;
	
/**************************************/
/*************** Entity ***************/
/**************************************/

Entity:
	entity='entity' name=ID ('table' tableName=ID)? '{'
	attributes+=Attribute ((',' attributes+=Attribute)?)*
	'}';

Attribute:
	(dataType=DataType | entityType=[Entity])
	name=ID (identifier='identifier')? (discriminator='discriminator')?
	(('column') columnId+=ID (',' columnId+=ID)* | ('attribute') attributeId+=ID (',' attributeId+=ID)*)?;

/**************************************/
/************** Datatype **************/
/**************************************/

DataType:
	(date='date'
	| bool='bool'
	| time='time'
	| int='int'
	| numeric='numeric' '[' INT ',' INT ']'
	| string='string' '[' INT ']'
	| list='list' '<' entity=[Entity] '>'
	);	
	
/**************************************/
/************ UserFunction ************/
/**************************************/
	
UserFunction:
	'function' name=ID implementation=FunctionImplementation;

FunctionImplementation:
	functionParametersDeclaration=FunctionParametersDeclaration codeblock=Codeblock;

FunctionParametersDeclaration:
	'(' (args+=ParameterDeclaration (',' args+=ParameterDeclaration)*)? ')';
	
Codeblock:
	'{' (satements+=Statement)* '}'
;

ParameterDeclaration:
	AbstractParameterDeclaration | ParameterDeclarationType
;

AbstractParameterDeclaration:
	name=ID
;

ParameterDeclarationType:
	name=ID 'as' type=[Entity]
;

/**************************************/
/********** PathExpressions ***********/
/**************************************/ 

QualifiedNameDefinition:
	QualifiedNameHead
;

QualifiedNameHead:
	ID (tail=QualifiedNameTail)?
;

QualifiedNameTail:
	'.' attribute=[ecore::EObject ] (tail=QualifiedNameTail)?
;
	
/**************************************/
/************* Variables **************/
/**************************************/ 

VariableDeclaration:
	AbstractVariableDeclaration | VariableDeclarationType
;

AbstractVariableDeclaration:
	QualifiedNameDefinition
;

VariableDeclarationType:
 	'var' name=ID 'as' type=[Entity]
;

VariableAssignment:
	VariableDeclaration ('=' expression=Expression)? 
;

/**************************************/
/************* Statement **************/
/**************************************/ 

Statement:
	VariableAssignment ';'
;

/**************************************/
/************ Expression **************/
/**************************************/ 


Expression:
	(expression+=ExpAnd) ('||' expression+=ExpAnd)*;

ExpAnd:
	(expAnd+=ExpComp)
	('&&' expAnd+=ExpComp)*;

ExpComp:
	(expComp+=ExpMasMenos)
	('==' expComp+=ExpMasMenos
	| 'like' expComp+=ExpMasMenos
	| '!=' expComp+=ExpMasMenos
	| '<' expComp+=ExpMasMenos
	| '>' expComp+=ExpMasMenos
	| '>=' expComp+=ExpMasMenos
	| '<=' expComp+=ExpMasMenos)*;

ExpMasMenos:
	(expMasMenos+=ExpMultDiv)
	('+' expMasMenos+=ExpMultDiv
	| '-' expMasMenos+=ExpMultDiv)*;

ExpMultDiv:
	(expMultDiv+=ExpMenos)
	('*' expMultDiv+=ExpMenos
	| '/' expMultDiv+=ExpMenos
	| '\\' expMultDiv+=ExpMenos
	| '^' expMultDiv+=ExpMenos
	| '%' expMultDiv+=ExpMenos)*;

ExpMenos:
	'-' ExpNo
	| ExpNo;

ExpNo:
	'!' QualifiedNameDefinition
	| QualifiedNameDefinition;



Maybe the rule names are incorrect, but this is my sample grammar so dont worry about that.

What i trying to get now, is, avoid a warning error :

http://img201.imageshack.us/img201/4230/pngmu.png

How you can see, my grammar allows to declare in codeblocks (pseudocode) :

var NAME as [Entity] = Expression


So, when i :

NAME. //-> In the scope I get all the features of the Entity in the cross reference.


But, my grammar allows too to declare variables without a defined type.

So is correct to said :

variable = data.data


And if "data" is a variable with type, I get the features of the entity but if "data" is a abstract variable, I want to allow everything. I.E.

function CalcPrice(){
variable = something.something // I get error because something.something is not a EObject
}


So, where I can avoid this error?, Validation? ScopeProvider?

The compiler is already done, so i dont need to know wich object is in the variable.variable,this is especific for a variable content assist.

Thanks, in advance.

  • Attachment: png.png
    (Size: 13.22KB, Downloaded 142 times)
Re: What i need to use for get entities-attributes in a variable? [message #784801 is a reply to message #784571] Sat, 28 January 2012 01:38 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
The grammar for expressions looks wrong - you are losing information.

As an example:

ExpMasMenos:
(expMasMenos+=ExpMultDiv)
('+' expMasMenos+=ExpMultDiv
| '-' expMasMenos+=ExpMultDiv)*;

Will give you a list of ExpMultDiv instances in ExpMasMenos, but the '+'
and '-' operators are lost. And since the only data is QualifiedName
definition, everything is reduced to nested lists of symbols.

Is that all you want to get after parsing? If not, you need to address
this first before thinking about cross referencing. (Look at some of the
Expression examples).

Regards
- henrik

On 2012-27-01 19:06, Federico Sellanes wrote:
> Hi again... :)
>
> This is my test grammar :
>
>
>
> grammar org.xtext.example.eal.Eal with org.eclipse.xtext.common.Terminals
>
> generate eal "http://www.xtext.org/example/eal/Eal"
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> /**************************************/
> /*************** Module ***************/
> /**************************************/
>
> ModuleModel:
> 'module' name=QualifiedName '{'
> ('description' description=STRING)? ';'
> (Entities+=Entity
> | Functions+=UserFunction
> | Imports+=Import)*
> '}';
>
> Import:
> imp='import' importedNamespace=QualifiedNameWithWildcard ';' ;
>
> QualifiedName:
> ID ('.' ID)*;
>
> QualifiedNameWithWildcard:
> QualifiedName '.*'?;
>
> /**************************************/
> /*************** Entity ***************/
> /**************************************/
>
> Entity:
> entity='entity' name=ID ('table' tableName=ID)? '{'
> attributes+=Attribute ((',' attributes+=Attribute)?)*
> '}';
>
> Attribute:
> (dataType=DataType | entityType=[Entity])
> name=ID (identifier='identifier')? (discriminator='discriminator')?
> (('column') columnId+=ID (',' columnId+=ID)* | ('attribute') attributeId+=ID (',' attributeId+=ID)*)?;
>
> /**************************************/
> /************** Datatype **************/
> /**************************************/
>
> DataType:
> (date='date'
> | bool='bool'
> | time='time'
> | int='int'
> | numeric='numeric' '[' INT ',' INT ']'
> | string='string' '[' INT ']'
> | list='list' '<' entity=[Entity]'>'
> );
>
> /**************************************/
> /************ UserFunction ************/
> /**************************************/
>
> UserFunction:
> 'function' name=ID implementation=FunctionImplementation;
>
> FunctionImplementation:
> functionParametersDeclaration=FunctionParametersDeclaration codeblock=Codeblock;
>
> FunctionParametersDeclaration:
> '(' (args+=ParameterDeclaration (',' args+=ParameterDeclaration)*)? ')';
>
> Codeblock:
> '{' (satements+=Statement)* '}'
> ;
>
> ParameterDeclaration:
> AbstractParameterDeclaration | ParameterDeclarationType
> ;
>
> AbstractParameterDeclaration:
> name=ID
> ;
>
> ParameterDeclarationType:
> name=ID 'as' type=[Entity]
> ;
>
> /**************************************/
> /********** PathExpressions ***********/
> /**************************************/
>
> QualifiedNameDefinition:
> QualifiedNameHead
> ;
>
> QualifiedNameHead:
> ID (tail=QualifiedNameTail)?
> ;
>
> QualifiedNameTail:
> '.' attribute=[ecore::EObject ] (tail=QualifiedNameTail)?
> ;
>
> /**************************************/
> /************* Variables **************/
> /**************************************/
>
> VariableDeclaration:
> AbstractVariableDeclaration | VariableDeclarationType
> ;
>
> AbstractVariableDeclaration:
> QualifiedNameDefinition
> ;
>
> VariableDeclarationType:
> 'var' name=ID 'as' type=[Entity]
> ;
>
> VariableAssignment:
> VariableDeclaration ('=' expression=Expression)?
> ;
>
> /**************************************/
> /************* Statement **************/
> /**************************************/
>
> Statement:
> VariableAssignment ';'
> ;
>
> /**************************************/
> /************ Expression **************/
> /**************************************/
>
>
> Expression:
> (expression+=ExpAnd) ('||' expression+=ExpAnd)*;
>
> ExpAnd:
> (expAnd+=ExpComp)
> ('&&' expAnd+=ExpComp)*;
>
> ExpComp:
> (expComp+=ExpMasMenos)
> ('==' expComp+=ExpMasMenos
> | 'like' expComp+=ExpMasMenos
> | '!=' expComp+=ExpMasMenos
> | '<' expComp+=ExpMasMenos
> | '>' expComp+=ExpMasMenos
> | '>=' expComp+=ExpMasMenos
> | '<=' expComp+=ExpMasMenos)*;
>
> ExpMasMenos:
> (expMasMenos+=ExpMultDiv)
> ('+' expMasMenos+=ExpMultDiv
> | '-' expMasMenos+=ExpMultDiv)*;
>
> ExpMultDiv:
> (expMultDiv+=ExpMenos)
> ('*' expMultDiv+=ExpMenos
> | '/' expMultDiv+=ExpMenos
> | '\\' expMultDiv+=ExpMenos
> | '^' expMultDiv+=ExpMenos
> | '%' expMultDiv+=ExpMenos)*;
>
> ExpMenos:
> '-' ExpNo
> | ExpNo;
>
> ExpNo:
> '!' QualifiedNameDefinition
> | QualifiedNameDefinition;
>
>
>
> Maybe the rule names are incorrect, but this is my sample grammar so dont worry about that.
>
> What i trying to get now, is, avoid a warning error :
>
>
>
> How you can see, my grammar allows to declare in codeblocks (pseudocode) :
>
>
> var NAME as [Entity] = Expression
>
>
> So, when i :
>
>
> NAME. //-> In the scope I get all the features of the Entity in the cross reference.
>
>
> But, my grammar allows too to declare variables without a defined type.
>
> So is correct to said :
>
>
> variable = data.data
>
>
> And if "data" is a variable with type, I get the features of the entity but if "data" is a abstract variable, I want to allow everything. I.E.
>
>
> function CalcPrice(){
> variable = something.something // I get error because something.something is not a EObject
> }
>
>
> So, where I can avoid this error?, Validation? ScopeProvider?
>
> The compiler is already done, so i dont need to know wich object is in the variable.variable,this is especific for a variable content assist.
>
> Thanks, in advance.
>
>
Re: What i need to use for get entities-attributes in a variable? [message #787647 is a reply to message #784801] Tue, 31 January 2012 20:45 Go to previous messageGo to next message
Federico Sellanes is currently offline Federico SellanesFriend
Messages: 71
Registered: November 2011
Member
Hi Henrik !! my battle continues...
First, thanks for your answer, I tried a lot of ways, and each of the options gives me and takes me different features, in the end I got nothing that work how I want. Now I changing my question in a different view...

I.E.

module Module{

function someFunction(){
//return something
}

}




module OtherModule {

entity Customer{
int code
}

function getSomething(){
var aux is Customer = Module.someFunction(); // 'var' ID 'is' [Entity] = [UserFunction] 
var otherAux is Customer = data; // 'var' ID 'is' [Entity] = ID
aux.code = something ; // ID.attribute = ID
}

}



Basically, this are my use cases...

So the expression in the left of the '=' can be, an ID or a VariableDeclaration and, the expressions in the right of the '=', can be a "static" function call, an ID
or a variable.attribute.


Just like java, variable, static function call, variable intellisense, assignment... but with the difference that in my dsl i can declare a variable without indicate the type (like a scripting language).

This is possible in xtext?

I'm going crazy.

PD: I got the most of the use cases but when I have them I cannot get the static function call. All the cases together seems a nightmare for a dsl noob.

I got the intellisense in the MyDslProposalProvider and work really good.


So, as you would you?

Thanks for help me.

[Updated on: Tue, 31 January 2012 20:54]

Report message to a moderator

Re: What i need to use for get entities-attributes in a variable? [message #787680 is a reply to message #787647] Tue, 31 January 2012 21:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the real painpoint is in my dsl i can declare a variable without indicate the type

a workaround for that is described for that

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 31 January 2012 21:41]

Report message to a moderator

Re: What i need to use for get entities-attributes in a variable? [message #787879 is a reply to message #787647] Wed, 01 February 2012 04:21 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Constructing a grammar for an expression based language using parser
technology that is LL requires that you use a well known pattern to
establish the precedence of expressions.

Here is a snippet from one such grammar (the standard Expression example
is simpler - but follows the same principle).

As you can see, each rule starts with a rule-call to the rule with the
next higher precedence. It is followed by an optional (often repeated as
operators are cumulative e.g. 1 + 2 + 3 + 4). This optional part
rewrites the result. You see something like:
{be::BBinaryOpExpression.leftExpr=current}
which means "create an instance of BBinaryOpExpression, and assign its
leftExpression to what was just parsed/created (i.e. 'current'), then
proceed with the just created instance as 'current').

Using Lisp like notation to illustrate the result of parsing:

1 + 2 => (+ 1 2)
1 * 2 => (* 1 2)
1 + 2 + 3 => (+ (+ 1 2) 3)
1 + 2 * 3 => (+ 1 (* 2 3))

i.e. 1 + 2 results in one instance of BBinaryOpExpression where leftExpr
is a Literal '1', the functionName is '+', and the rightExpr is a
Literal '2'. (You have to work out the others yourself ;))

The chain of calls goes all the way down to the primary expressions -
i.e. where you find the Literals (numbers, strings, etc.) and the
primary constructs if/then/else, switch/case, definitions etc.

As an exercise, try to read the code and see how the above tree gets
constructed.

This is all following a formula. The formula is slightly different
depending on if they are left or right associative, if they are
cumulative or not etc.

The snippet below is from the Eclipse project b3 (and contains quite a
few things specific to b3). You can naturally look at the source of
that, or cloudsmith/geppetto which is for a language called Puppet (also
expression based), as last but not least the source for Xtend. As
mentioned earlier there is an Expression example that is a good starting
point.

Whatever you do, do not try to write the entire grammar at once. Start
with a very small subset and make sure that works before you proceed.
That way you have a much better chance of understanding which of you
constructs/rules are giving you problems - or (worst case) you are
dealing with a language that is difficult to parse (having overlapping
terminals, or require semantic predicates). A bonus is that it is easier
for others to help you :) - if you ask "here is my grammar, and when I
introduce this rule xxx to do yyy, I get the following problem". Looking
at snippets of your source language, and a semi-broken full grammar
requires quite a lot guess work by anyone who tries to help you.

And before you even start on the Expressions, make sure you have your
terminals (and keywords) figured out.

Here is the snippet...


Expression : AdditiveExpression ;

AdditiveExpression returns be::BExpression :
MultiplicativeExpression ({be::BBinaryOpExpression.leftExpr=current}
functionName=("+" | "-") rightExpr=MultiplicativeExpression)*
;

MultiplicativeExpression returns be::BExpression :
SetExpression ({be::BBinaryOpExpression.leftExpr=current}
functionName=("*" | "/" | "%") rightExpr=SetExpression)*
;

SetExpression returns be::BExpression:
UnaryOrInfixExpression ({be::BBinaryOpExpression.leftExpr=current}
functionName=".." rightExpr=UnaryOrInfixExpression)*
;

UnaryOrInfixExpression returns be::BExpression
: PostopExpression
| UnaryExpression
| PreopExpression
;

UnaryExpression returns be::BExpression : {be::BUnaryOpExpression}
functionName=("!" | "-") expr=InfixExpression
;

PreopExpression returns be::BExpression : {be::BUnaryPreOpExpression}
functionName=("++" | "--") expr=InfixExpression
;

PostopExpression returns be::BExpression :
InfixExpression ({be::BUnaryPostOpExpression.expr=current} functionName
= ("--" | "++"))?
;

// Note that grammar is lenient with optional elements to enable good CA
InfixExpression returns be::BExpression :
CallExpression (
({be::BCallFeature.funcExpr=current} "." (name=ID_or_KW (call ?=
"(" (parameterList = ParameterList)? ")")?)?)
| ({be::BAtExpression.objExpr=current} '[' (indexExpr=Expression)? ']' )
)*;

CallExpression returns be::BExpression :
PrimaryExpression ({be::BCallFunction.funcExpr=current}"("
(parameterList = ParameterList)? ")")*
;

PrimaryExpression returns be::BExpression
: FeatureCall
| ConstructorCallExpression
| Literal
| VariableValue
| PropertyValue
| ParanthesizedExpression
| IfExpression
| BlockExpression
| SwitchExpression
| ThrowExpression
| TryCatchExpression
....
;

Hope this gives some insight into writing an Expression based grammar.

Regards
- henrik

On 2012-31-01 21:45, Federico Sellanes wrote:
> Hi Henrik !! my battle continues... First, thanks for your answer, i
> tried a lot of ways, and each of the options gives me and takes me
> different features, in the end i got nothing that work how i want. Now
> I'm changing my question in a different view...
>
> module name {
>
> entity Customer{
> int code
> }
>
> function getSomething(){
> var aux is Customer = Module.function(); // 'var' ID 'is' [Entity] =
> [UserFunction] var otherAux is Customer = data; // 'var' ID 'is'
> [Entity] = ID
> aux.code = something ; // ID.attribute = ID
> }
>
> }

Is this text in your source language?

>
>
>
> Basically, this are my use cases...
>
> So the expression in the right of the '=' can be, an ID or a
> VariableDeclaration and, the expressions in the right of the '=', can
> be, a "static" function call, an ID
> or a variable.attribute.
>
>
> Just like java, variable, static function call, variable intellisense,
> assignment...
>
> This is possible in xtext?
Look at Xtend - yes it is possible to describe a Java like language.

>
> I'm going crazy.
>
Not good. Start from the beginning and do small steps. When learning to
juggle, don't start by trying to juggle a dozen live chainsaws. That is
just going to hurt...

> PD: I got the most of the use cases but when i have them i cannot get
> the static function call. All the cases together seems a nightmare for a
> dsl noob.
>
You did not show the full grammar, so hard to tell how far you got on
the right track...

> Thanks for help me.
np - help us help you by being as concrete as possible - we can't guess
what your 'static function call' means in your language, nor what
problems you are running into when we don't see the grammar.

Regards
- henrik
Previous Topic:How to clone the model before generation
Next Topic:Boolean-Rule not used but causes Error in ANTlr
Goto Forum:
  


Current Time: Wed Apr 24 18:56:27 GMT 2024

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

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

Back to the top