Bug 389636 - YAML syntax highlighting for nested flow collections fails
Summary: YAML syntax highlighting for nested flow collections fails
Status: RESOLVED FIXED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (show other bugs)
Version: 5.28.0
Platform: Debian stable Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-30 09:57 UTC by Gerhard Bahr
Modified: 2018-08-13 00:01 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerhard Bahr 2018-01-30 09:57:34 UTC
In KDevelop this valid YAML code exhibits an incorrect syntax error marking:

{a: [{b: ''}]}

All characters from the first closing curly brace on are displayed in red and underlined.

The document mode and highlighting are set to Markup -> YAML.

Software used to reproduce this behaviour:

KDevelop Version 5.0.3

Using:
KDE Frameworks 5.28.0
Qt 5.7.1 (built against 5.7.1)
The xcb windowing system
Comment 1 Nibaldo G. 2018-08-12 11:31:09 UTC
Hi, thanks for reporting this bug.

It has been solved in: https://phabricator.kde.org/D14760
That corresponds to the commit: https://commits.kde.org/syntax-highlighting/bd9dbac79aa4402a3f768140993a53b12eab74e2

The fix will be included in KDE Frameworks 5.50, available in September 2018.
Comment 2 Nibaldo G. 2018-08-13 00:01:30 UTC
Git commit bd9dbac79aa4402a3f768140993a53b12eab74e2 by Nibaldo González.
Committed on 12/08/2018 at 11:08.
Pushed by ngonzalez into branch 'master'.

YAML: fix keys, add numbers and other improvements

Summary:
Fix some reported bugs and update the syntax for YAML 1.2:

* Fixes the end of a Key:
Related: bug 366586

Any line of text before `:` is highlighted as Key, which is very general and gives rise to errors. As mentioned in the bug, in a line like the following, everything is considered as a Key, until the last `:`
{F6188499}

To fix this, it's necessary to add a space/end-line to the end of a Key `KEY:(?=\s|$)`.
The YAML documentation mentions: *Mappings use a colon and space (“: ”) to mark each key: value pair* [1].

* Fix delimiter characters in a Key:

On the next line, it is highlighted as a Key: `{b:`
{F6188501}

Within hashes and lists, the characters `{`, `[` and `,` should not be highlighted as Keys, since these are delimiting characters that mark the start/end of an element.

* Allow inline attributes in lists: `[key1: value, key2: value, ...]`
Previously, when writing a key, the entire line was highlighted as a value, now the value ends with "," or "]" (in the example, `3, 2, !!ddfgdf` is Key and `sdsd 1, takeoff]}` is value).
{F6188504}

* Highlight values in Key with multiple lines. That is, when ":" is the first character of a line.

* Highlight references, aliases, strings, etc. in hashes. Before, the hashes only support content of the type `key: value`. This improves highlighting in keys with many lines.
{F6188507}

* Add mapping-key operator: `?`. In the current highlight, references, aliases, sequences and dash after "?" are not highlighted, that is corrected. This also applies to lists and hashes.
{F6188508}

* Add escapes [2]. Also, allow escapes in keys quoted. Ex: `"key\"a": value` or 'key''a': value`.

* Add Integers [4] & Floats [5] [3] (the documentation shows the exact regular expressions).

* Add booleans [7] & improves the detection of null (add missing null keywords) [6]. These are highlighted with "dsChar".

NOTE: Booleans, null, integers & floats require specific delimiters to avoid incorrect highlighting (for example, not highlight numbers present in sentences or dates). For that reason I use several RegExpr instead of keywords or other rules.

{F6188509}

Although there are still things to be corrected! Lines with literal/folded style (after "|" or ">") are not highlighted correctly.
Ex:
```
key1:
  - key2: |
     Literal characters " ' { }
     Literal...
  - key 3: value
```
To do that you have to capture the exact indentation of the Key. I tried to do it with dynamic rules, but it does not capture the spaces at the start of a line! I will try to fix this in a future diff. I added a comment mentioning this.

**References:**
* [1] YAML Specs, Collections: http://yaml.org/spec/1.2/spec.html#id2759963
* [2] YAML Specs, Escaped Characters: http://yaml.org/spec/1.2/spec.html#id2776092
* [3] YAML Specs, Integer & Float: http://yaml.org/spec/1.2/spec.html#id2803828
* [4] Integer Language-Independent Type for YAML™ Version 1.1: http://yaml.org/type/int.html
* [5] Floating-Point Language-Independent Type for YAML™ Version 1.1: http://yaml.org/type/float.html
* [6] Null Language-Independent Type for YAML™ Version 1.1: http://yaml.org/type/null.html
* [7] Boolean Language-Independent Type for YAML™ Version 1.1: http://yaml.org/type/bool.html

Reviewers: dhaumann, cullmann, #framework_syntax_highlighting

Reviewed By: cullmann, #framework_syntax_highlighting

Subscribers: kwrite-devel, kde-frameworks-devel

Tags: #kate, #frameworks

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

A  +78   -0    autotests/folding/test.yaml.fold
A  +85   -0    autotests/html/test.yaml.html
A  +78   -0    autotests/input/test.yaml
A  +78   -0    autotests/reference/test.yaml.ref
M  +166  -39   data/syntax/yaml.xml

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