Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 403812

Summary: Closing Braces doesn't work with Nested Braces
Product: [Modeling] TMF Reporter: Thomas Reisenbichler <thomas.reisenbichler>
Component: XtextAssignee: Hendrik Buender <hendrik.buender>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: christian.dietrich.opensource, karsten.thoms, sven.efftinge
Version: 2.3.1Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Windows Server 2008   
See Also: https://github.com/eclipse/xtext-eclipse/pull/95
Whiteboard: v2.11
Attachments:
Description Flags
Sample none

Description Thomas Reisenbichler CLA 2013-03-19 12:40:58 EDT
Created attachment 228666 [details]
Sample

With following grammar and the given example for the grammar, the MultiLineTerminalsEditStrategy adds a closing brace when hitting enter after "Thomas {". Problem is, that it kind of oversees the closing brace "}//" and then inserts a new brace, which is syntactically incorrect.

======= Grammar =======

Model: greetings+=Greeting*;
Greeting: 'Hello' '{' persons+=Person '}' '!';
Person:	name=ID	'{' birthday=Birthday '}';
Birthday: name=ID;

======= Example =======

Hello {
  Thomas {
    Birthday
  }//
} !

Attached is a simple project with the grammar.
Comment 1 Hendrik Buender CLA 2016-09-26 11:04:07 EDT
Problem analysis:
When enter is hit the inner start and stop terminal is found correctly, but the MultiLineTerminalsEditStrategy recognizes that the statement is nested and searches for the surrounding start and stop terminal. After the outer start terminal is found correctly, the stop terminal is searched for with the offset of the inner stop terminal + 1. At that offset (after the { and before //) the ITypedRegion is a __sl_comment leading to a search for the closing brace within  the following __sl_comment regions. Therefore, the closing brace in the next line is (}!) is not found because it is in the wrong ITypedRegion (__dftl_partition_content_type). 

Proposed Problem solution:
Closing tokens can only be in a __dftl_partition_content_type ITypedRegion. Therefore, if the region at inner stop terminal + 1 is not a __dftl_partition_content_type ITypedRegion that region is skipped until a __dftl_partition_content_type is found that is than passed to the DocumentUtil.searchInSamePartition method.
Comment 2 Eclipse Genie CLA 2016-09-29 05:53:05 EDT
GitHub Pull Request 95 created by [HBuender]
https://github.com/eclipse/xtext-eclipse/pull/95
Comment 3 Sven Efftinge CLA 2016-11-06 10:21:53 EST
thanks for the contribution!
Comment 4 Christian Dietrich CLA 2016-11-06 10:30:28 EST
Fixed in Xtext 2.11