Skip to content

Commit f09f9f5

Browse files
committed
Python: Make triple-quoted strings greedy + regexp optimisation and simplification
1 parent 92318b0 commit f09f9f5

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

components/prism-python.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
Prism.languages.python = {
2-
'triple-quoted-string': {
3-
pattern: /"""[\s\S]+?"""|'''[\s\S]+?'''/,
4-
alias: 'string'
5-
},
62
'comment': {
73
pattern: /(^|[^\\])#.*/,
84
lookbehind: true
95
},
6+
'triple-quoted-string': {
7+
pattern: /("""|''')[\s\S]+?\1/,
8+
greedy: true,
9+
alias: 'string'
10+
},
1011
'string': {
11-
pattern: /("|')(?:\\\\|\\?[^\\\r\n])*?\1/,
12+
pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
1213
greedy: true
1314
},
1415
'function': {
15-
pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_][a-zA-Z0-9_]*(?=\s*\()/g,
16+
pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
1617
lookbehind: true
1718
},
1819
'class-name': {
19-
pattern: /(\bclass\s+)[a-z0-9_]+/i,
20+
pattern: /(\bclass\s+)\w+/i,
2021
lookbehind: true
2122
},
2223
'keyword': /\b(?:as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|pass|print|raise|return|try|while|with|yield)\b/,
23-
'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/,
24+
'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/,
2425
'boolean': /\b(?:True|False|None)\b/,
2526
'number': /\b-?(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
2627
'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,

components/prism-python.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)