Bug 363227

Summary: C++ and ISO C++ highlighting incorrectly highlight some numbers as errors
Product: [Frameworks and Libraries] frameworks-syntax-highlighting Reporter: Patrick Roye <patrick.roye>
Component: syntaxAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: minor CC: i.zaufi, ilmari.lauhakangas, jonathan.poelen
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: All   
URL: https://phabricator.kde.org/D14283
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Patrick Roye 2016-05-18 14:58:37 UTC
The C++ and ISO C++ highlighting styles mark the following decimal numbers as errors: -1.0f, -1e7, -1e7f. The C highlighting style correctly marks these as decimal numbers.

Reproducible: Always

Steps to Reproduce:
1. Type -1.0f -1e7f -1e7f into a file
2. Set the highlighting mode to C++ or ISO C++

Actual Results:  
The number are highlighted as errors

Expected Results:  
The numbers are highlighted as decimal numbers.

Kate version 16.07.70 built from source on Windows using Visual Studio 2015.
Comment 1 Buovjaga 2016-07-08 18:50:31 UTC
Reproduced.

Arch Linux 64-bit
Kate 16.04.2
KDE Frameworks 5.23.0
Qt 5.7
xcb wm
Comment 2 Dominik Haumann 2017-07-23 21:42:46 UTC
@Alex: Do you want to look into this? Sounds like a very prominent missing features (iirc that was once working correctly).
Comment 3 Alex Turbov 2017-07-23 22:45:40 UTC
(In reply to Dominik Haumann from comment #2)
> @Alex: Do you want to look into this? Sounds like a very prominent missing
> features (iirc that was once working correctly).

Dominic, I'm still using Kate from KDE 4 (unfortunately PyKF5 is not available and I can't port Pate to it) and it looks almost fine in here... except `f` char in last two numbers. So, probably bug was introduced later (after porting syntax files to KF5). Unfortunately, I can't fix it cuz simple do not kate latest `kate` :(
Comment 4 Alex Turbov 2017-07-23 22:48:10 UTC
[patch]
> simple do not kate latest `kate` :(

simple do not have latest `kate ;(
Comment 5 Alex Turbov 2017-07-23 23:11:52 UTC
I've reviewed the C++ standard and fixed a typo in my KDE4 version so all numbers are look correct.
Where is a repo w/ syntax files nowadays? (want to check the floating point regex in it)
Comment 6 Alex Turbov 2017-07-23 23:19:45 UTC
Ok, I've got the repo... and checking the C++ ISO file I see it uses "built-in" <Float> element which is far from being correct for C++. It was so, since KDE4! It is why "my" version of C++ syntax didn't use it! Instead, I've built a <RegEx> according to modern C++ standard to match floating point literals.
Comment 7 Alex Turbov 2017-07-23 23:53:14 UTC
Here is a bunch of test numbers to check the C++ FP highlighter:

    1f; -1F;                                                // integer w/ floating suffix
    0.1; -0.1;                                              // fractional constant
    .1; -.1;                                                // fractional constant w/o leading digit seq
    1.; -1.;                                                // ... same, but omit trailing digit seq
    1.f; -1.F;                                              // ... same w/ floating suffix
    1.l; -1.L;                                              // ... same w/ long double suffix
    1e1; -1e1; 1e-1; -1e-1;                                 // digit w/ exponent part
    1e1f; -1e1F; 1e-1F; -1e-1f;                             // ... same w/ floating suffix
    1e1l; -1e1L; 1e-1L; -1e-1l;
    1.0e1; -1.0e1;                                          // fractional constant w/ exponent
    1.0e1f; -1.0e1F; 1.0e-1l; -1.0e-1L;                     // ... same w/ floating suffix
    1.0e1f; -1.0e1F; 1.0e-1l; -1.0e-1L;

    1e1_udl; 1e-1_udl; 1.0e1_udl; 1.0e-1_udl;               // w/ user defined literal suffix

    // std::complex suffixes
    1i; 1if; 1il;
    1.i; 1.if; 1.il;
    1e1i; 1e-1i; 1.0e1i; 1.0e-1i;
    1e1if; 1e-1if; 1.0e1if; 1.0e-1if;
    1e1il; 1e-1il; 1.0e1il; 1.0e-1il;
Comment 8 Dominik Haumann 2017-07-24 08:14:54 UTC
The syntax highlighting files moved to the kde:syntax-highlighting framework, a standalone implementation of Kate's syntax highlighting.

Please upstream your changes, this is rather important, since it doesn't help anyone if you just fix this in your local repository.

The syntax-highlighting framework depends on qt-gui only, so you should be able to build it even if you still are on KDE 4.

In order to fix this properly:
1. Please adapt the isocpp.xml and related files
2. Add examples to the unit tests in autotest/input/highlight.cpp (and/or related files).
3. run make test
4. look at the failing tests (i.e. compare the HTML output in your browser)
5. If all looks good, call in your build folder ./autotests/update-reference-data.sh
6. Make a review request on phabricator.kde.org (look for Create Diff at the right pane)

This would be very very helpful! :-)
Comment 9 Dominik Haumann 2018-07-29 07:31:13 UTC
@Jonathan: Is this fixed with your recent changes?
Comment 10 Jonathan Poelen 2018-07-30 19:22:02 UTC
@dhaumann yes, I close the ticket