YAML: fix keys, add numbers and other improvements

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

Description

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:

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:

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

Details