Commit d53e1abb authored by Роман Донченко's avatar Роман Донченко Committed by Christian Hergert

yaml.lang: fix some cases of falsely recognized map keys

First, don't recognize keys inside of quoted strings. Currently, "a: b"
is recognized as a map entry with `"a` as the key and `b"` as the value.
Fix that by giving the "string" context a higher priority than the "map"
context.

Second, prevent some comments from being recognized as map entries.
Specifically, cases like this:

 # foo: bar

Even though the "map" context has lower priority than the "comment"
context, this would still be recognized as a map entry, because the map
regex would match the line starting with the leading space and thus be
the leftmost match. Fix this by requiring the first character of a map
key to not be a whitespace character.

There is still a case where a map entry is recognized where it shouldn't
be:

foo # bar: baz

However, I don't see a way to fix this without running into the
performance problem described in the comment in the "map" context
definition.
parent eda6cda0
......@@ -189,7 +189,7 @@
<match>(?&lt;=^|\s)((?:[^:]|:(?=\S))+)(?::\s+|:$)</match>
-->
<match>(?&lt;=^|\s)((?:[^:])+)(?::\s+|:$)</match>
<match>(?&lt;=^|\s)([^:\s][^:]*)(?::\s+|:$)</match>
<include>
<context sub-pattern="1" style-ref="map-key"/>
</include>
......@@ -223,8 +223,8 @@
<context ref="alias"/>
<context ref="tag"/>
<context ref="anchor"/>
<context ref="map"/>
<context ref="string"/>
<context ref="map"/>
<context ref="unquoted-string"/>
</include>
</context>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment