eric6/ThirdParty/Pygments/pygments/lexers/parsers.py

changeset 7983
54c5cfbb1e29
parent 7701
25f42e208e08
equal deleted inserted replaced
7982:48d210e41c65 7983:54c5cfbb1e29
3 pygments.lexers.parsers 3 pygments.lexers.parsers
4 ~~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for parser generators. 6 Lexers for parser generators.
7 7
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 13
62 'numbers': [ 62 'numbers': [
63 (r'0x[0-9A-Fa-f]+', Number.Hex), 63 (r'0x[0-9A-Fa-f]+', Number.Hex),
64 (r'[+-]?[0-9]+', Number.Integer), 64 (r'[+-]?[0-9]+', Number.Integer),
65 ], 65 ],
66 'literals': [ 66 'literals': [
67 (r'"(\\\\|\\"|[^"])*"', String), # double quote string 67 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
68 (r"'(\\\\|\\'|[^'])*'", String), # single quote string 68 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
69 (r'\[(\\\\|\\\]|[^\]])*\]', String), # square bracket literals 69 (r'\[(\\\\|\\[^\\]|[^\\\]])*\]', String), # square bracket literals
70 (r'/(?!\*)(\\\\|\\/|[^/])*/', String.Regex), # regular expressions 70 (r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/', String.Regex), # regular expressions
71 ], 71 ],
72 'identifiers': [ 72 'identifiers': [
73 (r'[a-zA-Z_]\w*', Name.Variable), 73 (r'[a-zA-Z_]\w*', Name.Variable),
74 ], 74 ],
75 'operators': [ 75 'operators': [
104 (r'(' + r'|'.join(( # keep host code in largest possible chunks 104 (r'(' + r'|'.join(( # keep host code in largest possible chunks
105 r'[^{}\'"/#]+', # exclude unsafe characters 105 r'[^{}\'"/#]+', # exclude unsafe characters
106 r'[^\\]\\[{}]', # allow escaped { or } 106 r'[^\\]\\[{}]', # allow escaped { or }
107 107
108 # strings and comments may safely contain unsafe characters 108 # strings and comments may safely contain unsafe characters
109 r'"(\\\\|\\"|[^"])*"', # double quote string 109 r'"(\\\\|\\[^\\]|[^"\\])*"',
110 r"'(\\\\|\\'|[^'])*'", # single quote string 110 r"'(\\\\|\\[^\\]|[^'\\])*'",
111 r'//.*$\n?', # single line comment 111 r'//.*$\n?', # single line comment
112 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment 112 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
113 r'\#.*$\n?', # ruby comment 113 r'\#.*$\n?', # ruby comment
114 114
115 # regular expression: There's no reason for it to start 115 # regular expression: There's no reason for it to start
116 # with a * and this stops confusion with comments. 116 # with a * and this stops confusion with comments.
117 r'/(?!\*)(\\\\|\\/|[^/])*/', 117 r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/',
118 118
119 # / is safe now that we've handled regex and javadoc comments 119 # / is safe now that we've handled regex and javadoc comments
120 r'/', 120 r'/',
121 )) + r')+', Other), 121 )) + r')+', Other),
122 122
145 (r'(' + r'|'.join(( # keep host code in largest possible chunks 145 (r'(' + r'|'.join(( # keep host code in largest possible chunks
146 r'[^%\'"/#]+', # exclude unsafe characters 146 r'[^%\'"/#]+', # exclude unsafe characters
147 r'%(?=[^%]|$)', # a single % sign is okay, just not 2 of them 147 r'%(?=[^%]|$)', # a single % sign is okay, just not 2 of them
148 148
149 # strings and comments may safely contain unsafe characters 149 # strings and comments may safely contain unsafe characters
150 r'"(\\\\|\\"|[^"])*"', # double quote string 150 r'"(\\\\|\\[^\\]|[^"\\])*"',
151 r"'(\\\\|\\'|[^'])*'", # single quote string 151 r"'(\\\\|\\[^\\]|[^'\\])*'",
152 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment 152 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
153 r'//.*$\n?', # single line comment 153 r'//.*$\n?', # single line comment
154 r'\#.*$\n?', # ruby/ragel comment 154 r'\#.*$\n?', # ruby/ragel comment
155 r'/(?!\*)(\\\\|\\/|[^/])*/', # regular expression 155 r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/', # regular expression
156 156
157 # / is safe now that we've handled regex and javadoc comments 157 # / is safe now that we've handled regex and javadoc comments
158 r'/', 158 r'/',
159 )) + r')+', Other), 159 )) + r')+', Other),
160 160
180 # (ragel EOF actions) 180 # (ragel EOF actions)
181 r'(>|\$|%|<|@|<>)/', 181 r'(>|\$|%|<|@|<>)/',
182 182
183 # specifically allow regex followed immediately by * 183 # specifically allow regex followed immediately by *
184 # so it doesn't get mistaken for a comment 184 # so it doesn't get mistaken for a comment
185 r'/(?!\*)(\\\\|\\/|[^/])*/\*', 185 r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/\*',
186 186
187 # allow / as long as it's not followed by another / or by a * 187 # allow / as long as it's not followed by another / or by a *
188 r'/(?=[^/*]|$)', 188 r'/(?=[^/*]|$)',
189 189
190 # We want to match as many of these as we can in one block. 190 # We want to match as many of these as we can in one block.
191 # Not sure if we need the + sign here, 191 # Not sure if we need the + sign here,
192 # does it help performance? 192 # does it help performance?
193 )) + r')+', 193 )) + r')+',
194 194
195 # strings and comments may safely contain unsafe characters 195 # strings and comments may safely contain unsafe characters
196 r'"(\\\\|\\"|[^"])*"', # double quote string 196 r'"(\\\\|\\[^\\]|[^"\\])*"',
197 r"'(\\\\|\\'|[^'])*'", # single quote string 197 r"'(\\\\|\\[^\\]|[^'\\])*'",
198 r"\[(\\\\|\\\]|[^\]])*\]", # square bracket literal 198 r"\[(\\\\|\\[^\\]|[^\]\\])*\]", # square bracket literal
199 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment 199 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
200 r'//.*$\n?', # single line comment 200 r'//.*$\n?', # single line comment
201 r'\#.*$\n?', # ruby/ragel comment 201 r'\#.*$\n?', # ruby/ragel comment
202 )) + r')+', using(RagelLexer)), 202 )) + r')+', using(RagelLexer)),
203 203
414 # These might need to go in a separate 'block' state triggered by ( 414 # These might need to go in a separate 'block' state triggered by (
415 (r'options\b', Keyword, 'options'), 415 (r'options\b', Keyword, 'options'),
416 (r':', Punctuation), 416 (r':', Punctuation),
417 417
418 # literals 418 # literals
419 (r"'(\\\\|\\'|[^'])*'", String), 419 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
420 (r'"(\\\\|\\"|[^"])*"', String), 420 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
421 (r'<<([^>]|>[^>])>>', String), 421 (r'<<([^>]|>[^>])>>', String),
422 # identifiers 422 # identifiers
423 # Tokens start with capital letter. 423 # Tokens start with capital letter.
424 (r'\$?[A-Z_]\w*', Name.Constant), 424 (r'\$?[A-Z_]\w*', Name.Constant),
425 # Rules start with small letter. 425 # Rules start with small letter.
454 'action': [ 454 'action': [
455 (r'(' + r'|'.join(( # keep host code in largest possible chunks 455 (r'(' + r'|'.join(( # keep host code in largest possible chunks
456 r'[^${}\'"/\\]+', # exclude unsafe characters 456 r'[^${}\'"/\\]+', # exclude unsafe characters
457 457
458 # strings and comments may safely contain unsafe characters 458 # strings and comments may safely contain unsafe characters
459 r'"(\\\\|\\"|[^"])*"', # double quote string 459 r'"(\\\\|\\[^\\]|[^"\\])*"',
460 r"'(\\\\|\\'|[^'])*'", # single quote string 460 r"'(\\\\|\\[^\\]|[^'\\])*'",
461 r'//.*$\n?', # single line comment 461 r'//.*$\n?', # single line comment
462 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment 462 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
463 463
464 # regular expression: There's no reason for it to start 464 # regular expression: There's no reason for it to start
465 # with a * and this stops confusion with comments. 465 # with a * and this stops confusion with comments.
466 r'/(?!\*)(\\\\|\\/|[^/])*/', 466 r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/',
467 467
468 # backslashes are okay, as long as we are not backslashing a % 468 # backslashes are okay, as long as we are not backslashing a %
469 r'\\(?!%)', 469 r'\\(?!%)',
470 470
471 # Now that we've handled regex and javadoc comments 471 # Now that we've handled regex and javadoc comments
481 'nested-arg-action': [ 481 'nested-arg-action': [
482 (r'(' + r'|'.join(( # keep host code in largest possible chunks. 482 (r'(' + r'|'.join(( # keep host code in largest possible chunks.
483 r'[^$\[\]\'"/]+', # exclude unsafe characters 483 r'[^$\[\]\'"/]+', # exclude unsafe characters
484 484
485 # strings and comments may safely contain unsafe characters 485 # strings and comments may safely contain unsafe characters
486 r'"(\\\\|\\"|[^"])*"', # double quote string 486 r'"(\\\\|\\[^\\]|[^"\\])*"',
487 r"'(\\\\|\\'|[^'])*'", # single quote string 487 r"'(\\\\|\\[^\\]|[^'\\])*'",
488 r'//.*$\n?', # single line comment 488 r'//.*$\n?', # single line comment
489 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment 489 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
490 490
491 # regular expression: There's no reason for it to start 491 # regular expression: There's no reason for it to start
492 # with a * and this stops confusion with comments. 492 # with a * and this stops confusion with comments.
493 r'/(?!\*)(\\\\|\\/|[^/])*/', 493 r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/',
494 494
495 # Now that we've handled regex and javadoc comments 495 # Now that we've handled regex and javadoc comments
496 # it's safe to let / through. 496 # it's safe to let / through.
497 r'/', 497 r'/',
498 )) + r')+', Other), 498 )) + r')+', Other),
699 (r'[A-Z]\w*(?:::[A-Z]\w*)*', Name.Class, '#pop'), 699 (r'[A-Z]\w*(?:::[A-Z]\w*)*', Name.Class, '#pop'),
700 ], 700 ],
701 'rule': [ 701 'rule': [
702 include('space'), 702 include('space'),
703 include('end'), 703 include('end'),
704 (r'"(\\\\|\\"|[^"])*"', String.Double), 704 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
705 (r"'(\\\\|\\'|[^'])*'", String.Single), 705 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
706 (r'([A-Za-z_]\w*)(:)', bygroups(Name.Label, Punctuation)), 706 (r'([A-Za-z_]\w*)(:)', bygroups(Name.Label, Punctuation)),
707 (r'[A-Za-z_]\w*', Name), 707 (r'[A-Za-z_]\w*', Name),
708 (r'[()]', Punctuation), 708 (r'[()]', Punctuation),
709 (r'[?+*/&!~]', Operator), 709 (r'[?+*/&!~]', Operator),
710 (r'\[(?:\\.|\[:\^?[a-z]+:\]|[^\\\]])+\]', String.Regex), 710 (r'\[(?:\\.|\[:\^?[a-z]+:\]|[^\\\]])+\]', String.Regex),

eric ide

mercurial