From 0e1d45dc365ff481555d8767c3057e693404900e Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 27 Oct 2021 11:06:40 +0200 Subject: [PATCH] tweaks: fold some regexes together, and trim or improve some comments Also, trim some whitespace and group one rule better. Also, fix a stray closing parenthesis in the JSON syntax, and add the missing slash to the possible escaped characters. (Reference: https://www.json.org/json-en.html.) Also, improve the ending of multiline strings in the Rust syntax. --- syntax/asm.nanorc | 4 ++-- syntax/c.nanorc | 3 +-- syntax/changelog.nanorc | 6 +++--- syntax/cmake.nanorc | 3 +++ syntax/css.nanorc | 12 ++++++------ syntax/extra/ada.nanorc | 2 +- syntax/go.nanorc | 2 +- syntax/guile.nanorc | 3 +-- syntax/json.nanorc | 2 +- syntax/nftables.nanorc | 4 +++- syntax/objc.nanorc | 4 ++-- syntax/ocaml.nanorc | 4 ++-- syntax/python.nanorc | 4 ++-- syntax/rust.nanorc | 4 ++-- syntax/sh.nanorc | 2 +- syntax/xml.nanorc | 6 +++--- 16 files changed, 34 insertions(+), 31 deletions(-) diff --git a/syntax/asm.nanorc b/syntax/asm.nanorc index d7386623..2fa39279 100644 --- a/syntax/asm.nanorc +++ b/syntax/asm.nanorc @@ -11,8 +11,8 @@ color brightyellow "\.(ascii|asciz|byte|double|float|hword|int|long|short|single color brightred "^[[:blank:]]*[.0-9A-Za-z_]*:" color brightcyan "^[[:blank:]]*#[[:blank:]]*(define|undef|include|ifn?def|endif|elif|else|if|warning|error)" -# Strings. -color brightyellow "<[^= ]*>|"([^"\]|\\.)*"" +# Strings and names of included files. +color brightyellow ""([^"\]|\\.)*"|<[^= ]*>" # Comments. color brightblue "//.*" diff --git a/syntax/c.nanorc b/syntax/c.nanorc index 9571b3c9..23923526 100644 --- a/syntax/c.nanorc +++ b/syntax/c.nanorc @@ -28,8 +28,7 @@ color brightmagenta "'([^'\]|\\(["'\abfnrtv]|x[0-9A-Fa-f]{1,2}|[0-3]?[0-7]{1,2}) # GCC builtins. color cyan "__attribute__[[:blank:]]*\(\([^)]*\)\)" "__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__" -# Strings. (In general you will want your strings and comments to come last, -# because highlighting rules are applied in the order they are read in.) +# Strings and names of included files. color brightyellow ""([^"]|\\")*"" "#[[:blank:]]*include[[:blank:]]*<[^>]+>" # Preprocessor directives. diff --git a/syntax/changelog.nanorc b/syntax/changelog.nanorc index fa0bb46f..3c4c2840 100644 --- a/syntax/changelog.nanorc +++ b/syntax/changelog.nanorc @@ -13,13 +13,13 @@ color red "^(19|20)[0-9-]{8}" color yellow "<[^>]*@[^>]*>" # Command-line options. -color cyan "[[:blank:]]-[a-zA-Z\$]" "--[8a-z-]+" +color cyan "[[:blank:]]-[a-zA-Z\$]|--[8a-z-]+" # Bug and patch numbers. -color cyan "(BZ|bug|patch)[ ]#[0-9]+" "PR [[:alnum:]]+/[0-9]+" +color cyan "(BZ|bug|patch)[ ]#[0-9]+|PR [[:alnum:]]+/[0-9]+" # Probable constants, for variety. color brightred "\<[A-Z_][0-9A-Z_]+\>" # Key sequences. -color brightblue "\^[A-Z^\]" "\" +# Comments. color brightblue "(^|[[:blank:]])#.*" + +# Trailing whitespace. color ,green "[[:space:]]+$" diff --git a/syntax/css.nanorc b/syntax/css.nanorc index be014bff..5a0946db 100644 --- a/syntax/css.nanorc +++ b/syntax/css.nanorc @@ -4,17 +4,17 @@ syntax css "\.css$" comment "/*|*/" # First make everything red: -color brightred "." +color brightred "." # Then everything between braces yellow: -color brightyellow start="\{" end="\}" +color brightyellow start="\{" end="\}" # Then everything after a colon white: -color brightwhite start=":" end="([;^{]|$)" +color brightwhite start=":" end="([;^{]|$)" # Pseudo-classes: -color brightcyan ":(active|checked|focus|hover|link|visited|after|before)\>" +color brightcyan ":(active|checked|focus|hover|link|visited|after|before)\>" # Comments: -color brightblue start="/\*" end="\*/" +color brightblue start="/\*" end="\*/" # Syntactic characters: -color green ";|:|\{|\}" +color green ";|:|\{|\}" diff --git a/syntax/extra/ada.nanorc b/syntax/extra/ada.nanorc index e0cf5aea..85711bba 100644 --- a/syntax/extra/ada.nanorc +++ b/syntax/extra/ada.nanorc @@ -30,7 +30,7 @@ color cyan "'[[:alnum:]]+" color green "\<[0-9][0-9A-Fa-f_#.+-]*" # Characters / Strings -color red "'.'" ""[^"]*"" +color red "'.'|"[^"]*"" # Comments color brightblue "--.*" diff --git a/syntax/go.nanorc b/syntax/go.nanorc index 3266dad9..00b4e6ec 100644 --- a/syntax/go.nanorc +++ b/syntax/go.nanorc @@ -26,6 +26,7 @@ color magenta "\<(break|continue|fallthrough|goto|return)\>" color brightcyan "\<(package|import)\>" # Literals. +color red "\<(true|false|nil|iota|_)\>" color red "\<([1-9][0-9]*|0[0-7]*|0[xX][0-9A-Fa-f]+)\>" color red "\<[0-9]+\.[0-9]*([eE][+-]?[0-9]+)?i?\>" color red "\<[0-9]+[eE][+-]?[0-9]+i?\>" @@ -33,7 +34,6 @@ color red "\B\.[0-9]+([eE][+-]?[0-9]+)?i?\>" color red "\<[0-9]+i\>" # Strings and characters; slightly fuzzy. -color red "\<(true|false|nil|iota|_)\>" color red ""([^"\]|\\.)*"|'([^'\]|\\.)+'" color red start=""([^"\]|\\.)*\\[[:blank:]]*$" end="^([^"\]|\\.)*"" diff --git a/syntax/guile.nanorc b/syntax/guile.nanorc index 0c61a5c1..2f231fad 100644 --- a/syntax/guile.nanorc +++ b/syntax/guile.nanorc @@ -11,8 +11,7 @@ color brightcyan "\" # Quoted symbols color brightyellow "'\<(\w|-)+\>" # Chars -color brightmagenta "#\\." -color brightmagenta "#\\\w+\>" +color brightmagenta "#\\(.|\w+)" # Booleans color brightred "(#t|#f)\>" # Keywords diff --git a/syntax/json.nanorc b/syntax/json.nanorc index 05be6569..9178f1e3 100644 --- a/syntax/json.nanorc +++ b/syntax/json.nanorc @@ -14,7 +14,7 @@ color brightmagenta "".+"" # Hex numbers (used as value). color green ":[[:blank:]]*"#[0-9abcdefABCDEF]+"" # Escapes. -color green "\\\\" "\\"" "\\[bfnrt]" "\\u[0-9abcdefABCDEF]{4})" +color green "\\["\/bfnrt]" "\\u[0-9abcdefABCDEF]{4}" # Special words. color green "\<(true|false|null)\>" diff --git a/syntax/nftables.nanorc b/syntax/nftables.nanorc index 263f180d..9facbb44 100644 --- a/syntax/nftables.nanorc +++ b/syntax/nftables.nanorc @@ -25,8 +25,10 @@ color cyan "(^|[[:blank:]])#.*" # Trailing whitespace color ,green "[[:space:]]+$" -# Strings and others +# Strings color yellow ""([^"\]|\\.)*"|'([^'\]|\\.)*'" + +# Syntactic symbols color green "[][{}():;|`$<>!=&\]" # Basic variable names diff --git a/syntax/objc.nanorc b/syntax/objc.nanorc index fc46ad3e..97940b80 100644 --- a/syntax/objc.nanorc +++ b/syntax/objc.nanorc @@ -4,7 +4,7 @@ syntax m "\.m$" magic "Objective-C source" comment "//" -# Stuffs, +# Stuffs. color brightwhite "\<[A-Z_][0-9A-Z_]+\>" color green "\<(float|double|BOOL|bool|char|int|short|long|id|sizeof|enum|void|static|const|struct|union|typedef|extern|(un)?signed|inline)\>" color green "\<[[:alpha:]_][[:alnum:]_]*_t\>" @@ -24,7 +24,7 @@ color magenta "[[:alnum:]]*:" color white "\[[^][:blank:]]*\]" # Strings. -color brightblack "'([^'\]|(\\["'abfnrtv\]))'" "'\\(([0-3]?[0-7]{1,2}))'" "'\\x[0-9A-Fa-f]{1,2}'" +color brightblack "'([^'\]|\\(["'\abfnrtv]|x[0-9A-Fa-f]{1,2}|[0-3]?[0-7]{1,2}))'" color brightblack "<[^= ]*>|"([^"\]|\\.)*"" color brightblue "@"([^"\]|\\.)*"" diff --git a/syntax/ocaml.nanorc b/syntax/ocaml.nanorc index 26b20b93..64319b36 100644 --- a/syntax/ocaml.nanorc +++ b/syntax/ocaml.nanorc @@ -26,5 +26,5 @@ color green "\<(include|inherit|initializer)\>" color yellow "\<(new|ref|mutable|lazy|assert|raise)\>" # Comments: color white start="\(\*" end="\*\)" -# Strings: (no multiline handling yet) -color brightblack ""[^\"]*"" +# Strings: +color brightblack ""[^"\]*"" diff --git a/syntax/python.nanorc b/syntax/python.nanorc index fd3ff393..931f6aad 100644 --- a/syntax/python.nanorc +++ b/syntax/python.nanorc @@ -29,8 +29,8 @@ color normal "'''|"""" # Comments. color brightred "(^|[[:blank:]])#.*" # Triple-quoted strings. -color brightgreen start="'''([^'),]|$)" end="(^|[^(\])'''" -color brightgreen start=""""([^"),]|$)" end="(^|[^(\])"""" +color brightgreen start="'''([^'),]|$)" end="(^|[^(\])'''" +color brightgreen start=""""([^"),]|$)" end="(^|[^(\])"""" # Reminders. color brightwhite,yellow "\<(FIXME|TODO|XXX)\>" diff --git a/syntax/rust.nanorc b/syntax/rust.nanorc index 1a933ab3..640ffa74 100644 --- a/syntax/rust.nanorc +++ b/syntax/rust.nanorc @@ -23,8 +23,8 @@ color magenta "[A-Z][A-Za-z0-9]+" # Strings color green ""([^"]|\\")*"" -color green start=""([^"]|\\")*\\$" end=".*"" -## NOTE: This isn't accurate, but matching "#{0,} for the end of the string is too liberal. +color green start=""([^"]|\\")*\\$" end="(^|.*[^\])"" +## Inaccurate, but it's not possible to balance the number of hashes. color green start="r#+"" end=""#+" # Comments diff --git a/syntax/sh.nanorc b/syntax/sh.nanorc index 0deb5d20..71191377 100644 --- a/syntax/sh.nanorc +++ b/syntax/sh.nanorc @@ -18,7 +18,7 @@ color green "[][{}():;|`$<>!=&\]" color green "-(eq|ne|gt|lt|ge|le|ef|ot|nt)\>" # Short and long options. -color brightmagenta "[[:blank:]]-[A-Za-z]\>" "[[:blank:]]--[A-Za-z-]+\>" +color brightmagenta "[[:blank:]](-[A-Za-z]|--\<[A-Za-z-]+)\>" # Common commands. color brightblue "\<(awk|cat|cd|ch(grp|mod|own)|cp|cut|echo|env|grep|head|install|ln|make|mkdir|mv|popd|printf|pushd|rm|rmdir|sed|set|sort|tail|tar|touch|umask|unset)\>" diff --git a/syntax/xml.nanorc b/syntax/xml.nanorc index 8aab9f46..c212b4ea 100644 --- a/syntax/xml.nanorc +++ b/syntax/xml.nanorc @@ -6,10 +6,10 @@ magic "(XML|SGML) (sub)?document" comment "" # The entire content of the tag: -color green start="<" end=">" +color green start="<" end=">" # The start and the end of the tag: -color cyan "<[^> ]+" ">" +color cyan "<[^> ]+" ">" # The strings inside the tag: color magenta ""[^"]*"" @@ -19,4 +19,4 @@ color yellow start="" color yellow start="" # Escapes: -color red "&[^;]*;" +color red "&[^;]*;"