Bug 348765 - Perl syntax highlighting is wrong when using scalar references (backslash quote)
Summary: Perl syntax highlighting is wrong when using scalar references (backslash quote)
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL: http://imgur.com/WYnBB0M
Depends on:
Reported: 2015-06-06 00:12 UTC by johnnywalls
Modified: 2018-09-10 08:20 UTC (History)
3 users (show)

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


Note You need to log in before you can comment on or make changes to this bug.
Description johnnywalls 2015-06-06 00:12:21 UTC
In Perl, you can use a backslash before a quoted string to obtain a scalar reference.  But Kate's higlighting engine seems to think the backslash-quote is an escaped single quote, and messes subsequent syntax highlighting

Reproducible: Always

Steps to Reproduce:
1.Put Kate in Perl syntax highlighting mode (for example, by saving the current file with with a .pl extension)
2. Create a scalar reference, with something like my $x = \'string';
3. Keep writing valid code afterwards

Actual Results:  
The first backslash-quote in \'string' is treated as a single-quote escape, therefore the single quote ending \'string' is not recognized as an actual end of string.  All subsequent code is wrongly highlighted, as if the string declared weren't properly end-quoted.

Expected Results:  
The last single quote character in \'string' should be properly recognized as an end of string.

I had used scalar references in Perl with previous versions of Kate, and this wrong highlighting had not appeared before
Comment 1 Buovjaga 2016-06-25 14:37:44 UTC

Arch Linux 64-bit
Kate 16.04.2
KDE Frameworks 5.23.0
Qt 5.7
xcb wm
Comment 2 Christoph Cullmann 2017-06-25 11:50:34 UTC
Reassigning to syntax highlighting framework.
Comment 3 Nibaldo G. 2018-09-10 08:20:03 UTC
Git commit d0c698198ec8abc2245ee3d2ab38eabf8f62f444 by Nibaldo González.
Committed on 10/09/2018 at 08:19.
Pushed by ngonzalez into branch 'master'.

Perl: fix brackets, variables, string references and others

### Fix incorrect bracket closures in RegExp patterns
Related: bug 364866, bug 355300, bug 391577

Recursive subgroups are added inside brackets `{}` and `()`, to avoid incorrect closures in RegExp patterns. This correction is in accordance with other text editors (VS Code, Atom, gedit & Sublime Text), which highlight the RegExp patterns in that way.

### Allow strings as scalar references

Previously, the characters `"` and `'` were escaped, which caused an erroneous highlight when using references such as `\'string'` (see ref. [1] and [2]).

### Fix incorrect highlighting of variables that start with underscores

This error was caused by the order of the RegExpr rules to detect variables: `[@\$][\+\-_]` had priority over `\$[#_][\w_]` (`$_` is a special variable) (ref. [3] & [4]).

### Fix incorrect highlighting of characters in variables

Previously, characters such as `()[]}` were highlighted after `*` in some variables, such as `@*)`, causing incorrect closures of brackets.

### Other fixes:

* Add variables with carret, such as: `${^Foo}` or `$^V` (ref. [3]).
* Add special variables: `%+`, `%-`, `%!` & `%^H` (ref. [3]).
* Missing escapes are added, such as `\x{NN..}`, `\o{NN..}` (full list in ref. [5]).


* [1] Perl References: https://gist.github.com/afair/2402068
* [2] PerlMonks. Constant string reference: https://www.perlmonks.org/?node_id=413500
* [3] Perl Programming Documentation. perlvar: https://perldoc.perl.org/perlvar.html
* [4] PerlMonks. Perl Special Variables Quick Reference: https://www.perlmonks.org/?node_id=353259
* [5] Perl Programming Documentation. perlrebackslash: https://perldoc.perl.org/perlrebackslash.html

FIXED-IN: 5.51.0

Reviewers: cullmann, dhaumann, #framework_syntax_highlighting

Reviewed By: cullmann, #framework_syntax_highlighting

Subscribers: kwrite-devel, kde-frameworks-devel

Tags: #kate, #frameworks

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

M  +20   -0    autotests/folding/highlight.pl.fold
M  +20   -0    autotests/html/highlight.pl.html
M  +20   -0    autotests/input/highlight.pl
M  +20   -0    autotests/reference/highlight.pl.ref
M  +58   -13   data/syntax/perl.xml