Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 362581 - [serializer] Syntactic sequencer extension for serialization of optional keywords doesn't work
Summary: [serializer] Syntactic sequencer extension for serialization of optional keyw...
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.1.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: M4   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-01 13:39 EDT by Miro Spoenemann CLA
Modified: 2017-09-19 18:06 EDT (History)
2 users (show)

See Also:
sven.efftinge: juno+


Attachments
Syntactic sequencer for the example grammar (560 bytes, text/x-java)
2011-11-01 14:10 EDT, Miro Spoenemann CLA
no flags Details
Command handler that serializes a model to demonstrate the problem (1.50 KB, text/x-java)
2011-11-01 14:15 EDT, Miro Spoenemann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Miro Spoenemann CLA 2011-11-01 13:39:46 EDT
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.
Comment 1 Miro Spoenemann CLA 2011-11-01 14:10:35 EDT
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.
Comment 2 Miro Spoenemann CLA 2011-11-01 14:15:34 EDT
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 !
Comment 3 Moritz Eysholdt CLA 2011-11-09 07:04:21 EST
thanks for the detailed report.
Comment 4 Moritz Eysholdt CLA 2011-11-09 08:06:10 EST
fixed in branches 'master' and '2.1.x_Maintenance'
Comment 5 Karsten Thoms CLA 2017-09-19 17:55:42 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 6 Karsten Thoms CLA 2017-09-19 18:06:27 EDT
Closing all bugs that were set to RESOLVED before Neon.0