Bug 399388 - IncludeRules breaks dynamic RegExpr matching
Summary: IncludeRules breaks dynamic RegExpr matching
Status: RESOLVED FIXED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (show other bugs)
Version: 5.50.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-04 18:49 UTC by Christopher Jacobs
Modified: 2019-09-26 20:47 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
highlight definition file (2.62 KB, text/xml)
2018-10-04 18:49 UTC, Christopher Jacobs
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Jacobs 2018-10-04 18:49:42 UTC
Created attachment 115415 [details]
highlight definition file

SUMMARY

If a highlighting context uses `<IncludeRules context="..."/>` to include the rules from another context that contains a dynamic regular expression match (e.g. `<RegExpr String="%1" dynamic="true".../>` the *second* context becomes broken if it matches anywhere on the same line as the *first* context. Specifically, only the RegExpr rule stops matching correctly.

I've attached a very simple syntax highlighting definition file to illustrate. It only recognizes a single construct: a literal capital letter 'X', followed by a delimited string. The delimiter can either be a pair of matching parentheses, a pair of matching braces, or any other non-space character (where the end of the string occurs whenever the initial delimiter is matched again). If you're familiar with Perl's matching operator, it's basically a very stripped down version of this. Other than this simple setup, there are some bogus "keywords" that get matched _only_ inside the string, just to prove that these rules appear to working correctly.

The only difference between the two bracket-like contexts (other than the delimiter) is the way in which they "inherit" the keyword matching rules from the "generic" context. The brace-context uses the `<IncludeRules context="...">`, while the paren-context simply contains the copy-pasted content.

Generally, all of these contexts work well when the constructs they match are alone on a line. That is, all of the following highlight correctly:

    normal X(string with This and That and other) normal
    normal X{string with This and That and other} normal
    normal X:string with This and That and other: normal

The paren-delimited and generic-delimited contexts will similarly highlight everything correctly when paired in the same line:

    normal X(string with This and That and other) normal X(string with This and That and other) normal
    normal X(string with This and That and other) normal X:string with This and That and other: normal
    normal X:string with This and That and other: normal X(string with This and That and other) normal
    normal X:string with This and That and other: normal X:string with This and That and other: normal

But things stop working when the brace-delimited construct _precedes_ a generically-delimited construct:

    normal X{string with This and That and other} normal X:string with This and That and other: this is _not_ normal

The generic-delimited context doesn't recognize the ':' delimiter and the text after it will continue matching against the rules in that context. The other-way around works just fine:

    normal X:string with This and That and other: normal X{string with This and That and other} normal again

The contexts pop at end-of-line, so things are restored to normal whenever a newline occurs. Things get a little more interesting when `lineEndContext="#stay"` is applied. The patterns above still hold, except that in the broken scenario, if a ':' is found on any subsequent line, it is recognized:

    normal X{string with This and That and other} normal X:string with This and That and other: this is _not_ normal
    string continues to new line: <- delimiter recognized, normal again

SOFTWARE VERSIONS
(available in About System)
KDE Plasma Version: 5.50.0
KDE Frameworks Version: 5.50.0
Qt Version: 5.11.2
Comment 1 Jonathan Poelen 2019-09-26 20:47:30 UTC
Git commit d6b1e02ad4da168755df693bca379937ce618f13 by Jonathan Poelen.
Committed on 26/09/2019 at 21:03.
Pushed by jpoelen into branch 'master'.

Fix skipOffset with dynamic RegExpr

Summary:
The pattern used depends on the previous contexts so skipOffset cannot be computed with a dynamic regex.

Reviewers: #framework_syntax_highlighting, dhaumann, cullmann

Reviewed By: #framework_syntax_highlighting, cullmann

Subscribers: kwrite-devel, kde-frameworks-devel

Tags: #kate, #frameworks

Differential Revision: https://phabricator.kde.org/D24179

A  +2    -0    autotests/folding/d399388_dynamic_RegExpr.dyInclRl.fold
A  +9    -0    autotests/html/d399388_dynamic_RegExpr.dyInclRl.html
A  +2    -0    autotests/input/d399388_dynamic_RegExpr.dyInclRl
A  +40   -0    autotests/input/syntax/d399388_dynamic_RegExpr.xml
A  +2    -0    autotests/reference/d399388_dynamic_RegExpr.dyInclRl.ref
M  +3    -1    src/lib/rule.cpp

https://commits.kde.org/syntax-highlighting/d6b1e02ad4da168755df693bca379937ce618f13