Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serializer fails with InvalidConcreteSyntaxException
Serializer fails with InvalidConcreteSyntaxException [message #778121] Wed, 11 January 2012 12:50 Go to next message
Thomas Williams is currently offline Thomas WilliamsFriend
Messages: 15
Registered: January 2012
Junior Member
Hello Xtexters,

Me again I'm afraid with another serialization problem Wink

The grammar:
GeneralProcessModellingSystem:
    {GeneralProcessModellingSystem}
    (
        (
            "DECLARE"
            (
                (   "TYPE" ( variableTypes += VariableTypeEntity )* )               
              | ( "STREAM" ( streamTypes += StreamTypeEntity )* )
            )
            "END"
        )
        | ( connectionTypes += ConnectionTypeEntity )
    )*
;

VariableTypeEntity:
    name = ID
    '=' default=RealNumber
    ':' lowerBound=RealNumber 
    ':' upperBound=RealNumber 
    ("UNIT" '=' unit=STRING)? ;

StreamTypeEntity:
    name = ID
    "IS"
    elements += ID ( ',' elements += ID )*
;

ConnectionTypeEntity:
    "CONNECTIONTYPE"
    name = ID
    // TODO
    "END"
;

// Use ecore::EDoubleObject rather than ecore::EDouble because of bug in the
// XText serializer.
RealNumber returns ecore::EDoubleObject:
    ('-')? INT ( '.' INT )?
;


The (JUnit) code for parse and serialize:
    @Test
    public void testSerializer() throws Exception {

        String text =
                "DECLARE TYPE\n" +
                "    Length = 0.0 : 0.0 : 100.0 UNIT = \"m\"\n" +
                "END\n" +
                "DECLARE STREAM\n" +
                "    Gas IS Mass_Rate, Concentration, Temperature\n" +
                "END\n" +
                "CONNECTIONTYPE Material\n" +
                "END";

        GeneralProcessModellingSystem gpms = m_Parser.parse(text);
        System.out.println(org.eclipse.xtext.util.EmfFormatter.objToStr(gpms));

        String serializedText = m_Serializer.serialize(gpms);
        System.out.println("--- Serialization Begins ---");
        System.out.println(serializedText);
        System.out.println("--- Serialization Ends ---");
    }


The output from EmfFormatter#objToStr():
GeneralProcessModellingSystem {
    cref VariableTypeEntity variableTypes [
        0: VariableTypeEntity {
            attr EString name 'Length'
            attr EDoubleObject default '0.0'
            attr EDoubleObject lowerBound '0.0'
            attr EDoubleObject upperBound '100.0'
            attr EString unit 'm'
        }
    ]
    cref StreamTypeEntity streamTypes [
        0: StreamTypeEntity {
            attr EString name 'Gas'
            attr EString elements [
                0: 'Mass_Rate'
                1: 'Concentration'
                2: 'Temperature'
            ]
        }
    ]
    cref ConnectionTypeEntity connectionTypes [
        0: ConnectionTypeEntity {
            attr EString name 'Material'
        }
    ]
}


The exception:
org.eclipse.xtext.validation.IConcreteSyntaxValidator$InvalidConcreteSyntaxException: These errors need to be fixed before the model can be serialized.
GeneralProcessModellingSystem: Feature GeneralProcessModellingSystem.streamTypes holds 1 non-transient value(s), but exactly 0 are required. Constraint: (variableTypes*|streamTypes*) Quantities: streamTypes:1, variableTypes:1
GeneralProcessModellingSystem: Feature GeneralProcessModellingSystem.variableTypes holds 1 non-transient value(s), but exactly 0 are required. Constraint: (variableTypes*|streamTypes*) Quantities: streamTypes:1, variableTypes:1

	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:95)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:117)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:50)
	at psenterprise.xtext.GpromsLanguageParserTest.testSerializer(GpromsLanguageParserTest.java:316)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.eclipse.xtext.junit4.XtextRunner$1.evaluate(XtextRunner.java:55)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)



The exception doesn't occur if I remove the ConnectionTypeEntity from the grammar and corresponding CONNECTIONTYPE from the parsed text.

I assume it has something to do with the somewhat convoluted way that VariableTypeEntity and StreamTypeEntity are declared within a DECLARE section, but the language is immutable, so I need to resolve the issue with the grammar.

Regards,

Tom
Re: Serializer fails with InvalidConcreteSyntaxException [message #778501 is a reply to message #778121] Thu, 12 January 2012 21:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi guess you are affected by https://bugs.eclipse.org/bugs/show_bug.cgi?id=305164
or at least have a similar problem


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializer fails with InvalidConcreteSyntaxException [message #779330 is a reply to message #778501] Sun, 15 January 2012 11:34 Go to previous messageGo to next message
Moritz Eysholdt is currently offline Moritz EysholdtFriend
Messages: 161
Registered: July 2009
Location: Kiel, Germany
Senior Member
hi Thomas,

that is indeed a false positive of the ConcreteSyntaxValidator.

As a workaround, you can turn ConcreteSyntvValidation off by setting
"validate" in org.eclipse.xtext.resource.SaveOptions to false.

regards,
Moritz

On 12.01.12 22:36, Christian Dietrich wrote:
> hi guess you are affected by
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=305164
> or at least have a similar problem
>
Re: Serializer fails with InvalidConcreteSyntaxException [message #780834 is a reply to message #778121] Thu, 19 January 2012 14:52 Go to previous message
Thomas Williams is currently offline Thomas WilliamsFriend
Messages: 15
Registered: January 2012
Junior Member
Thanks Moritz,

I haven't tried this out since my evaluation effort on Xtext is over; at least for the moment.

Sincerely,

Tom
Previous Topic:Strange autocompletion behaviour in the xtext editor
Next Topic:How to generate language with comments
Goto Forum:
  


Current Time: Thu Apr 25 01:56:45 GMT 2024

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

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

Back to the top