Skip to content

Commit

Permalink
Python: Support for underscores in numbers (#3039)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvintensuan committed Aug 16, 2021
1 parent d8ef3d5 commit 6f5d68f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/prism-python.js
Expand Up @@ -54,7 +54,7 @@ Prism.languages.python = {
'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/,
'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(?:True|False|None)\b/,
'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?j?\b/i,
'number': /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?\b/i,
'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
'punctuation': /[{}[\];(),.:]/
};
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.

19 changes: 18 additions & 1 deletion tests/languages/python/number_feature.test
Expand Up @@ -7,6 +7,14 @@
0.3e-7
4.8e+1
42j
0b_0001
0b0_001
0o_754
0o7_540
0x_BadFace
0xBad_Face
4_200
4_200j

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

Expand All @@ -19,7 +27,16 @@
["number", "2.1E10"],
["number", "0.3e-7"],
["number", "4.8e+1"],
["number", "42j"]
["number", "42j"],
["number", "0b_0001"],
["number", "0b0_001"],
["number", "0o_754"],
["number", "0o7_540"],
["number", "0x_BadFace"],
["number", "0xBad_Face"],
["number", "4_200"],
["number", "4_200j"]

]

----------------------------------------------------
Expand Down

0 comments on commit 6f5d68f

Please sign in to comment.