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.
master
Benno Schulenberg 2021-10-26 12:27:15 +02:00
parent 375b30507e
commit 485eb18d83
9 changed files with 9 additions and 11 deletions

View File

@ -17,7 +17,7 @@ color cyan "\<[[:upper:]_[:digit:]]+\>"
color red "\<[-_.0-9]+\>"
# Strings:
color red ""[^"]*"" "'[^']*'"
color red ""[^"]*"|'[^']*'"
# Backticks:
color green "`[^`]*`"

View File

@ -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.

View File

@ -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.

View File

@ -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="\*/"

View File

@ -26,7 +26,7 @@ color cyan "(^|[[:blank:]])#.*"
color ,green "[[:space:]]+$"
# Strings and others
color yellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"
color yellow ""(\\.|[^"])*"|'(\\.|[^'])*'"
color green "[][{}():;|`$<>!=&\]"
# Basic variable names

View File

@ -25,7 +25,7 @@ color brightcyan "\<(and|or|xor)\>"
color magenta "\<(break|continue|goto|return)\>"
# Strings.
color brightyellow ""(\.|[^"])*"" "'(\.|[^'])*'"
color brightyellow ""(\\.|[^"])*"|'(\\.|[^'])*'"
# Comments.
color brightblue "(^|[[:blank:]]+)//.*"

View File

@ -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:]])#.*"

View File

@ -33,7 +33,7 @@ color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:bla
color cyan "(^|[[:blank:]])#.*"
# Strings.
color brightyellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"
color brightyellow ""(\\.|[^"])*"|'(\\.|[^'])*'"
# Trailing whitespace.
color ,green "[[:space:]]+$"

View File

@ -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: