nibags created this revision.
Restricted Application added projects: Kate, Frameworks.
Restricted Application added subscribers: kde-frameworks-devel, kwrite-devel.
nibags requested review of this revision.
REVISION 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 `:`
{image1}
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).
For this, the context "attribute-pre-inline" is separated in the contexts
"list-attribute-pre-inline" and "hash-attribute-pre-inline"; and
"attribute-inline" is separated in "list-attribute-inline" and
"hash-attribute-inline". The only difference is that one ends with "}" and
another with "]".
- 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.
In Keys, the operator "?" now it is highlighted with the "Operator" attribute.
- Add escapes [2]. Single quote strings admit only one type of escape: `''`.
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.
**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
REPOSITORY
R216 Syntax Highlighting
BRANCH
fix-yaml
REVISION DETAIL
https://phabricator.kde.org/D14760
AFFECTED FILES
autotests/folding/test.yaml.fold
autotests/html/test.yaml.html
autotests/input/test.yaml
autotests/reference/test.yaml.ref
data/syntax/yaml.xml
To: nibags
Cc: kwrite-devel, kde-frameworks-devel, michaelh, kevinapavew, ngraham, bruns,
demsking, cullmann, sars, dhaumann