Bug 411508

Summary: Digraphs and trigraphs in C and C++ are not handled correctly
Product: [Frameworks and Libraries] frameworks-syntax-highlighting Reporter: loic.damien
Component: syntaxAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: nibgonz
Priority: NOR    
Version First Reported In: 5.61.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 5.62.0
Sentry Crash Report:

Description loic.damien 2019-09-01 21:11:23 UTC
SUMMARY

Digraphs and trigraphs (https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C) are not handled correctly

STEPS TO REPRODUCE
1. Copy the folowing code in a C++ file (from https://twitter.com/lunasorcery/status/1168256179178475520):
int main()
<%
    [](){%>();
}
2. Place the cursor after the closing brace

OBSERVED RESULT
The brace on the second line is highlighted
The code folding "arrow" is on the third line

EXPECTED RESULT
The digraph on the second line is highlighted
The code folding "arrow" is on the second line

SOFTWARE/OS VERSIONS
Linux/KDE Plasma:
Operating System: Arch Linux 
KDE Plasma Version: 5.16.4
KDE Frameworks Version: 5.61.0
Qt Version: 5.13.0
OS Type: 64-bit
Comment 1 Nibaldo G. 2019-09-03 08:26:56 UTC
Digraphs can be easily added.
The trigraphs were removed in C++17 and are almost in disuse in C, do you think it is necessary to add them also to the C highlighter? For example, at least, the folding of ??< and ??> (equivalent to { and }).
Comment 2 Nibaldo G. 2019-09-03 09:05:53 UTC
Proposed patch: https://phabricator.kde.org/D23691
Comment 3 Christoph Cullmann 2019-09-03 16:46:11 UTC
Git commit 364ed572e2ec89c090c1c19dab8eab6a02518d46 by Christoph Cullmann, on behalf of Nibaldo González.
Committed on 03/09/2019 at 16:46.
Pushed by cullmann into branch 'master'.

C & ISO C++: add digraphs (folding & preprocessor)

Summary:

**ISO C ++**
* Add folding for digraphs `<%`, `%>`, `<:` and `:>`, which are equivalent to `{`, `}`, `[` and `]`.
* Fix the highlight of `%:` in preprocessor, for example, `%:include <some>`.

**C**
* Add folding for digraphs `<%` and `%>`, which are equivalent to `{` and `}`.
* Add `%:` equivalent to `#` in preprocessor.

Trigraphs were removed in C++17 and are supported in C (if activated in the compiler), but are almost obsolete. That's why I decided not to add them. Although if you wish I can add folding to `??<` and `??>`, which are equivalent to `{` and `}`.

**More:**
* https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C

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

M  +8    -0    autotests/folding/highlight.cpp.fold
M  +9    -0    autotests/folding/test.c.fold
M  +8    -0    autotests/html/highlight.cpp.html
M  +9    -0    autotests/html/test.c.html
M  +8    -0    autotests/input/highlight.cpp
M  +9    -0    autotests/input/test.c
M  +8    -0    autotests/reference/highlight.cpp.ref
M  +9    -0    autotests/reference/test.c.ref
M  +21   -16   data/syntax/c.xml
M  +9    -4    data/syntax/isocpp.xml

https://commits.kde.org/syntax-highlighting/364ed572e2ec89c090c1c19dab8eab6a02518d46