[gtksourceview/gnome-3-24] yaml.lang: fix some cases of falsely recognized map keys



commit 897c749bccadfd0c8204e99d8e3cea2e898d1b71
Author: Роман Донченко <dpb corrigendum ru>
Date:   Mon Apr 29 23:06:36 2019 +0300

    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.

 data/language-specs/yaml.lang | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/data/language-specs/yaml.lang b/data/language-specs/yaml.lang
index 4f52f8b6..4578bd66 100644
--- a/data/language-specs/yaml.lang
+++ b/data/language-specs/yaml.lang
@@ -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>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]