]> git.lizzy.rs Git - micro.git/commitdiff
Highlight multicharacter escape sequences in C and C++ string literals (#1761)
authorJán Priner <51519088+priner@users.noreply.github.com>
Wed, 8 Jul 2020 04:17:48 +0000 (06:17 +0200)
committerGitHub <noreply@github.com>
Wed, 8 Jul 2020 04:17:48 +0000 (00:17 -0400)
runtime/syntax/c.yaml
runtime/syntax/cpp.yaml

index bdcbef5e7d2ba0e28a06b023cfe82bc2e0fd28d3..15310ee82053fced3984192caa4b0597e3591a20 100644 (file)
@@ -12,9 +12,6 @@ rules:
     - statement: "\\b(for|if|while|do|else|case|default|switch)\\b"
     - statement: "\\b(goto|continue|break|return)\\b"
     - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)"
-    - constant: "'([^'\\\\]|(\\\\[\"'abfnrtv\\\\]))'"
-    - constant: "'\\\\(([0-3]?[0-7]{1,2}))'"
-    - constant: "'\\\\x[0-9A-Fa-f]{1,2}'"
       # GCC builtins
     - statement: "__attribute__[[:space:]]*\\(\\([^)]*\\)\\)"
     - statement: "__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__"
@@ -29,15 +26,15 @@ rules:
         end: "\""
         skip: "\\\\."
         rules:
-            - constant.specialChar: "\\\\."
+            - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})"
 
     - constant.string:
         start: "'"
         end: "'"
         skip: "\\\\."
         rules:
-            - preproc: "..+"
-            - constant.specialChar: "\\\\."
+            - error: "..+"
+            - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})"
 
     - comment:
         start: "//"
index d1ffaeb6f9fc62c549c1d2ee79f54c9ca8ed14a7..a2fb42cc1fe30d05668ba82b84724c69241d3a74 100644 (file)
@@ -4,8 +4,7 @@ detect:
     filename: "(\\.c(c|pp|xx)$|\\.h(h|pp|xx)$|\\.ii?$|\\.(def)$)"
 
 rules:
-
-    - identifier: "\\b[A-Z_][0-9A-Z_]+\\b" 
+    - identifier: "\\b[A-Z_][0-9A-Z_]+\\b"
     - type: "\\b(auto|float|double|bool|char|int|short|long|sizeof|enum|void|static|const|constexpr|struct|union|typedef|extern|(un)?signed|inline)\\b"
     - type: "\\b((s?size)|((u_?)?int(8|16|32|64|ptr)))_t\\b"
     - statement: "\\b(class|namespace|template|public|protected|private|typename|this|friend|virtual|using|mutable|volatile|register|explicit)\\b"
@@ -13,13 +12,12 @@ rules:
     - statement: "\\b(try|throw|catch|operator|new|delete)\\b"
     - statement: "\\b(goto|continue|break|return)\\b"
     - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)"
-    - constant: "('([^'\\\\]|(\\\\[\"'abfnrtv\\\\]))'|'\\\\(([0-3]?[0-7]{1,2}))'|'\\\\x[0-9A-Fa-f]{1,2}')"
 
       # GCC builtins
     - statement: "(__attribute__[[:space:]]*\\(\\([^)]*\\)\\)|__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__)"
 
       # Operator Color
-    - symbol.operator: "([.:;,+*|=!\\%]|<|>|/|-|&)" 
+    - symbol.operator: "([.:;,+*|=!\\%]|<|>|/|-|&)"
       # Parenthetical Color
     - symbol.brackets: "[(){}]|\\[|\\]"
 
@@ -31,15 +29,15 @@ rules:
         end: "\""
         skip: "\\\\."
         rules:
-            - constant.specialChar: "\\\\."
+            - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})"
 
     - constant.string:
         start: "'"
         end: "'"
         skip: "\\\\."
         rules:
-            - preproc: "..+"
-            - constant.specialChar: "\\\\."
+            - error: "..+"
+            - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})"
 
     - comment:
         start: "//"