Bug 497097

Summary: Bracket matching is broken if section patterns are followed by a block pattern in grammar
Product: [ECD] Orion (Archived) Reporter: Alex Tugarev <alex.tugarev>
Component: EditorAssignee: Grant Gayed <grant_gayed>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 Keywords: triaged
Version: 13.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Alex Tugarev CLA 2016-06-30 10:02:18 EDT
Consider the following patterns for the highlighting configuration:

patterns: [
 {include: "orion.lib#string_doubleQuote"},
 {include: "orion.lib#string_singleQuote"},
 {include: "orion.lib#brace_open"},
 {include: "orion.lib#brace_close"},
 {include: "orion.lib#bracket_open"},
 {include: "orion.lib#bracket_close"},
 {include: "orion.lib#parenthesis_open"},
 {include: "orion.lib#parenthesis_close"},
 {include: "orion.lib#number_decimal"},
 {include: "orion.lib#number_hex"}
]

Braket matching won't work if one add a block pattern (e.g. {include: "orion.lib#doc_block"}) at the end of this array.

Have a look at the function TextStyler#_initPatterns. It is assumed, that the block patterns are at the beginning of the array:

block.blockPatterns = block.linePatterns.slice(0, lastBlock + 1);

But if there is a block pattern after the section patterns, then all of them are treated as block patterns. This breaks at least the bracket matching. 

I have added a notice to https://wiki.eclipse.org/Orion/Documentation/Developer_Guide/Plugging_into_the_editor#orion.edit.highlighter.

If you like, I'd contribute a change to filter for block patterns instead of slicing the array by index.
Comment 1 Grant Gayed CLA 2016-06-30 14:23:03 EDT
Yes, there's an implicit assumption that all patterns that precede the last block pattern are treated as block patterns, even if they're defined with single-line match: values.  This is not documented and is a bit of a hack.  I think that changing this without making accompanying changes in some language grammars that depend on it would break them.

I will plan to revisit this in the near future (will be away for the next two weeks).