Home » Modeling » TMF (Xtext) » debugging DSL serialisation
debugging DSL serialisation [message #52874] |
Thu, 25 June 2009 13:44  |
Eclipse User |
|
|
|
Hi,
I'm experiencing an exception while trying to save a transformed model to
an XText DSL grammar.
I'm having trouble debugging what the problem is - I was hoping for some
advice.
I'm fairly new to the eclipse modeling world - so please forgive any
naivety (but I have years of experience writing metamodels/m2m/m2t in MOF
and other tools - so I'll understand the concepts).
So - I have two XText dsls, a model in one language, and a transformation
to transform it to the other. I have a MWE workflow to load the first
model, run the transformation, then save the transformed model to a new
file.
The final Writer step falls over with an exception. To be honest I don't
fully understand it, but it seems to suggest that I haven't properly
created a serialisable model (so really the problem is probably in my m2m
transformation). The exception mentions a particular instance in the
target model - if I remove that instance I don't get the error (it's the
only instance of that type in the model).
Here's the exception:
org.eclipse.xtext.parsetree.reconstr.XtextSerializationExcep tion:
Serialization failed
<# of serialized tokens>: "<serializable fragment, starting from the end>":
-> <possible reasons for not continuing>
107: "controller usecase1 { outcome-state-action event_ou...":
-> Can not leave rule 'Controller' since the current object 'Controller'
has features with unconsumed values: 'states':1
104: ", finished , cancelled } outcome-state-action outco...":
-> OutcomeAction_StatesAssignment_4_1: All 2 values of
OutcomeAction.states have been consumed. More are needed to continue here.
104: "controller usecase1 { outcome-state-action event_ou...":
-> Can not leave rule 'Controller' since the current object 'Controller'
has features with unconsumed values: 'states':1
104: "controller usecase1 { outcome-state-action event_ou...":
-> Can not leave rule 'Controller' since the current object 'Controller'
has features with unconsumed values: 'states':1
101: "outcome-state-action event_outcomes_view1 { cancell...":
-> Can not leave rule 'OutcomeAction' since the current object
'OutcomeAction' has features with unconsumed values: 'states':1
at
org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeC onstructor.serialize(AbstractParseTreeConstructor.java:432)
at
org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeC onstructor.serialize(AbstractParseTreeConstructor.java:378)
at
org.eclipse.xtext.parsetree.reconstr.SerializerUtil.serializ e(SerializerUtil.java:47)
at
org.eclipse.xtext.parsetree.reconstr.SerializerUtil.serializ e(SerializerUtil.java:52)
at org.eclipse.xtext.resource.XtextResource.doSave(XtextResourc e.java:188)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1406)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993)
at org.eclipse.emf.mwe.utils.Writer.write(Writer.java:149)
So - I wonder where to go from here.
The type in question:
OutcomeAction:
'outcome-state-action' name=ID '{' states+=[State] (','
states+=[State])* '}';
The message seems to say it found 2 instances of State to assign to
"states", but needed more than 2. I doubt I've interpreted it correctly,
though - my DSL definition seems to allow 1 or more States in "states"...
|
|
| |
Re: debugging DSL serialisation [message #52927 is a reply to message #52874] |
Thu, 25 June 2009 14:24   |
Eclipse User |
|
|
|
Hi Antony,
thanks for the detailed information in your post. The problem seems to
be the rule Controller instead of OutcomeAction. Would you please be so
kind and post this part of your grammar as well. Maybe you can attach a
minimal sample model?
Regards,
Sebastian
Am 25.06.2009 19:44 Uhr, schrieb Antony Wilkins:
> Hi,
>
> I'm experiencing an exception while trying to save a transformed model
> to an XText DSL grammar.
>
> I'm having trouble debugging what the problem is - I was hoping for some
> advice.
>
> I'm fairly new to the eclipse modeling world - so please forgive any
> naivety (but I have years of experience writing metamodels/m2m/m2t in
> MOF and other tools - so I'll understand the concepts).
>
> So - I have two XText dsls, a model in one language, and a
> transformation to transform it to the other. I have a MWE workflow to
> load the first model, run the transformation, then save the transformed
> model to a new file.
>
> The final Writer step falls over with an exception. To be honest I don't
> fully understand it, but it seems to suggest that I haven't properly
> created a serialisable model (so really the problem is probably in my
> m2m transformation). The exception mentions a particular instance in the
> target model - if I remove that instance I don't get the error (it's the
> only instance of that type in the model).
>
> Here's the exception:
> org.eclipse.xtext.parsetree.reconstr.XtextSerializationExcep tion:
> Serialization failed
> <# of serialized tokens>: "<serializable fragment, starting from the end>":
> -> <possible reasons for not continuing>
> 107: "controller usecase1 { outcome-state-action event_ou...":
> -> Can not leave rule 'Controller' since the current object 'Controller'
> has features with unconsumed values: 'states':1
> 104: ", finished , cancelled } outcome-state-action outco...":
> -> OutcomeAction_StatesAssignment_4_1: All 2 values of
> OutcomeAction.states have been consumed. More are needed to continue here.
> 104: "controller usecase1 { outcome-state-action event_ou...":
> -> Can not leave rule 'Controller' since the current object 'Controller'
> has features with unconsumed values: 'states':1
> 104: "controller usecase1 { outcome-state-action event_ou...":
> -> Can not leave rule 'Controller' since the current object 'Controller'
> has features with unconsumed values: 'states':1
> 101: "outcome-state-action event_outcomes_view1 { cancell...":
> -> Can not leave rule 'OutcomeAction' since the current object
> 'OutcomeAction' has features with unconsumed values: 'states':1
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeC onstructor.serialize(AbstractParseTreeConstructor.java:432)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeC onstructor.serialize(AbstractParseTreeConstructor.java:378)
>
> at
> org.eclipse.xtext.parsetree.reconstr.SerializerUtil.serializ e(SerializerUtil.java:47)
>
> at
> org.eclipse.xtext.parsetree.reconstr.SerializerUtil.serializ e(SerializerUtil.java:52)
>
> at org.eclipse.xtext.resource.XtextResource.doSave(XtextResourc e.java:188)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1406)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993)
>
> at org.eclipse.emf.mwe.utils.Writer.write(Writer.java:149)
>
>
> So - I wonder where to go from here.
>
> The type in question:
> OutcomeAction:
> 'outcome-state-action' name=ID '{' states+=[State] (','
> states+=[State])* '}';
>
> The message seems to say it found 2 instances of State to assign to
> "states", but needed more than 2. I doubt I've interpreted it correctly,
> though - my DSL definition seems to allow 1 or more States in "states"...
>
|
|
| | | |
Re: debugging DSL serialisation [message #53127 is a reply to message #53051] |
Fri, 26 June 2009 04:07   |
Eclipse User |
|
|
|
Hi Antony,
nice to see that you are an Xtext-fan by now ;-)
I cannot find a rule for a type OutcomeActionState in your grammar
snippet. Is it due to the fact, that you simply didn't copy it into the
post or is it actually missing in your grammar?
If you don't mind, you could send my your grammar and your sample model
(or even better: a small sample project with a testcase) and I'll have a
look into this issue. Currently I'm afraid that you stumbled across a bug.
Regards,
Sebastian
Am 26.06.2009 3:11 Uhr, schrieb Antony Wilkins:
> Hi Sebastian,
>
> Thanks for the speedy reply!
>
> Here's the things I think are relevant:
>
> Controller:
> 'controller' name=ID '{' (actions+=Action)*
> (commonTransitions+=CommonTransition)* ('on start' entryAction+=[Action])*
> (states+=StartState) (states+=RunningState)+
> (states+=StopState)+ ('on end' exitAction+=[Action])*
> '}';
>
> State:
> StartState|StartedState;
>
> StartedState:
> RunningState|StopState;
>
> StartState:
> 'start-state' ref=[RunningState];
>
> StopState:
> 'stop-state' name=ID;
>
> RunningState:
> EventWaitingState | ActionState | SubControllerState;
> EventWaitingState:
> 'wait-state' name=ID '{'
> ('on-entry' entryAction+=[Action])*
> ((transitions+=SimpleTransition)|(transitions+=CommonTransit ionRef))+
> ('on-exit' exitAction+=[Action])* '}';
>
>
> and here's a model that produces the error:
>
> <mVC:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:mVC="http://www.antonywilkins.com/mdd/mvc/dsl/MVC"
> xsi:schemaLocation="http://www.antonywilkins.com/mdd/mvc/dsl/MVC
> java://com.antonywilkins.mdd.mvc.dsl.mVC.MVCPackage">
> <controllers name="usecase1">
> <actions xsi:type="mVC:OutcomeAction" name="event_outcomes_view1"
> states="//@controllers.0/@states.3 //@controllers.0/@states.4"/>
> <states xsi:type="mVC:OutcomeActionState" name="event_outcomes_view1"
> action="//@controllers.0/@actions.0"/>
> <states xsi:type="mVC:StartState" ref="//@controllers.0/@states.2"/>
> <states xsi:type="mVC:EventWaitingState" name="view1">
> <transitions xsi:type="mVC:SimpleTransition"
> to="//@controllers.0/@states.0">
> <event name="ok"/>
> </transitions>
> <transitions xsi:type="mVC:SimpleTransition"
> to="//@controllers.0/@states.0">
> <event name="cancel"/>
> </transitions>
> </states>
> <states xsi:type="mVC:StopState" name="finished"/>
> <states xsi:type="mVC:StopState" name="cancelled"/>
> </controllers>
> </mVC:Model>
>
> This is the textual version I *think* it should produce:
>
> controller myController {
> outcome-state-action event_outcomes_view1 { finished , cancelled }
>
> start-state view1
>
> wait-state view1 {
> event ok go to handle_events_view1
> event cancel go to event_outcomes_view1
> }
>
> action-state event_outcomes_view1 outcomes event_outcomes_view1
>
> stop-state finished
>
> stop-state cancelled
> }
>
> As you can guess, I've taken the famous state machine example and
> altered it a bit to fit an MVC framework like spring webflow or struts.
> (You'll thing that model is a bit odd - it's the result of a
> transformation from something else that has a different take on state
> machines - less verbose, but less flexible).
>
>
> Sebastian Zarnekow wrote:
>
>> Hi Antony,
>
>> thanks for the detailed information in your post. The problem seems to
>> be the rule Controller instead of OutcomeAction. Would you please be
>> so kind and post this part of your grammar as well. Maybe you can
>> attach a minimal sample model?
>
>> Regards,
>> Sebastian
>
>
|
|
| |
Re: debugging DSL serialisation [message #53229 is a reply to message #53051] |
Fri, 26 June 2009 08:34   |
Eclipse User |
|
|
|
Hi Antony,
could you try to put your model elements in "state" in the same order as
they would appear in the textual model?
For example, your grammar implies that the start state always should be
the first. Therefore, it must be at this position in the list of states
as well. However, your XMI shows that an OutcomeActionState is at the
first position...
If you don't like the idea that your grammar introduces this constraint,
you can express it like this:
Controller:
'controller' name=ID '{' (actions+=Action)*
(commonTransitions+=CommonTransition)* ('on start'
entryAction+=[Action])*
(states+=State)+ ('on end' exitAction+=[Action])*
'}';
Or, to keep the constrain that you need exactly one start state and at
least one running state and one stop state, you could store the states
in separate features:
Controller:
'controller' name=ID '{' (actions+=Action)*
(commonTransitions+=CommonTransition)* ('on start'
entryAction+=[Action])*
(startState=StartState) (runningStates+=RunningState)+
(stopStates+=StopState)+ ('on end' exitAction+=[Action])*
'}';
hth,
Moritz
> Hi Sebastian,
>
> Thanks for the speedy reply!
>
> Here's the things I think are relevant:
>
> Controller:
> 'controller' name=ID '{' (actions+=Action)*
> (commonTransitions+=CommonTransition)* ('on start'
> entryAction+=[Action])*
> (states+=StartState) (states+=RunningState)+
> (states+=StopState)+ ('on end' exitAction+=[Action])*
> '}';
>
> State:
> StartState|StartedState;
>
> StartedState:
> RunningState|StopState;
>
> StartState:
> 'start-state' ref=[RunningState];
>
> StopState:
> 'stop-state' name=ID;
>
> RunningState:
> EventWaitingState | ActionState | SubControllerState;
> EventWaitingState:
> 'wait-state' name=ID '{'
> ('on-entry' entryAction+=[Action])*
> ((transitions+=SimpleTransition)|(transitions+=CommonTransit ionRef))+
> ('on-exit' exitAction+=[Action])* '}';
>
>
> and here's a model that produces the error:
>
> <mVC:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:mVC="http://www.antonywilkins.com/mdd/mvc/dsl/MVC"
> xsi:schemaLocation="http://www.antonywilkins.com/mdd/mvc/dsl/MVC
> java://com.antonywilkins.mdd.mvc.dsl.mVC.MVCPackage">
> <controllers name="usecase1">
> <actions xsi:type="mVC:OutcomeAction" name="event_outcomes_view1"
> states="//@controllers.0/@states.3 //@controllers.0/@states.4"/>
> <states xsi:type="mVC:OutcomeActionState" name="event_outcomes_view1"
> action="//@controllers.0/@actions.0"/>
> <states xsi:type="mVC:StartState" ref="//@controllers.0/@states.2"/>
> <states xsi:type="mVC:EventWaitingState" name="view1">
> <transitions xsi:type="mVC:SimpleTransition"
> to="//@controllers.0/@states.0">
> <event name="ok"/>
> </transitions>
> <transitions xsi:type="mVC:SimpleTransition"
> to="//@controllers.0/@states.0">
> <event name="cancel"/>
> </transitions>
> </states>
> <states xsi:type="mVC:StopState" name="finished"/>
> <states xsi:type="mVC:StopState" name="cancelled"/>
> </controllers>
> </mVC:Model>
>
> This is the textual version I *think* it should produce:
>
> controller myController {
> outcome-state-action event_outcomes_view1 { finished , cancelled }
>
> start-state view1
>
> wait-state view1 {
> event ok go to handle_events_view1
> event cancel go to event_outcomes_view1
> }
>
> action-state event_outcomes_view1 outcomes event_outcomes_view1
>
> stop-state finished
>
> stop-state cancelled
> }
>
> As you can guess, I've taken the famous state machine example and
> altered it a bit to fit an MVC framework like spring webflow or struts.
> (You'll thing that model is a bit odd - it's the result of a
> transformation from something else that has a different take on state
> machines - less verbose, but less flexible).
>
>
> Sebastian Zarnekow wrote:
>
>> Hi Antony,
>
>> thanks for the detailed information in your post. The problem seems to
>> be the rule Controller instead of OutcomeAction. Would you please be
>> so kind and post this part of your grammar as well. Maybe you can
>> attach a minimal sample model?
>
>> Regards,
>> Sebastian
>
>
|
|
| | |
Re: debugging DSL serialisation [message #53309 is a reply to message #53229] |
Fri, 26 June 2009 12:22   |
Eclipse User |
|
|
|
That was it - yes - I was putting a non-StartState before the StartState,
contrary to my grammar rules, but not contrary to my metamodel. I see -
hence I was able to store it as XMI.
I tried one of your options and it fixes it! Thank you so much! And
thanks to Sebastian for his kind offer to have a look at the full project
and his help so far.
I went with your second option, because I like the constraints being
effectively expressed in my metamodel definition, and because it's nice to
have the grammar enforce it without having to write validation logic.
(So far I've been able to keep rules out of the validation, just by
scoping things correctly - with the added benefit of adding a bit more
semantics, and getting IDE things like content proposals and validation
for free).
The downside is I have to write a "getAllStates()" operation in my
transformation logic, but that's a small price to pay.
On the subject of adapter logic - I'm finding that XTend is very nice
place to decorate my metamodel with behaviour - great for re-use in m2m
and m2t transformations. Sometimes, though, I want to re-use the logic in
the DSL Validator/ScopeProvider/ContentProposers. Is the easiest way just
to write it in Java static methods and call the operations from there in
the XTend, or is there a way to reuse XTend definitions in Java?
|
|
| |
Re: debugging DSL serialisation [message #53583 is a reply to message #53309] |
Sat, 27 June 2009 14:45   |
Eclipse User |
|
|
|
Hi Antony,
have a look at the post processing step of the Ecore model generation.
It allows to add custom properties and operation to your model.
See here:
http://www.eclipse.org/Xtext/documentation/0_7_0/xtext.html# metamodelInference
That is currently the only way to make the model more oo'ish and get rid
of static helper methods.
Regards,
Sebastian
Am 26.06.2009 18:22 Uhr, schrieb Antony Wilkins:
> That was it - yes - I was putting a non-StartState before the
> StartState, contrary to my grammar rules, but not contrary to my
> metamodel. I see - hence I was able to store it as XMI.
>
> I tried one of your options and it fixes it! Thank you so much! And
> thanks to Sebastian for his kind offer to have a look at the full
> project and his help so far.
>
> I went with your second option, because I like the constraints being
> effectively expressed in my metamodel definition, and because it's nice
> to have the grammar enforce it without having to write validation logic.
>
> (So far I've been able to keep rules out of the validation, just by
> scoping things correctly - with the added benefit of adding a bit more
> semantics, and getting IDE things like content proposals and validation
> for free).
>
> The downside is I have to write a "getAllStates()" operation in my
> transformation logic, but that's a small price to pay.
>
> On the subject of adapter logic - I'm finding that XTend is very nice
> place to decorate my metamodel with behaviour - great for re-use in m2m
> and m2t transformations. Sometimes, though, I want to re-use the logic
> in the DSL Validator/ScopeProvider/ContentProposers. Is the easiest way
> just to write it in Java static methods and call the operations from
> there in the XTend, or is there a way to reuse XTend definitions in Java?
>
>
>
>
|
|
| | | |
Goto Forum:
Current Time: Tue May 13 12:29:48 EDT 2025
Powered by FUDForum. Page generated in 0.06328 seconds
|