Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Testing language serializer
Testing language serializer [message #990839] Fri, 14 December 2012 11:52
Marco Naddeo is currently offline Marco NaddeoFriend
Messages: 62
Registered: November 2012
Member
Hi all Smile

I'm trying to test my language serializer but i get some errors I don't understand, so I need your help please. Very Happy

Given these production rules:

ActualParameters:
	{ActualParameters} '(' (expressions+=Expression (',' expressions+=Expression)*)? ')'
;

MethodCall:
	receiverObject=Expression '.' mixinName=ID '.' methodName=ID params=ActualParameters
;

Expression:
    TerminalExpression ({Expression.expr=current} '.' mixinName=ID '.' memberName=ID actualParams=ActualParameters?)*
;

TerminalExpression returns Expression:
	{ThisExpr} 'this' |
        {NullExpr} 'null' |
        {FalseExpr} 'false' |
        {TrueExpr} 'true ' |
        {StringLiteralExpr} stringLiteral=STRING_LITERAL |
	{NumberLiteralExpr} numberLiteral=NUMBER_LITERAL |
	{IdentifierExpr} identifier=ID |
	{ObjectCreationExpr} objectCreation=ObjectCreation |
        {SuperExpr} 'super' actualParams=ActualParameters |
        {ParenthesizedExpr} '(' parenthesizedExpr=Expression ')'
;

ParamAssignment:
	mixinName=ID '.' paramName=ID ':=' assignedValue=Expression
;

ParamAssignments:
	{ParamAssignments} (paramAssignments+=ParamAssignment (',' paramAssignments+=ParamAssignment)*)?
;


...I'd like to create - via language factory - an EObject representing the method call "this.Point2D.setCoords2D(10, 20)", and then serialize it, printing the resulting string (expected to be that one), but this code:

Injector injector = Guice.createInjector(new MyLanguageRuntimeModule());  
Serializer serializer = injector.getInstance(Serializer.class);
MethodCall methodCall = MyLanguageFactory.eINSTANCE.createMethodCall();
methodCall.setReceiverObject(MyLanguageFactory.eINSTANCE.createThisExpr());
methodCall.setMixinName("Point2D");
methodCall.setMethodName("setCoords2D");
ActualParameters params = MyLanguageFactory.eINSTANCE.createActualParameters();
NumberLiteralExpr param1 = MyLanguageFactory.eINSTANCE.createNumberLiteralExpr();
param1.setNumberLiteral("10");
NumberLiteralExpr param2 = MyLanguageFactory.eINSTANCE.createNumberLiteralExpr();
param2.setNumberLiteral("20");

//I'm not sure the underlying code is correct :-/
//how can I add a NumberLiteralExpr to the "expressions" collection of a ActualParameters object?

params.getExpressions().add(param1);
params.getExpressions().add(param2);

methodCall.setParams(params);
System.out.println(serializer.serialize(methodCall));


generates these errors Shocked

org.eclipse.xtext.parsetree.reconstr.XtextSerializationException: Serialization failed
<# of serialized tokens>: <EObject path> "<serializable fragment, starting from the end>":
  -> <possible reasons for not continuing>
13:MethodCall.params->ActualParameters: "( 20 )":
  -> ActualParameters_ActualParametersAction_0: n/a
11:MethodCall.params->ActualParameters.expressions[1]->NumberLiteralExpr: ")":
  -> TerminalExpression_NumberLiteralAssignment_5_1: n/a
5:MethodCall.params->ActualParameters: "( )":
  -> ActualParameters_ActualParametersAction_0: n/a


Could you please help me? Rolling Eyes

Thanks in advance,
Marco

[Updated on: Fri, 14 December 2012 11:54]

Report message to a moderator

Previous Topic:Getting EReference from Node
Next Topic:AssertionError: Cyclic resolution of lazy links
Goto Forum:
  


Current Time: Sun Sep 27 18:03:36 GMT 2020

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

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

Back to the top