Skip to content

Commit d60cd21

Browse files
committed
enh(php): Tidy up regex rules
- Use `\<` and `\>` to match word boundaries, instead of `[^a-z0-9_-]{1}` - Fix the OR operator `||` being highlighted twice. - Fix cannot include escapes in quoted strings. - Fix redundant highlights to HEREDOC. - Make inline comments regex more compact. - Variables: Remove parts that does not seem relevant
1 parent 8cba4b0 commit d60cd21

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

php.nanorc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ syntax "PHP" "\.php[2345s~]?$|\.module$"
33
header "^#!.*php"
44
magic "PHP script"
55
comment "//"
6+
7+
# Default
68
color white start="<\?(php|=)?" end="\?>"
79
# Constructs
810
color brightblue "(class|extends|goto) ([a-zA-Z0-9_]*)"
9-
color brightblue "[^a-z0-9_-]{1}(var|class|function|echo|case|break|default|exit|switch|if|else|elseif|endif|foreach|endforeach|@|while|public|private|protected|return|const|static|extends|as|array|require|include|require_once|include_once|define|do|continue|declare|goto|print|in|namespace|use)[^a-z0-9_-]{1}"
11+
color brightblue "\<(var|class|function|echo|case|break|default|exit|switch|if|else|elseif|endif|foreach|endforeach|@|while|public|private|protected|return|const|static|extends|as|array|require|include|require_once|include_once|define|do|continue|declare|goto|print|in|namespace|use)\>"
1012
color brightblue "[a-zA-Z0-9_]+:"
1113
# Variables
12-
color green "\$[a-zA-Z_0-9$]*|[=!<>]"
13-
color green "\->[a-zA-Z_0-9$]*|[=!<>]"
14+
#color green "\$[a-zA-Z_0-9]*|[=!<>]"
15+
#color green "\->[a-zA-Z_0-9$]*|[=!<>]"
16+
color green "\$[a-zA-Z_0-9]*"
17+
color green "\->[a-zA-Z_0-9]*"
1418
# Functions
1519
color brightblue "([a-zA-Z0-9_-]*)\("
1620
# Special values
17-
color brightmagenta "[^a-z0-9_-]{1}(true|false|null|TRUE|FALSE|NULL)$"
18-
color brightmagenta "[^a-z0-9_-]{1}(true|false|null|TRUE|FALSE|NULL)[^A-Za-z0-9_-]{1}"
21+
color brightmagenta "\<(true|false|null|TRUE|FALSE|NULL)\>"
1922
# Special Characters
2023
color yellow "[.,{}();]"
2124
color cyan "\["
@@ -30,26 +33,25 @@ color magenta ";"
3033
color yellow "(<|>)"
3134
# Assignment operator
3235
color brightblue "="
33-
# Bitwise Operations
36+
# Bitwise operators
3437
color magenta "(&|\||\^)"
3538
color magenta "(<<|>>)"
3639
# Comparison operators
3740
color yellow "(==|===|!=|<>|!==|<=|>=|<=>)"
3841
# Logical Operators
39-
color yellow "( and | or | xor |!|&&|\|\|)"
40-
# And/Or/SRO/etc
41-
color cyan "(\;\;|\|\||::|=>|->)"
42+
color yellow "\<(and|or|xor)\>" "(!|&&|\|\|)"
43+
# SRO and other operators
44+
color cyan "(\;\;|::|=>|->)"
4245
# Double quoted STRINGS!
43-
color red "(\"[^\"]*\")"
46+
color red "\"([^"\]|\\.)*\""
47+
# Single quoted string
48+
color red "'([^'\]|\\.)*'"
4449
# Heredoc (typically ends with a semicolon).
4550
color red start="<<<['\"]?[A-Z][A-Z0-9_]*['\"]?" end="^[A-Z][A-Z0-9_]*;"
4651
# Inline Variables
4752
color white "\{\$[^}]*\}"
48-
# Single quoted string
49-
color red "('[^']*')"
5053
# Online Comments
51-
color brightyellow "^(#.*|//.*)$"
52-
color brightyellow "[ | ](#.*|//.*)$"
54+
color brightyellow "(^|[[:blank:]])(#.*|//.*)$"
5355
# PHP Tags
5456
color red "(<\?(php)?|\?>)"
5557
# General HTML
@@ -58,5 +60,3 @@ color red start="\?>" end="<\?(php|=)?"
5860
color ,green "[[:space:]]+$"
5961
# multi-line comments
6062
color brightyellow start="/\*" end="\*/"
61-
# Nowdoc
62-
color red start="<<<'[A-Z][A-Z0-9_]*'" end="^[A-Z][A-Z0-9_]*;"

0 commit comments

Comments
 (0)