commit 485eb18d836ca584ff9e5e66c6bae190a4ffca0c
parent 375b30507ea60b49bffe759b3d8810c478482001
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Tue, 26 Oct 2021 12:27:15 +0200
syntaxes: use one regex for coloring quoted strings, to avoid overlap
Quoted strings cannot start within another quoted string and end after
that other string has ended. Therefore single-quoted and double-quoted
strings should (as much as possible) be colorized by a single rule, so
that overlapping colorations are avoided.
(This also fixes a double typo in the PHP syntax (\. --> \\.) that has
been there since the PHP syntax was added in 2008, commit 90ee8ee4.)
This fixes https://savannah.gnu.org/bugs/?61387.
Bug existed since each of these syntaxes was introduced,
the oldest ones around 2006, a few others around 2015.
The one that got it right was the Lua syntax from 2011.
Diffstat:
9 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/syntax/autoconf.nanorc b/syntax/autoconf.nanorc
@@ -17,7 +17,7 @@ color cyan "\<[[:upper:]_[:digit:]]+\>"
color red "\<[-_.0-9]+\>"
# Strings:
-color red ""[^"]*"" "'[^']*'"
+color red ""[^"]*"|'[^']*'"
# Backticks:
color green "`[^`]*`"
diff --git a/syntax/extra/gentoo.nanorc b/syntax/extra/gentoo.nanorc
@@ -41,7 +41,7 @@ color blue "\<(awk|cat|cd|chmod|chown|cp|echo|env|find|e?grep|ln|make|mkdir|mv|p
## Comments (doesn't work that well):
color yellow "(^|[[:space:]])#.*"
## Strings (doesn't work that well):
-color brightyellow ""(\\.|[^\"])*"" "'(\\.|[^'])*'"
+color brightyellow ""(\\.|[^\"])*"|'(\\.|[^'])*'"
## Trailing space is bad!
color ,green "[[:space:]]+$"
## Mixed whitespace is also bad.
diff --git a/syntax/go.nanorc b/syntax/go.nanorc
@@ -34,8 +34,7 @@ color red "\<[0-9]+i\>"
# Strings and characters; slightly fuzzy.
color red "\<(true|false|nil|iota|_)\>"
-color red "'(\\.|[^'])+'"
-color red ""(\\.|[^"])*""
+color red ""(\\.|[^"])*"|'(\\.|[^'])+'"
color red start=""(\\.|[^"])*\\[[:blank:]]*$" end="^(\\.|[^"])*""
# Comments.
diff --git a/syntax/javascript.nanorc b/syntax/javascript.nanorc
@@ -17,7 +17,7 @@ color cyan "\<([0-9]+|0x[0-9A-Fa-f]+)\>"
color cyan "\<(true|false|null|undefined)\>"
# Strings.
-color brightmagenta ""(\\.|[^"])*"" "'(\\.|[^'])*'" "`(\\.|[^`])*`"
+color brightmagenta ""(\\.|[^"])*"|'(\\.|[^'])*'|`(\\.|[^`])*`"
# Comments.
color brightblue "(^|[[:blank:]])//.*"
color brightblue start="/\*" end="\*/"
diff --git a/syntax/nftables.nanorc b/syntax/nftables.nanorc
@@ -26,7 +26,7 @@ color cyan "(^|[[:blank:]])#.*"
color ,green "[[:space:]]+$"
# Strings and others
-color yellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"
+color yellow ""(\\.|[^"])*"|'(\\.|[^'])*'"
color green "[][{}():;|`$<>!=&\]"
# Basic variable names
diff --git a/syntax/php.nanorc b/syntax/php.nanorc
@@ -25,7 +25,7 @@ color brightcyan "\<(and|or|xor)\>"
color magenta "\<(break|continue|goto|return)\>"
# Strings.
-color brightyellow ""(\.|[^"])*"" "'(\.|[^'])*'"
+color brightyellow ""(\\.|[^"])*"|'(\\.|[^'])*'"
# Comments.
color brightblue "(^|[[:blank:]]+)//.*"
diff --git a/syntax/python.nanorc b/syntax/python.nanorc
@@ -24,8 +24,7 @@ color brightcyan "\<(exec|print)([[:blank:]]|$)"
color brightmagenta "\<(False|None|True)\>"
# Mono-quoted strings.
-color brightgreen "'([^'\]|\\.)*'|'''"
-color brightgreen ""([^"\]|\\.)*"|""""
+color brightgreen "'([^'\]|\\.)*'|"([^"\]|\\.)*"|'''|""""
color normal "'''|""""
# Comments.
color brightred "(^|[[:blank:]])#.*"
diff --git a/syntax/sh.nanorc b/syntax/sh.nanorc
@@ -33,7 +33,7 @@ color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:bla
color cyan "(^|[[:blank:]])#.*"
# Strings.
-color brightyellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"
+color brightyellow ""(\\.|[^"])*"|'(\\.|[^'])*'"
# Trailing whitespace.
color ,green "[[:space:]]+$"
diff --git a/syntax/tcl.nanorc b/syntax/tcl.nanorc
@@ -17,7 +17,7 @@ color green "\<(alarm|auto_load_pkg|bsearch|catclose|catgets|catopen|ccollate|cc
# Syntax:
color brightblue "\<proc[[:blank:]]|\{|\}"
color green "\(|\)|\;|`|\\|\$|<|>|!|=|&|\|"
-color brightyellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"
+color brightyellow ""(\\.|[^"])*"|'(\\.|[^'])*'"
color brightred "\$\{?[0-9A-Za-z_!@#$*?-]+\}?"
# Trailing whitespace: