Community
Participate
Working Groups
Build Identifier: 20110916-0149 For a grammar with optional keywords such as Model: greetings+=Greeting*; Greeting: 'Hello' name=ID '!'?; the new serializer generates a class AbstractMyDslSyntacticSequencer with an init(IGrammarAccess) method that creates this matching rule: match_Greeting_ExclamationMarkKeyword_2_q = new TokenAlias(true, false, grammarAccess.getGreetingAccess().getExclamationMarkKeyword_2()); The created token has many=true and optional=false, which is wrong. It should be many=false and optional=true. The consequence of this is that the method emitUnassignedTokens(EObject, ISynTransition, INode, INode), which uses the created matching rules, never matches the optional exclamation mark during serialization and the emit_Greeting_ExclamationMarkKeyword_2_q(EObject, ISynNavigable, List<INode>) method is never called, so it is not possible to change the serialization of optional keywords. Changing or overriding the generated code by setting the correct values for 'many' and 'optional' fixes the problem. Reproducible: Always Steps to Reproduce: 1. Create a grammar with an optional keyword (use question mark). 2. Generate code with the new serializer. 3. Override the corresponding 'emit' method in the generated syntactic sequencer. 4. The overridden method is not considered during serialization.
Created attachment 206283 [details] Syntactic sequencer for the example grammar Using this syntactic sequencer enforces serialization of the optional exclamation mark, but it works only if the TokenAlias creation in its superclass is modified as described.
Created attachment 206284 [details] Command handler that serializes a model to demonstrate the problem Output without correcting AbstractMyDslSyntacticSequencer: Hello world Output after correcting the 'many' and 'optional' parameters of match_Greeting_ExclamationMarkKeyword_2_q: Hello world !
thanks for the detailed report.
fixed in branches 'master' and '2.1.x_Maintenance'
Closing all bugs that were set to RESOLVED before Neon.0