Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross References are working only in a specific parts of the model - why?
Cross References are working only in a specific parts of the model - why? [message #894841] Tue, 10 July 2012 17:44 Go to next message
Hannes Müller is currently offline Hannes MüllerFriend
Messages: 24
Registered: June 2012
Junior Member
Hi everyone,

I have a language posted below. My problem is the following: I "declare" formulas in a specific parameter for example:
parameter BeginPos{
recalculates
{
Mta & init ==> formula myFormula2 : BeginPos + 2;
}
}

If I know want to reuse my formula I work with cross references.
Recalculate:
... '==>' (recalculateFormula = RecalculateFormula | 'reuse' resusedRecalculateFormula = [RecalculateFormula]) ';'
;

The DSL would look like this ...
knownParameter BeginPos {
recalculates {
Customer & init ==> reuse myFormula2;
}
}

But because of some unknown reason xtext can not resolve the reference to myFormula2???

If I do declare a formula in the scope of a "reused" Parameter (a cross reference to a known parameter - see the example DSL below) -> than xtext CAN RESOLVE the formulas!?

knownParameter BeginPos {
recalculates {
Customer & inProgress ==> formula myFormula2 : 2 + 3 4;
}
}

knownParameter BeginPos {
recalculates {
Customer & init ==> reuse myFormula2;
}
}

Does anyone has a clue why this behaves this way? I would be grateful for any hint.

Thx in advance
Hannes

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

generate myDsl // here is the DSL URI - but I am still not allowed to add URIs in the forum ...

DomainModel:
{DomainModel}
supportedUsers = SupportedUserStates
supportedProgressStates = SupportedProgressStates
supportedActions = SupportedStateChangingActions
measurementsWithParmeters += MeasurementsWithParametersAndStateTransitions+
;

SupportedUserStates:
'users' '{' supportedUserStates += SupportedUserState (',' supportedUserStates += SupportedUserState)*'}'
;

SupportedUserState:
name = ID
;

SupportedProgressStates:
'progresses' '{'supportedProgressStates += SupportedProgressState (',' supportedProgressStates += SupportedProgressState)*'}'
;

SupportedProgressState:
name = ID
;

SupportedStateChangingActions:
'actions' '{'supportedStateChangingActions += StateChangingAction (',' supportedStateChangingActions += StateChangingAction)*'}'
;

StateChangingAction:
name = ID
;

MeasurementsWithParametersAndStateTransitions:
'measurements' '{'measurementsWithParametersAndStateTransitions += MeasurementWithParametersAndTransition 'end measurement;' (measurementsWithParametersAndStateTransitions += MeasurementWithParametersAndTransition 'end measurement;')* '}'
;

MeasurementWithParametersAndTransition:
measurement = Measurement '{' (parametersWithRecalulate += ParameterWithRecalculate)+ stateTransitions = StateTransitions '}'
;

Measurement:
'measurement' name = ID
;

ParameterWithRecalculate:
// new parameter should be declared or know parameter which already has some formulas
('parameter' name = ID (immutable = "immutable")?| 'knownParameter' paramWithRecal = [ParameterWithRecalculate])
'{' 'recalculates' '{' (recalculates += Recalculate)+ '}''}'
;

Recalculate:
userStates += [SupportedUserState] '&' progressStates += [SupportedProgressState]
('&&' userStates += [SupportedUserState] '&' progressStates += [SupportedProgressState])* '==>' (recalculateFormula = RecalculateFormula | 'reuse' resusedRecalculateFormula = [RecalculateFormula]) ';'
// the keyword reused (could be an other name) is mandatory necessary because else the parser cannot decide what to chose (ambiguity)
;

RecalculateFormula:
('formula 'name = ID':')? (complexFormula = Expression | specialFormula = SpecialFormula)
;

enum SpecialFormula:
NOP="NOP" // signals null object pattern
;

Expression:
Addition
;

Addition returns Expression:
Multiplication (({Plus.left=current} '+' | {Minus.left=current} '-') right=Multiplication)*
;

Multiplication returns Expression:
PrimaryExpression (({Multi.left=current} '*' | {Div.left=current} '/') right=PrimaryExpression)*
;

PrimaryExpression returns Expression:
leftBracktet = '(' expression = Expression rightBracket =')' | parameter = [ParameterWithRecalculate] | number = Number // the features left and right brackets are a "trick" to be able to recognize if the current formula is or is not surrounded with brackets while code generation
;

Number:
integer = INT | double = Double
;

Double:
predecimalNumber = INT '.' decimalNumber = INT
;

enum FormulaOperator:
PLUS = '+' | MINUS = '-' | MULTIPLIKATION = '*' | DIVISION = '/'
;

StateTransitions:
'state transitions {' (stateTransitions += StateTransition ';')+'}'
;

StateTransition:
stateTransitionConditions += StateTransitionContition ('&&' stateTransitionConditions += StateTransitionContition)* '==>' userStateNEW = [SupportedUserState] '&' progressStateNEW = [SupportedProgressState]
;

StateTransitionContition:
userStateOLD = [SupportedUserState] '&' progressStateOLD = [SupportedProgressState] '&' stateChangingAction = [StateChangingAction]
;

[Updated on: Tue, 10 July 2012 17:48]

Report message to a moderator

Re: Cross References are working only in a specific parts of the model - why? [message #894842 is a reply to message #894841] Tue, 10 July 2012 17:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13613
Registered: July 2009
Senior Member
Hi,

sounds like a qualified name problem. xtext by default builds names like
parentName.childName => it will not work if you write ref=[Sometype] since this is short for ref=[Sometype|ID] and . (dot) is not allowed in ID

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross References are working only in a specific parts of the model - why? [message #894958 is a reply to message #894842] Wed, 11 July 2012 08:55 Go to previous messageGo to next message
Hannes Müller is currently offline Hannes MüllerFriend
Messages: 24
Registered: June 2012
Junior Member
Hello,

First thank you Christian for your answer Smile

Ok, the first thing I do not understand is, that 'knownParameter' paramWithRecal = [ParameterWithRecalculate] works in my DSL and 'reuse' resusedRecalculateFormula = [RecalculateFormula] not - I mean it looks equal! And ParameterWithRecalculate also should have a qualified name like parentName.childName (it also has a parent) - or am I wrong here? What is the different of this two?
Also the tutorial example looks equal ('extends' superType = [Entity])

The second question is how can I solve my problem because I want reusable formulas.

Thx in advance for any hint
Hannes

Re: Cross References are working only in a specific parts of the model - why? [message #894982 is a reply to message #894958] Wed, 11 July 2012 10:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13613
Registered: July 2009
Senior Member
Hi the first has no parent with a name the second has. If you want to
use simple names in general bind simplenameprovider as
iqualifiednameprovider - else write a custom
defaultdeclarativenameprovider that gives the element a simple name.
Or you change the grammar to
Xxx=[sometype|FQN]
With
FQN: ID ("." ID)*;

--
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross References are working only in a specific parts of the model - why? [message #895022 is a reply to message #894982] Wed, 11 July 2012 12:43 Go to previous message
Hannes Müller is currently offline Hannes MüllerFriend
Messages: 24
Registered: June 2012
Junior Member
Thanks Christian,

I work with the FQN variant and it works. I am happy Smile

The thread can be closed.
Previous Topic:JVMField with primitive type
Next Topic:OCL: Iterate over code lines
Goto Forum:
  


Current Time: Tue Sep 29 11:42:32 GMT 2020

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

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

Back to the top