Skip to content

Commit 2a9a5af

Browse files
authored
Fix python decorator syntax. (zyedidia#2827)
1. Python decorators begin a compound statement, so they only appear at the start of a line. So match at the line start to avoid giving decorator colors to matrix multiplication (@) expressions. Source: https://docs.python.org/3/reference/compound_stmts.html#function-definitions 2. Python decorators go to the end of the line and might not include parentheses (for example @functools.cache). So instead of matching everything until an `(`, just match as many non-`(` characters as possible---which both catches the @functools.cache example and allows decorator parameters to fall back to the default color. 3. Instead of hardcoding `brightgreen` (which railscast.micro also complains about), color decorators as `preproc` (otherwise unused by the python syntax files, and arguably the right colorscheme group to be using for syntactic sugars anyway). Note this will change decorator colors---for example from bright green to kinda brown on monokai, and from yellow to more of a light orange on railscast.
1 parent c55fb33 commit 2a9a5af

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

runtime/syntax/python2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rules:
2121
# keywords
2222
- statement: "\\b(and|as|assert|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield)\\b"
2323
# decorators
24-
- brightgreen: "@.*[(]"
24+
- preproc: "^\\s*@[^(]*"
2525
# operators
2626
- symbol.operator: "([.:;,+*|=!\\%@]|<|>|/|-|&)"
2727
# parentheses

runtime/syntax/python3.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ rules:
2020
# keywords
2121
- statement: "\\b(and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|raise|return|try|while|with|yield)\\b"
2222
# decorators
23-
- brightgreen: "@.*[(]"
23+
- preproc: "^\\s*@[^(]*"
2424
# operators
2525
- symbol.operator: "([~^.:;,+*|=!\\%@]|<|>|/|-|&)"
2626
# parentheses

0 commit comments

Comments
 (0)