Skip to content

Commit

Permalink
Python: Add match and case (soft) keywords (#3142)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoonweiting committed Oct 7, 2021
1 parent 344d0b2 commit 3f24dc7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/prism-python.js
Expand Up @@ -51,7 +51,7 @@ Prism.languages.python = {
'punctuation': /\./
}
},
'keyword': /\b(?:and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
'keyword': /\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
'builtin': /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
'boolean': /\b(?:False|None|True)\b/,
'number': /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-python.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions tests/languages/python/keyword_feature.test
Expand Up @@ -9,6 +9,7 @@ pass print raise return
try while with yield
nonlocal
and not or
match case _:

----------------------------------------------------

Expand All @@ -23,9 +24,10 @@ and not or
["keyword", "pass"], ["keyword", "print"], ["keyword", "raise"], ["keyword", "return"],
["keyword", "try"], ["keyword", "while"], ["keyword", "with"], ["keyword", "yield"],
["keyword", "nonlocal"],
["keyword", "and"], ["keyword", "not"], ["keyword", "or"]
["keyword", "and"], ["keyword", "not"], ["keyword", "or"],
["keyword", "match"], ["keyword", "case"], ["keyword", "_"], ["punctuation", ":"]
]

----------------------------------------------------

Checks for all keywords.
Checks for all keywords.

0 comments on commit 3f24dc7

Please sign in to comment.