Bug 361875 - ruby syntax markup fails on regexes
Summary: ruby syntax markup fails on regexes
Status: RESOLVED FIXED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (other bugs)
Version First Reported In: unspecified
Platform: Debian unstable Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL: http://dump.bitcheese.net/files/ikyxi...
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-16 21:02 UTC by Voker57
Modified: 2019-01-16 09:07 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 5.55.0
Sentry Crash Report:


Attachments
Screenshot from original reporter (1.04 KB, image/png)
2016-07-02 11:00 UTC, Buovjaga
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Voker57 2016-04-16 21:02:05 UTC
This ruby code: "get 'files/:slug/:filename', to: 'files#download', slug: /^[a-z]+$/, filename: %r|^[^/\s]+$|"

somehow breaks kate's highlighting. See URL for more information:  /^[a-z]+$/ is not considered a regex, %r|^[^/\s]+$| as well.

Reproducible: Always

Steps to Reproduce:
1. Set syntax highlighting to Ruby
2. input text "get 'files/:slug/:filename', to: 'files#download', slug: /^[a-z]+$/, filename: %r|^[^/\s]+$|"

Actual Results:  
See URL.

Expected Results:  
regexes should be highlighted as regexes.
Comment 1 Buovjaga 2016-07-02 11:00:44 UTC
Created attachment 99799 [details]
Screenshot from original reporter
Comment 2 Buovjaga 2016-07-02 11:01:24 UTC
Reproduced.

Arch Linux 64-bit
Kate 16.04.2
KDE Frameworks 5.23.0
Qt 5.7
xcb wm
Comment 3 Nibaldo G. 2019-01-16 09:07:20 UTC
Git commit 4c577562628e2c0e28d241564a3335ede9eb8b32 by Nibaldo González.
Committed on 16/01/2019 at 09:07.
Pushed by ngonzalez into branch 'master'.

Ruby: fix RegExp after ": " and fix/improve detection of HEREDOC

Summary:
## Allow regular expressions after ": "
Related: bug 358273

Previously, after `text: `, `[]: ` or `$text=: ` regular expressions weren't highlighted (the `check_div_1` context prevents highlighting regex, similar to `NoRegExp` context in "javascript.xml"). Regular expressions are allowed there, so they will now be highlighted.
{F6539652}

## Don't highlight HEREDOC in singleton class definition (operator <<)

Now, after the keyword "class", Heredoc's will not be highlighted [1]. For example:
{F6539653}

Before, `<<Foo` was highlighted as Heredoc.

I did some tests in Ruby 2.6.0, 2.5.1 and 2.3.8, and Heredoc isn't considered in the code: `class <<Foo`, `class <<21`, `class <<"Foo"` or `class <<-Foo`, so I can say that the fix is correct.

## Improvements in HEREDOC:

* Add squiggly HEREDOC (introduced in Ruby 2.3) [2][3]

For example: `<<~HEREDOC`

* Backticks can surround identifiers [3]. Example: <<-`HEREDOC`

* Improve highlighting of identifier quotes. Now you need to close quotes to highlight the HEREDOC.

For example, HEREDOC was previously highlighted as: `<<"HEREDOC` , `<<HEREDOC"`

I also added a modeline to force the use of tabs as an indentation, since the file uses tabs.

**References:**
* [1] Ruby/Rails Programming. Singleton Classes in Ruby (aka eigenclasses): https://codequizzes.wordpress.com/2014/04/11/singleton-classes-in-ruby-aka-eigenclasses/
* [2] Infinum. Multiline strings in Ruby 2.3 - the squiggly heredoc: https://infinum.co/the-capsized-eight/multiline-strings-ruby-2-3-0-the-squiggly-heredoc
* [3] Ruby-doc.org. Here Documents: https://ruby-doc.org/core-2.5.1/doc/syntax/literals_rdoc.html#label-Here+Documents

FIXED-IN: 5.55.0

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/D18174

M  +22   -0    autotests/folding/highlight.rb.fold
M  +22   -0    autotests/html/highlight.rb.html
M  +22   -0    autotests/input/highlight.rb
M  +22   -0    autotests/reference/highlight.rb.ref
M  +35   -17   data/syntax/ruby.xml

https://commits.kde.org/syntax-highlighting/4c577562628e2c0e28d241564a3335ede9eb8b32