YAML: fix keys, add numbers and other improvements
ClosedPublic

Authored by nibags on Aug 12 2018, 9:43 AM.

Details

Summary

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

  • Fixes the end of a Key:

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 :

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:

BUG: 389636

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

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).

  • 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.

  • 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.

  • 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.

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:

Diff Detail

Repository
R216 Syntax Highlighting
Branch
fix-yaml
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 1722
Build 1740: arc lint + arc unit
nibags created this revision.Aug 12 2018, 9:43 AM
Restricted Application added projects: Kate, Frameworks. · View Herald TranscriptAug 12 2018, 9:43 AM
Restricted Application added subscribers: kde-frameworks-devel, kwrite-devel. · View Herald Transcript
nibags requested review of this revision.Aug 12 2018, 9:43 AM
cullmann accepted this revision.Aug 12 2018, 10:52 AM

The screenshots look convincing!

This revision is now accepted and ready to land.Aug 12 2018, 10:52 AM
nibags closed this revision.Aug 12 2018, 11:08 AM