comparison MoinMoin/support/pygments/lexers/parsers.py @ 6097:815981fad7fd

upgrade pygments from 1.6 to 2.1.3
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 05 Sep 2016 23:55:33 +0200
parents b48a69886ca4
children
comparison
equal deleted inserted replaced
6096:86a41c2bedec 6097:815981fad7fd
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-2013 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2015 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
14 from pygments.lexer import RegexLexer, DelegatingLexer, \ 14 from pygments.lexer import RegexLexer, DelegatingLexer, \
15 include, bygroups, using 15 include, bygroups, using
16 from pygments.token import Punctuation, Other, Text, Comment, Operator, \ 16 from pygments.token import Punctuation, Other, Text, Comment, Operator, \
17 Keyword, Name, String, Number, Whitespace 17 Keyword, Name, String, Number, Whitespace
18 from pygments.lexers.compiled import JavaLexer, CLexer, CppLexer, \ 18 from pygments.lexers.jvm import JavaLexer
19 ObjectiveCLexer, DLexer 19 from pygments.lexers.c_cpp import CLexer, CppLexer
20 from pygments.lexers.objective import ObjectiveCLexer
21 from pygments.lexers.d import DLexer
20 from pygments.lexers.dotnet import CSharpLexer 22 from pygments.lexers.dotnet import CSharpLexer
21 from pygments.lexers.agile import RubyLexer, PythonLexer, PerlLexer 23 from pygments.lexers.ruby import RubyLexer
22 from pygments.lexers.web import ActionScriptLexer 24 from pygments.lexers.python import PythonLexer
23 25 from pygments.lexers.perl import PerlLexer
24 26
25 __all__ = ['RagelLexer', 'RagelEmbeddedLexer', 'RagelCLexer', 'RagelDLexer', 27 __all__ = ['RagelLexer', 'RagelEmbeddedLexer', 'RagelCLexer', 'RagelDLexer',
26 'RagelCppLexer', 'RagelObjectiveCLexer', 'RagelRubyLexer', 28 'RagelCppLexer', 'RagelObjectiveCLexer', 'RagelRubyLexer',
27 'RagelJavaLexer', 'AntlrLexer', 'AntlrPythonLexer', 29 'RagelJavaLexer', 'AntlrLexer', 'AntlrPythonLexer',
28 'AntlrPerlLexer', 'AntlrRubyLexer', 'AntlrCppLexer', 30 'AntlrPerlLexer', 'AntlrRubyLexer', 'AntlrCppLexer',
29 #'AntlrCLexer', 31 # 'AntlrCLexer',
30 'AntlrCSharpLexer', 'AntlrObjectiveCLexer', 32 'AntlrCSharpLexer', 'AntlrObjectiveCLexer',
31 'AntlrJavaLexer', "AntlrActionScriptLexer", 33 'AntlrJavaLexer', 'AntlrActionScriptLexer',
32 'TreetopLexer'] 34 'TreetopLexer', 'EbnfLexer']
33 35
34 36
35 class RagelLexer(RegexLexer): 37 class RagelLexer(RegexLexer):
36 """ 38 """
37 A pure `Ragel <http://www.complang.org/ragel/>`_ lexer. Use this for 39 A pure `Ragel <http://www.complang.org/ragel/>`_ lexer. Use this for
38 fragments of Ragel. For ``.rl`` files, use RagelEmbeddedLexer instead 40 fragments of Ragel. For ``.rl`` files, use RagelEmbeddedLexer instead
39 (or one of the language-specific subclasses). 41 (or one of the language-specific subclasses).
40 42
41 *New in Pygments 1.1.* 43 .. versionadded:: 1.1
42 """ 44 """
43 45
44 name = 'Ragel' 46 name = 'Ragel'
45 aliases = ['ragel'] 47 aliases = ['ragel']
46 filenames = [] 48 filenames = []
61 'numbers': [ 63 'numbers': [
62 (r'0x[0-9A-Fa-f]+', Number.Hex), 64 (r'0x[0-9A-Fa-f]+', Number.Hex),
63 (r'[+-]?[0-9]+', Number.Integer), 65 (r'[+-]?[0-9]+', Number.Integer),
64 ], 66 ],
65 'literals': [ 67 'literals': [
66 (r'"(\\\\|\\"|[^"])*"', String), # double quote string 68 (r'"(\\\\|\\"|[^"])*"', String), # double quote string
67 (r"'(\\\\|\\'|[^'])*'", String), # single quote string 69 (r"'(\\\\|\\'|[^'])*'", String), # single quote string
68 (r'\[(\\\\|\\\]|[^\]])*\]', String), # square bracket literals 70 (r'\[(\\\\|\\\]|[^\]])*\]', String), # square bracket literals
69 (r'/(?!\*)(\\\\|\\/|[^/])*/', String.Regex), # regular expressions 71 (r'/(?!\*)(\\\\|\\/|[^/])*/', String.Regex), # regular expressions
70 ], 72 ],
71 'identifiers': [ 73 'identifiers': [
72 (r'[a-zA-Z_][a-zA-Z_0-9]*', Name.Variable), 74 (r'[a-zA-Z_]\w*', Name.Variable),
73 ], 75 ],
74 'operators': [ 76 'operators': [
75 (r',', Operator), # Join 77 (r',', Operator), # Join
76 (r'\||&|--?', Operator), # Union, Intersection and Subtraction 78 (r'\||&|--?', Operator), # Union, Intersection and Subtraction
77 (r'\.|<:|:>>?', Operator), # Concatention 79 (r'\.|<:|:>>?', Operator), # Concatention
78 (r':', Operator), # Label 80 (r':', Operator), # Label
79 (r'->', Operator), # Epsilon Transition 81 (r'->', Operator), # Epsilon Transition
80 (r'(>|\$|%|<|@|<>)(/|eof\b)', Operator), # EOF Actions 82 (r'(>|\$|%|<|@|<>)(/|eof\b)', Operator), # EOF Actions
81 (r'(>|\$|%|<|@|<>)(!|err\b)', Operator), # Global Error Actions 83 (r'(>|\$|%|<|@|<>)(!|err\b)', Operator), # Global Error Actions
82 (r'(>|\$|%|<|@|<>)(\^|lerr\b)', Operator), # Local Error Actions 84 (r'(>|\$|%|<|@|<>)(\^|lerr\b)', Operator), # Local Error Actions
83 (r'(>|\$|%|<|@|<>)(~|to\b)', Operator), # To-State Actions 85 (r'(>|\$|%|<|@|<>)(~|to\b)', Operator), # To-State Actions
84 (r'(>|\$|%|<|@|<>)(\*|from\b)', Operator), # From-State Actions 86 (r'(>|\$|%|<|@|<>)(\*|from\b)', Operator), # From-State Actions
85 (r'>|@|\$|%', Operator), # Transition Actions and Priorities 87 (r'>|@|\$|%', Operator), # Transition Actions and Priorities
86 (r'\*|\?|\+|{[0-9]*,[0-9]*}', Operator), # Repetition 88 (r'\*|\?|\+|\{[0-9]*,[0-9]*\}', Operator), # Repetition
87 (r'!|\^', Operator), # Negation 89 (r'!|\^', Operator), # Negation
88 (r'\(|\)', Operator), # Grouping 90 (r'\(|\)', Operator), # Grouping
89 ], 91 ],
90 'root': [ 92 'root': [
91 include('literals'), 93 include('literals'),
92 include('whitespace'), 94 include('whitespace'),
93 include('comments'), 95 include('comments'),
94 include('keywords'), 96 include('keywords'),
95 include('numbers'), 97 include('numbers'),
96 include('identifiers'), 98 include('identifiers'),
97 include('operators'), 99 include('operators'),
98 (r'{', Punctuation, 'host'), 100 (r'\{', Punctuation, 'host'),
99 (r'=', Operator), 101 (r'=', Operator),
100 (r';', Punctuation), 102 (r';', Punctuation),
101 ], 103 ],
102 'host': [ 104 'host': [
103 (r'(' + r'|'.join(( # keep host code in largest possible chunks 105 (r'(' + r'|'.join(( # keep host code in largest possible chunks
104 r'[^{}\'"/#]+', # exclude unsafe characters 106 r'[^{}\'"/#]+', # exclude unsafe characters
105 r'[^\\][\\][{}]', # allow escaped { or } 107 r'[^\\]\\[{}]', # allow escaped { or }
106 108
107 # strings and comments may safely contain unsafe characters 109 # strings and comments may safely contain unsafe characters
108 r'"(\\\\|\\"|[^"])*"', # double quote string 110 r'"(\\\\|\\"|[^"])*"', # double quote string
109 r"'(\\\\|\\'|[^'])*'", # single quote string 111 r"'(\\\\|\\'|[^'])*'", # single quote string
110 r'//.*$\n?', # single line comment 112 r'//.*$\n?', # single line comment
111 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment 113 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
112 r'\#.*$\n?', # ruby comment 114 r'\#.*$\n?', # ruby comment
113 115
114 # regular expression: There's no reason for it to start 116 # regular expression: There's no reason for it to start
115 # with a * and this stops confusion with comments. 117 # with a * and this stops confusion with comments.
116 r'/(?!\*)(\\\\|\\/|[^/])*/', 118 r'/(?!\*)(\\\\|\\/|[^/])*/',
117 119
118 # / is safe now that we've handled regex and javadoc comments 120 # / is safe now that we've handled regex and javadoc comments
119 r'/', 121 r'/',
120 )) + r')+', Other), 122 )) + r')+', Other),
121 123
122 (r'{', Punctuation, '#push'), 124 (r'\{', Punctuation, '#push'),
123 (r'}', Punctuation, '#pop'), 125 (r'\}', Punctuation, '#pop'),
124 ], 126 ],
125 } 127 }
126 128
127 129
128 class RagelEmbeddedLexer(RegexLexer): 130 class RagelEmbeddedLexer(RegexLexer):
130 A lexer for `Ragel`_ embedded in a host language file. 132 A lexer for `Ragel`_ embedded in a host language file.
131 133
132 This will only highlight Ragel statements. If you want host language 134 This will only highlight Ragel statements. If you want host language
133 highlighting then call the language-specific Ragel lexer. 135 highlighting then call the language-specific Ragel lexer.
134 136
135 *New in Pygments 1.1.* 137 .. versionadded:: 1.1
136 """ 138 """
137 139
138 name = 'Embedded Ragel' 140 name = 'Embedded Ragel'
139 aliases = ['ragel-em'] 141 aliases = ['ragel-em']
140 filenames = ['*.rl'] 142 filenames = ['*.rl']
141 143
142 tokens = { 144 tokens = {
143 'root': [ 145 'root': [
144 (r'(' + r'|'.join(( # keep host code in largest possible chunks 146 (r'(' + r'|'.join(( # keep host code in largest possible chunks
145 r'[^%\'"/#]+', # exclude unsafe characters 147 r'[^%\'"/#]+', # exclude unsafe characters
146 r'%(?=[^%]|$)', # a single % sign is okay, just not 2 of them 148 r'%(?=[^%]|$)', # a single % sign is okay, just not 2 of them
147 149
148 # strings and comments may safely contain unsafe characters 150 # strings and comments may safely contain unsafe characters
149 r'"(\\\\|\\"|[^"])*"', # double quote string 151 r'"(\\\\|\\"|[^"])*"', # double quote string
150 r"'(\\\\|\\'|[^'])*'", # single quote string 152 r"'(\\\\|\\'|[^'])*'", # single quote string
151 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment 153 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
152 r'//.*$\n?', # single line comment 154 r'//.*$\n?', # single line comment
153 r'\#.*$\n?', # ruby/ragel comment 155 r'\#.*$\n?', # ruby/ragel comment
154 r'/(?!\*)(\\\\|\\/|[^/])*/', # regular expression 156 r'/(?!\*)(\\\\|\\/|[^/])*/', # regular expression
155 157
156 # / is safe now that we've handled regex and javadoc comments 158 # / is safe now that we've handled regex and javadoc comments
157 r'/', 159 r'/',
158 )) + r')+', Other), 160 )) + r')+', Other),
159 161
163 (r'(%%)(?![{%])(.*)($|;)(\n?)', bygroups(Punctuation, 165 (r'(%%)(?![{%])(.*)($|;)(\n?)', bygroups(Punctuation,
164 using(RagelLexer), 166 using(RagelLexer),
165 Punctuation, Text)), 167 Punctuation, Text)),
166 168
167 # Multi Line FSM. 169 # Multi Line FSM.
168 (r'(%%%%|%%){', Punctuation, 'multi-line-fsm'), 170 (r'(%%%%|%%)\{', Punctuation, 'multi-line-fsm'),
169 ], 171 ],
170 'multi-line-fsm': [ 172 'multi-line-fsm': [
171 (r'(' + r'|'.join(( # keep ragel code in largest possible chunks. 173 (r'(' + r'|'.join(( # keep ragel code in largest possible chunks.
172 r'(' + r'|'.join(( 174 r'(' + r'|'.join((
173 r'[^}\'"\[/#]', # exclude unsafe characters 175 r'[^}\'"\[/#]', # exclude unsafe characters
174 r'}(?=[^%]|$)', # } is okay as long as it's not followed by % 176 r'\}(?=[^%]|$)', # } is okay as long as it's not followed by %
175 r'}%(?=[^%]|$)', # ...well, one %'s okay, just not two... 177 r'\}%(?=[^%]|$)', # ...well, one %'s okay, just not two...
176 r'[^\\][\\][{}]', # ...and } is okay if it's escaped 178 r'[^\\]\\[{}]', # ...and } is okay if it's escaped
177 179
178 # allow / if it's preceded with one of these symbols 180 # allow / if it's preceded with one of these symbols
179 # (ragel EOF actions) 181 # (ragel EOF actions)
180 r'(>|\$|%|<|@|<>)/', 182 r'(>|\$|%|<|@|<>)/',
181 183
182 # specifically allow regex followed immediately by * 184 # specifically allow regex followed immediately by *
183 # so it doesn't get mistaken for a comment 185 # so it doesn't get mistaken for a comment
184 r'/(?!\*)(\\\\|\\/|[^/])*/\*', 186 r'/(?!\*)(\\\\|\\/|[^/])*/\*',
185 187
186 # allow / as long as it's not followed by another / or by a * 188 # allow / as long as it's not followed by another / or by a *
187 r'/(?=[^/\*]|$)', 189 r'/(?=[^/*]|$)',
188 190
189 # We want to match as many of these as we can in one block. 191 # We want to match as many of these as we can in one block.
190 # Not sure if we need the + sign here, 192 # Not sure if we need the + sign here,
191 # does it help performance? 193 # does it help performance?
192 )) + r')+', 194 )) + r')+',
193 195
194 # strings and comments may safely contain unsafe characters 196 # strings and comments may safely contain unsafe characters
195 r'"(\\\\|\\"|[^"])*"', # double quote string 197 r'"(\\\\|\\"|[^"])*"', # double quote string
196 r"'(\\\\|\\'|[^'])*'", # single quote string 198 r"'(\\\\|\\'|[^'])*'", # single quote string
197 r"\[(\\\\|\\\]|[^\]])*\]", # square bracket literal 199 r"\[(\\\\|\\\]|[^\]])*\]", # square bracket literal
198 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment 200 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
199 r'//.*$\n?', # single line comment 201 r'//.*$\n?', # single line comment
200 r'\#.*$\n?', # ruby/ragel comment 202 r'\#.*$\n?', # ruby/ragel comment
201 )) + r')+', using(RagelLexer)), 203 )) + r')+', using(RagelLexer)),
202 204
203 (r'}%%', Punctuation, '#pop'), 205 (r'\}%%', Punctuation, '#pop'),
204 ] 206 ]
205 } 207 }
206 208
207 def analyse_text(text): 209 def analyse_text(text):
208 return '@LANG: indep' in text or 0.1 210 return '@LANG: indep' in text
209 211
210 212
211 class RagelRubyLexer(DelegatingLexer): 213 class RagelRubyLexer(DelegatingLexer):
212 """ 214 """
213 A lexer for `Ragel`_ in a Ruby host file. 215 A lexer for `Ragel`_ in a Ruby host file.
214 216
215 *New in Pygments 1.1.* 217 .. versionadded:: 1.1
216 """ 218 """
217 219
218 name = 'Ragel in Ruby Host' 220 name = 'Ragel in Ruby Host'
219 aliases = ['ragel-ruby', 'ragel-rb'] 221 aliases = ['ragel-ruby', 'ragel-rb']
220 filenames = ['*.rl'] 222 filenames = ['*.rl']
221 223
222 def __init__(self, **options): 224 def __init__(self, **options):
223 super(RagelRubyLexer, self).__init__(RubyLexer, RagelEmbeddedLexer, 225 super(RagelRubyLexer, self).__init__(RubyLexer, RagelEmbeddedLexer,
224 **options) 226 **options)
225 227
226 def analyse_text(text): 228 def analyse_text(text):
227 return '@LANG: ruby' in text 229 return '@LANG: ruby' in text
228 230
229 231
230 class RagelCLexer(DelegatingLexer): 232 class RagelCLexer(DelegatingLexer):
231 """ 233 """
232 A lexer for `Ragel`_ in a C host file. 234 A lexer for `Ragel`_ in a C host file.
233 235
234 *New in Pygments 1.1.* 236 .. versionadded:: 1.1
235 """ 237 """
236 238
237 name = 'Ragel in C Host' 239 name = 'Ragel in C Host'
238 aliases = ['ragel-c'] 240 aliases = ['ragel-c']
239 filenames = ['*.rl'] 241 filenames = ['*.rl']
248 250
249 class RagelDLexer(DelegatingLexer): 251 class RagelDLexer(DelegatingLexer):
250 """ 252 """
251 A lexer for `Ragel`_ in a D host file. 253 A lexer for `Ragel`_ in a D host file.
252 254
253 *New in Pygments 1.1.* 255 .. versionadded:: 1.1
254 """ 256 """
255 257
256 name = 'Ragel in D Host' 258 name = 'Ragel in D Host'
257 aliases = ['ragel-d'] 259 aliases = ['ragel-d']
258 filenames = ['*.rl'] 260 filenames = ['*.rl']
266 268
267 class RagelCppLexer(DelegatingLexer): 269 class RagelCppLexer(DelegatingLexer):
268 """ 270 """
269 A lexer for `Ragel`_ in a CPP host file. 271 A lexer for `Ragel`_ in a CPP host file.
270 272
271 *New in Pygments 1.1.* 273 .. versionadded:: 1.1
272 """ 274 """
273 275
274 name = 'Ragel in CPP Host' 276 name = 'Ragel in CPP Host'
275 aliases = ['ragel-cpp'] 277 aliases = ['ragel-cpp']
276 filenames = ['*.rl'] 278 filenames = ['*.rl']
284 286
285 class RagelObjectiveCLexer(DelegatingLexer): 287 class RagelObjectiveCLexer(DelegatingLexer):
286 """ 288 """
287 A lexer for `Ragel`_ in an Objective C host file. 289 A lexer for `Ragel`_ in an Objective C host file.
288 290
289 *New in Pygments 1.1.* 291 .. versionadded:: 1.1
290 """ 292 """
291 293
292 name = 'Ragel in Objective C Host' 294 name = 'Ragel in Objective C Host'
293 aliases = ['ragel-objc'] 295 aliases = ['ragel-objc']
294 filenames = ['*.rl'] 296 filenames = ['*.rl']
304 306
305 class RagelJavaLexer(DelegatingLexer): 307 class RagelJavaLexer(DelegatingLexer):
306 """ 308 """
307 A lexer for `Ragel`_ in a Java host file. 309 A lexer for `Ragel`_ in a Java host file.
308 310
309 *New in Pygments 1.1.* 311 .. versionadded:: 1.1
310 """ 312 """
311 313
312 name = 'Ragel in Java Host' 314 name = 'Ragel in Java Host'
313 aliases = ['ragel-java'] 315 aliases = ['ragel-java']
314 filenames = ['*.rl'] 316 filenames = ['*.rl']
325 """ 327 """
326 Generic `ANTLR`_ Lexer. 328 Generic `ANTLR`_ Lexer.
327 Should not be called directly, instead 329 Should not be called directly, instead
328 use DelegatingLexer for your target language. 330 use DelegatingLexer for your target language.
329 331
330 *New in Pygments 1.1.* 332 .. versionadded:: 1.1
331 333
332 .. _ANTLR: http://www.antlr.org/ 334 .. _ANTLR: http://www.antlr.org/
333 """ 335 """
334 336
335 name = 'ANTLR' 337 name = 'ANTLR'
336 aliases = ['antlr'] 338 aliases = ['antlr']
337 filenames = [] 339 filenames = []
338 340
339 _id = r'[A-Za-z][A-Za-z_0-9]*' 341 _id = r'[A-Za-z]\w*'
340 _TOKEN_REF = r'[A-Z][A-Za-z_0-9]*' 342 _TOKEN_REF = r'[A-Z]\w*'
341 _RULE_REF = r'[a-z][A-Za-z_0-9]*' 343 _RULE_REF = r'[a-z]\w*'
342 _STRING_LITERAL = r'\'(?:\\\\|\\\'|[^\']*)\'' 344 _STRING_LITERAL = r'\'(?:\\\\|\\\'|[^\']*)\''
343 _INT = r'[0-9]+' 345 _INT = r'[0-9]+'
344 346
345 tokens = { 347 tokens = {
346 'whitespace': [ 348 'whitespace': [
360 # optionsSpec 362 # optionsSpec
361 (r'options\b', Keyword, 'options'), 363 (r'options\b', Keyword, 'options'),
362 # tokensSpec 364 # tokensSpec
363 (r'tokens\b', Keyword, 'tokens'), 365 (r'tokens\b', Keyword, 'tokens'),
364 # attrScope 366 # attrScope
365 (r'(scope)(\s*)(' + _id + ')(\s*)({)', 367 (r'(scope)(\s*)(' + _id + ')(\s*)(\{)',
366 bygroups(Keyword, Whitespace, Name.Variable, Whitespace, 368 bygroups(Keyword, Whitespace, Name.Variable, Whitespace,
367 Punctuation), 'action'), 369 Punctuation), 'action'),
368 # exception 370 # exception
369 (r'(catch|finally)\b', Keyword, 'exception'), 371 (r'(catch|finally)\b', Keyword, 'exception'),
370 # action 372 # action
371 (r'(@' + _id + ')(\s*)(::)?(\s*)(' + _id + ')(\s*)({)', 373 (r'(@' + _id + ')(\s*)(::)?(\s*)(' + _id + ')(\s*)(\{)',
372 bygroups(Name.Label, Whitespace, Punctuation, Whitespace, 374 bygroups(Name.Label, Whitespace, Punctuation, Whitespace,
373 Name.Label, Whitespace, Punctuation), 'action'), 375 Name.Label, Whitespace, Punctuation), 'action'),
374 # rule 376 # rule
375 (r'((?:protected|private|public|fragment)\b)?(\s*)(' + _id + ')(!)?', \ 377 (r'((?:protected|private|public|fragment)\b)?(\s*)(' + _id + ')(!)?',
376 bygroups(Keyword, Whitespace, Name.Label, Punctuation), 378 bygroups(Keyword, Whitespace, Name.Label, Punctuation),
377 ('rule-alts', 'rule-prelims')), 379 ('rule-alts', 'rule-prelims')),
378 ], 380 ],
379 'exception': [ 381 'exception': [
380 (r'\n', Whitespace, '#pop'), 382 (r'\n', Whitespace, '#pop'),
393 (r'\{', Punctuation, 'action'), 395 (r'\{', Punctuation, 'action'),
394 # throwsSpec 396 # throwsSpec
395 (r'(throws)(\s+)(' + _id + ')', 397 (r'(throws)(\s+)(' + _id + ')',
396 bygroups(Keyword, Whitespace, Name.Label)), 398 bygroups(Keyword, Whitespace, Name.Label)),
397 (r'(,)(\s*)(' + _id + ')', 399 (r'(,)(\s*)(' + _id + ')',
398 bygroups(Punctuation, Whitespace, Name.Label)), # Additional throws 400 bygroups(Punctuation, Whitespace, Name.Label)), # Additional throws
399 # optionsSpec 401 # optionsSpec
400 (r'options\b', Keyword, 'options'), 402 (r'options\b', Keyword, 'options'),
401 # ruleScopeSpec - scope followed by target language code or name of action 403 # ruleScopeSpec - scope followed by target language code or name of action
402 # TODO finish implementing other possibilities for scope 404 # TODO finish implementing other possibilities for scope
403 # L173 ANTLRv3.g from ANTLR book 405 # L173 ANTLRv3.g from ANTLR book
404 (r'(scope)(\s+)({)', bygroups(Keyword, Whitespace, Punctuation), 406 (r'(scope)(\s+)(\{)', bygroups(Keyword, Whitespace, Punctuation),
405 'action'), 407 'action'),
406 (r'(scope)(\s+)(' + _id + ')(\s*)(;)', 408 (r'(scope)(\s+)(' + _id + ')(\s*)(;)',
407 bygroups(Keyword, Whitespace, Name.Label, Whitespace, Punctuation)), 409 bygroups(Keyword, Whitespace, Name.Label, Whitespace, Punctuation)),
408 # ruleAction 410 # ruleAction
409 (r'(@' + _id + ')(\s*)({)', 411 (r'(@' + _id + ')(\s*)(\{)',
410 bygroups(Name.Label, Whitespace, Punctuation), 'action'), 412 bygroups(Name.Label, Whitespace, Punctuation), 'action'),
411 # finished prelims, go to rule alts! 413 # finished prelims, go to rule alts!
412 (r':', Punctuation, '#pop') 414 (r':', Punctuation, '#pop')
413 ], 415 ],
414 'rule-alts': [ 416 'rule-alts': [
423 (r"'(\\\\|\\'|[^'])*'", String), 425 (r"'(\\\\|\\'|[^'])*'", String),
424 (r'"(\\\\|\\"|[^"])*"', String), 426 (r'"(\\\\|\\"|[^"])*"', String),
425 (r'<<([^>]|>[^>])>>', String), 427 (r'<<([^>]|>[^>])>>', String),
426 # identifiers 428 # identifiers
427 # Tokens start with capital letter. 429 # Tokens start with capital letter.
428 (r'\$?[A-Z_][A-Za-z_0-9]*', Name.Constant), 430 (r'\$?[A-Z_]\w*', Name.Constant),
429 # Rules start with small letter. 431 # Rules start with small letter.
430 (r'\$?[a-z_][A-Za-z_0-9]*', Name.Variable), 432 (r'\$?[a-z_]\w*', Name.Variable),
431 # operators 433 # operators
432 (r'(\+|\||->|=>|=|\(|\)|\.\.|\.|\?|\*|\^|!|\#|~)', Operator), 434 (r'(\+|\||->|=>|=|\(|\)|\.\.|\.|\?|\*|\^|!|\#|~)', Operator),
433 (r',', Punctuation), 435 (r',', Punctuation),
434 (r'\[', Punctuation, 'nested-arg-action'), 436 (r'\[', Punctuation, 'nested-arg-action'),
435 (r'\{', Punctuation, 'action'), 437 (r'\{', Punctuation, 'action'),
436 (r';', Punctuation, '#pop') 438 (r';', Punctuation, '#pop')
437 ], 439 ],
438 'tokens': [ 440 'tokens': [
439 include('whitespace'), 441 include('whitespace'),
440 include('comments'), 442 include('comments'),
441 (r'{', Punctuation), 443 (r'\{', Punctuation),
442 (r'(' + _TOKEN_REF + r')(\s*)(=)?(\s*)(' + _STRING_LITERAL 444 (r'(' + _TOKEN_REF + r')(\s*)(=)?(\s*)(' + _STRING_LITERAL
443 + ')?(\s*)(;)', 445 + ')?(\s*)(;)',
444 bygroups(Name.Label, Whitespace, Punctuation, Whitespace, 446 bygroups(Name.Label, Whitespace, Punctuation, Whitespace,
445 String, Whitespace, Punctuation)), 447 String, Whitespace, Punctuation)),
446 (r'}', Punctuation, '#pop'), 448 (r'\}', Punctuation, '#pop'),
447 ], 449 ],
448 'options': [ 450 'options': [
449 include('whitespace'), 451 include('whitespace'),
450 include('comments'), 452 include('comments'),
451 (r'{', Punctuation), 453 (r'\{', Punctuation),
452 (r'(' + _id + r')(\s*)(=)(\s*)(' + 454 (r'(' + _id + r')(\s*)(=)(\s*)(' +
453 '|'.join((_id, _STRING_LITERAL, _INT, '\*'))+ ')(\s*)(;)', 455 '|'.join((_id, _STRING_LITERAL, _INT, '\*')) + ')(\s*)(;)',
454 bygroups(Name.Variable, Whitespace, Punctuation, Whitespace, 456 bygroups(Name.Variable, Whitespace, Punctuation, Whitespace,
455 Text, Whitespace, Punctuation)), 457 Text, Whitespace, Punctuation)),
456 (r'}', Punctuation, '#pop'), 458 (r'\}', Punctuation, '#pop'),
457 ], 459 ],
458 'action': [ 460 'action': [
459 (r'(' + r'|'.join(( # keep host code in largest possible chunks 461 (r'(' + r'|'.join(( # keep host code in largest possible chunks
460 r'[^\${}\'"/\\]+', # exclude unsafe characters 462 r'[^${}\'"/\\]+', # exclude unsafe characters
461 463
462 # strings and comments may safely contain unsafe characters 464 # strings and comments may safely contain unsafe characters
463 r'"(\\\\|\\"|[^"])*"', # double quote string 465 r'"(\\\\|\\"|[^"])*"', # double quote string
464 r"'(\\\\|\\'|[^'])*'", # single quote string 466 r"'(\\\\|\\'|[^'])*'", # single quote string
465 r'//.*$\n?', # single line comment 467 r'//.*$\n?', # single line comment
466 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment 468 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
467 469
468 # regular expression: There's no reason for it to start 470 # regular expression: There's no reason for it to start
469 # with a * and this stops confusion with comments. 471 # with a * and this stops confusion with comments.
470 r'/(?!\*)(\\\\|\\/|[^/])*/', 472 r'/(?!\*)(\\\\|\\/|[^/])*/',
471 473
477 r'/', 479 r'/',
478 )) + r')+', Other), 480 )) + r')+', Other),
479 (r'(\\)(%)', bygroups(Punctuation, Other)), 481 (r'(\\)(%)', bygroups(Punctuation, Other)),
480 (r'(\$[a-zA-Z]+)(\.?)(text|value)?', 482 (r'(\$[a-zA-Z]+)(\.?)(text|value)?',
481 bygroups(Name.Variable, Punctuation, Name.Property)), 483 bygroups(Name.Variable, Punctuation, Name.Property)),
482 (r'{', Punctuation, '#push'), 484 (r'\{', Punctuation, '#push'),
483 (r'}', Punctuation, '#pop'), 485 (r'\}', Punctuation, '#pop'),
484 ], 486 ],
485 'nested-arg-action': [ 487 'nested-arg-action': [
486 (r'(' + r'|'.join(( # keep host code in largest possible chunks. 488 (r'(' + r'|'.join(( # keep host code in largest possible chunks.
487 r'[^\$\[\]\'"/]+', # exclude unsafe characters 489 r'[^$\[\]\'"/]+', # exclude unsafe characters
488 490
489 # strings and comments may safely contain unsafe characters 491 # strings and comments may safely contain unsafe characters
490 r'"(\\\\|\\"|[^"])*"', # double quote string 492 r'"(\\\\|\\"|[^"])*"', # double quote string
491 r"'(\\\\|\\'|[^'])*'", # single quote string 493 r"'(\\\\|\\'|[^'])*'", # single quote string
492 r'//.*$\n?', # single line comment 494 r'//.*$\n?', # single line comment
493 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment 495 r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
494 496
495 # regular expression: There's no reason for it to start 497 # regular expression: There's no reason for it to start
496 # with a * and this stops confusion with comments. 498 # with a * and this stops confusion with comments.
497 r'/(?!\*)(\\\\|\\/|[^/])*/', 499 r'/(?!\*)(\\\\|\\/|[^/])*/',
498 500
518 # TH: I'm not aware of any language features of C++ that will cause 520 # TH: I'm not aware of any language features of C++ that will cause
519 # incorrect lexing of C files. Antlr doesn't appear to make a distinction, 521 # incorrect lexing of C files. Antlr doesn't appear to make a distinction,
520 # so just assume they're C++. No idea how to make Objective C work in the 522 # so just assume they're C++. No idea how to make Objective C work in the
521 # future. 523 # future.
522 524
523 #class AntlrCLexer(DelegatingLexer): 525 # class AntlrCLexer(DelegatingLexer):
524 # """ 526 # """
525 # ANTLR with C Target 527 # ANTLR with C Target
526 # 528 #
527 # *New in Pygments 1.1* 529 # .. versionadded:: 1.1
528 # """ 530 # """
529 # 531 #
530 # name = 'ANTLR With C Target' 532 # name = 'ANTLR With C Target'
531 # aliases = ['antlr-c'] 533 # aliases = ['antlr-c']
532 # filenames = ['*.G', '*.g'] 534 # filenames = ['*.G', '*.g']
535 # super(AntlrCLexer, self).__init__(CLexer, AntlrLexer, **options) 537 # super(AntlrCLexer, self).__init__(CLexer, AntlrLexer, **options)
536 # 538 #
537 # def analyse_text(text): 539 # def analyse_text(text):
538 # return re.match(r'^\s*language\s*=\s*C\s*;', text) 540 # return re.match(r'^\s*language\s*=\s*C\s*;', text)
539 541
542
540 class AntlrCppLexer(DelegatingLexer): 543 class AntlrCppLexer(DelegatingLexer):
541 """ 544 """
542 `ANTLR`_ with CPP Target 545 `ANTLR`_ with CPP Target
543 546
544 *New in Pygments 1.1.* 547 .. versionadded:: 1.1
545 """ 548 """
546 549
547 name = 'ANTLR With CPP Target' 550 name = 'ANTLR With CPP Target'
548 aliases = ['antlr-cpp'] 551 aliases = ['antlr-cpp']
549 filenames = ['*.G', '*.g'] 552 filenames = ['*.G', '*.g']
551 def __init__(self, **options): 554 def __init__(self, **options):
552 super(AntlrCppLexer, self).__init__(CppLexer, AntlrLexer, **options) 555 super(AntlrCppLexer, self).__init__(CppLexer, AntlrLexer, **options)
553 556
554 def analyse_text(text): 557 def analyse_text(text):
555 return AntlrLexer.analyse_text(text) and \ 558 return AntlrLexer.analyse_text(text) and \
556 re.search(r'^\s*language\s*=\s*C\s*;', text, re.M) 559 re.search(r'^\s*language\s*=\s*C\s*;', text, re.M)
557 560
558 561
559 class AntlrObjectiveCLexer(DelegatingLexer): 562 class AntlrObjectiveCLexer(DelegatingLexer):
560 """ 563 """
561 `ANTLR`_ with Objective-C Target 564 `ANTLR`_ with Objective-C Target
562 565
563 *New in Pygments 1.1.* 566 .. versionadded:: 1.1
564 """ 567 """
565 568
566 name = 'ANTLR With ObjectiveC Target' 569 name = 'ANTLR With ObjectiveC Target'
567 aliases = ['antlr-objc'] 570 aliases = ['antlr-objc']
568 filenames = ['*.G', '*.g'] 571 filenames = ['*.G', '*.g']
571 super(AntlrObjectiveCLexer, self).__init__(ObjectiveCLexer, 574 super(AntlrObjectiveCLexer, self).__init__(ObjectiveCLexer,
572 AntlrLexer, **options) 575 AntlrLexer, **options)
573 576
574 def analyse_text(text): 577 def analyse_text(text):
575 return AntlrLexer.analyse_text(text) and \ 578 return AntlrLexer.analyse_text(text) and \
576 re.search(r'^\s*language\s*=\s*ObjC\s*;', text) 579 re.search(r'^\s*language\s*=\s*ObjC\s*;', text)
577 580
578 581
579 class AntlrCSharpLexer(DelegatingLexer): 582 class AntlrCSharpLexer(DelegatingLexer):
580 """ 583 """
581 `ANTLR`_ with C# Target 584 `ANTLR`_ with C# Target
582 585
583 *New in Pygments 1.1.* 586 .. versionadded:: 1.1
584 """ 587 """
585 588
586 name = 'ANTLR With C# Target' 589 name = 'ANTLR With C# Target'
587 aliases = ['antlr-csharp', 'antlr-c#'] 590 aliases = ['antlr-csharp', 'antlr-c#']
588 filenames = ['*.G', '*.g'] 591 filenames = ['*.G', '*.g']
591 super(AntlrCSharpLexer, self).__init__(CSharpLexer, AntlrLexer, 594 super(AntlrCSharpLexer, self).__init__(CSharpLexer, AntlrLexer,
592 **options) 595 **options)
593 596
594 def analyse_text(text): 597 def analyse_text(text):
595 return AntlrLexer.analyse_text(text) and \ 598 return AntlrLexer.analyse_text(text) and \
596 re.search(r'^\s*language\s*=\s*CSharp2\s*;', text, re.M) 599 re.search(r'^\s*language\s*=\s*CSharp2\s*;', text, re.M)
597 600
598 601
599 class AntlrPythonLexer(DelegatingLexer): 602 class AntlrPythonLexer(DelegatingLexer):
600 """ 603 """
601 `ANTLR`_ with Python Target 604 `ANTLR`_ with Python Target
602 605
603 *New in Pygments 1.1.* 606 .. versionadded:: 1.1
604 """ 607 """
605 608
606 name = 'ANTLR With Python Target' 609 name = 'ANTLR With Python Target'
607 aliases = ['antlr-python'] 610 aliases = ['antlr-python']
608 filenames = ['*.G', '*.g'] 611 filenames = ['*.G', '*.g']
611 super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, 614 super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer,
612 **options) 615 **options)
613 616
614 def analyse_text(text): 617 def analyse_text(text):
615 return AntlrLexer.analyse_text(text) and \ 618 return AntlrLexer.analyse_text(text) and \
616 re.search(r'^\s*language\s*=\s*Python\s*;', text, re.M) 619 re.search(r'^\s*language\s*=\s*Python\s*;', text, re.M)
617 620
618 621
619 class AntlrJavaLexer(DelegatingLexer): 622 class AntlrJavaLexer(DelegatingLexer):
620 """ 623 """
621 `ANTLR`_ with Java Target 624 `ANTLR`_ with Java Target
622 625
623 *New in Pygments 1.1* 626 .. versionadded:: 1.
624 """ 627 """
625 628
626 name = 'ANTLR With Java Target' 629 name = 'ANTLR With Java Target'
627 aliases = ['antlr-java'] 630 aliases = ['antlr-java']
628 filenames = ['*.G', '*.g'] 631 filenames = ['*.G', '*.g']
638 641
639 class AntlrRubyLexer(DelegatingLexer): 642 class AntlrRubyLexer(DelegatingLexer):
640 """ 643 """
641 `ANTLR`_ with Ruby Target 644 `ANTLR`_ with Ruby Target
642 645
643 *New in Pygments 1.1.* 646 .. versionadded:: 1.1
644 """ 647 """
645 648
646 name = 'ANTLR With Ruby Target' 649 name = 'ANTLR With Ruby Target'
647 aliases = ['antlr-ruby', 'antlr-rb'] 650 aliases = ['antlr-ruby', 'antlr-rb']
648 filenames = ['*.G', '*.g'] 651 filenames = ['*.G', '*.g']
651 super(AntlrRubyLexer, self).__init__(RubyLexer, AntlrLexer, 654 super(AntlrRubyLexer, self).__init__(RubyLexer, AntlrLexer,
652 **options) 655 **options)
653 656
654 def analyse_text(text): 657 def analyse_text(text):
655 return AntlrLexer.analyse_text(text) and \ 658 return AntlrLexer.analyse_text(text) and \
656 re.search(r'^\s*language\s*=\s*Ruby\s*;', text, re.M) 659 re.search(r'^\s*language\s*=\s*Ruby\s*;', text, re.M)
657 660
658 661
659 class AntlrPerlLexer(DelegatingLexer): 662 class AntlrPerlLexer(DelegatingLexer):
660 """ 663 """
661 `ANTLR`_ with Perl Target 664 `ANTLR`_ with Perl Target
662 665
663 *New in Pygments 1.1.* 666 .. versionadded:: 1.1
664 """ 667 """
665 668
666 name = 'ANTLR With Perl Target' 669 name = 'ANTLR With Perl Target'
667 aliases = ['antlr-perl'] 670 aliases = ['antlr-perl']
668 filenames = ['*.G', '*.g'] 671 filenames = ['*.G', '*.g']
671 super(AntlrPerlLexer, self).__init__(PerlLexer, AntlrLexer, 674 super(AntlrPerlLexer, self).__init__(PerlLexer, AntlrLexer,
672 **options) 675 **options)
673 676
674 def analyse_text(text): 677 def analyse_text(text):
675 return AntlrLexer.analyse_text(text) and \ 678 return AntlrLexer.analyse_text(text) and \
676 re.search(r'^\s*language\s*=\s*Perl5\s*;', text, re.M) 679 re.search(r'^\s*language\s*=\s*Perl5\s*;', text, re.M)
677 680
678 681
679 class AntlrActionScriptLexer(DelegatingLexer): 682 class AntlrActionScriptLexer(DelegatingLexer):
680 """ 683 """
681 `ANTLR`_ with ActionScript Target 684 `ANTLR`_ with ActionScript Target
682 685
683 *New in Pygments 1.1.* 686 .. versionadded:: 1.1
684 """ 687 """
685 688
686 name = 'ANTLR With ActionScript Target' 689 name = 'ANTLR With ActionScript Target'
687 aliases = ['antlr-as', 'antlr-actionscript'] 690 aliases = ['antlr-as', 'antlr-actionscript']
688 filenames = ['*.G', '*.g'] 691 filenames = ['*.G', '*.g']
689 692
690 def __init__(self, **options): 693 def __init__(self, **options):
694 from pygments.lexers.actionscript import ActionScriptLexer
691 super(AntlrActionScriptLexer, self).__init__(ActionScriptLexer, 695 super(AntlrActionScriptLexer, self).__init__(ActionScriptLexer,
692 AntlrLexer, **options) 696 AntlrLexer, **options)
693 697
694 def analyse_text(text): 698 def analyse_text(text):
695 return AntlrLexer.analyse_text(text) and \ 699 return AntlrLexer.analyse_text(text) and \
696 re.search(r'^\s*language\s*=\s*ActionScript\s*;', text, re.M) 700 re.search(r'^\s*language\s*=\s*ActionScript\s*;', text, re.M)
701
697 702
698 class TreetopBaseLexer(RegexLexer): 703 class TreetopBaseLexer(RegexLexer):
699 """ 704 """
700 A base lexer for `Treetop <http://treetop.rubyforge.org/>`_ grammars. 705 A base lexer for `Treetop <http://treetop.rubyforge.org/>`_ grammars.
701 Not for direct use; use TreetopLexer instead. 706 Not for direct use; use TreetopLexer instead.
702 707
703 *New in Pygments 1.6.* 708 .. versionadded:: 1.6
704 """ 709 """
705 710
706 tokens = { 711 tokens = {
707 'root': [ 712 'root': [
708 include('space'), 713 include('space'),
713 'module': [ 718 'module': [
714 include('space'), 719 include('space'),
715 include('end'), 720 include('end'),
716 (r'module\b', Keyword, '#push'), 721 (r'module\b', Keyword, '#push'),
717 (r'grammar\b', Keyword, 'grammar'), 722 (r'grammar\b', Keyword, 'grammar'),
718 (r'[A-Z][A-Za-z_0-9]*(?:::[A-Z][A-Za-z_0-9]*)*', Name.Namespace), 723 (r'[A-Z]\w*(?:::[A-Z]\w*)*', Name.Namespace),
719 ], 724 ],
720 'grammar': [ 725 'grammar': [
721 include('space'), 726 include('space'),
722 include('end'), 727 include('end'),
723 (r'rule\b', Keyword, 'rule'), 728 (r'rule\b', Keyword, 'rule'),
724 (r'include\b', Keyword, 'include'), 729 (r'include\b', Keyword, 'include'),
725 (r'[A-Z][A-Za-z_0-9]*', Name), 730 (r'[A-Z]\w*', Name),
726 ], 731 ],
727 'include': [ 732 'include': [
728 include('space'), 733 include('space'),
729 (r'[A-Z][A-Za-z_0-9]*(?:::[A-Z][A-Za-z_0-9]*)*', Name.Class, '#pop'), 734 (r'[A-Z]\w*(?:::[A-Z]\w*)*', Name.Class, '#pop'),
730 ], 735 ],
731 'rule': [ 736 'rule': [
732 include('space'), 737 include('space'),
733 include('end'), 738 include('end'),
734 (r'"(\\\\|\\"|[^"])*"', String.Double), 739 (r'"(\\\\|\\"|[^"])*"', String.Double),
735 (r"'(\\\\|\\'|[^'])*'", String.Single), 740 (r"'(\\\\|\\'|[^'])*'", String.Single),
736 (r'([A-Za-z_][A-Za-z_0-9]*)(:)', bygroups(Name.Label, Punctuation)), 741 (r'([A-Za-z_]\w*)(:)', bygroups(Name.Label, Punctuation)),
737 (r'[A-Za-z_][A-Za-z_0-9]*', Name), 742 (r'[A-Za-z_]\w*', Name),
738 (r'[()]', Punctuation), 743 (r'[()]', Punctuation),
739 (r'[?+*/&!~]', Operator), 744 (r'[?+*/&!~]', Operator),
740 (r'\[(?:\\.|\[:\^?[a-z]+:\]|[^\\\]])+\]', String.Regex), 745 (r'\[(?:\\.|\[:\^?[a-z]+:\]|[^\\\]])+\]', String.Regex),
741 (r'([0-9]*)(\.\.)([0-9]*)', 746 (r'([0-9]*)(\.\.)([0-9]*)',
742 bygroups(Number.Integer, Operator, Number.Integer)), 747 bygroups(Number.Integer, Operator, Number.Integer)),
743 (r'(<)([^>]+)(>)', bygroups(Punctuation, Name.Class, Punctuation)), 748 (r'(<)([^>]+)(>)', bygroups(Punctuation, Name.Class, Punctuation)),
744 (r'{', Punctuation, 'inline_module'), 749 (r'\{', Punctuation, 'inline_module'),
745 (r'\.', String.Regex), 750 (r'\.', String.Regex),
746 ], 751 ],
747 'inline_module': [ 752 'inline_module': [
748 (r'{', Other, 'ruby'), 753 (r'\{', Other, 'ruby'),
749 (r'}', Punctuation, '#pop'), 754 (r'\}', Punctuation, '#pop'),
750 (r'[^{}]+', Other), 755 (r'[^{}]+', Other),
751 ], 756 ],
752 'ruby': [ 757 'ruby': [
753 (r'{', Other, '#push'), 758 (r'\{', Other, '#push'),
754 (r'}', Other, '#pop'), 759 (r'\}', Other, '#pop'),
755 (r'[^{}]+', Other), 760 (r'[^{}]+', Other),
756 ], 761 ],
757 'space': [ 762 'space': [
758 (r'[ \t\n\r]+', Whitespace), 763 (r'[ \t\n\r]+', Whitespace),
759 (r'#[^\n]*', Comment.Single), 764 (r'#[^\n]*', Comment.Single),
761 'end': [ 766 'end': [
762 (r'end\b', Keyword, '#pop'), 767 (r'end\b', Keyword, '#pop'),
763 ], 768 ],
764 } 769 }
765 770
771
766 class TreetopLexer(DelegatingLexer): 772 class TreetopLexer(DelegatingLexer):
767 """ 773 """
768 A lexer for `Treetop <http://treetop.rubyforge.org/>`_ grammars. 774 A lexer for `Treetop <http://treetop.rubyforge.org/>`_ grammars.
769 775
770 *New in Pygments 1.6.* 776 .. versionadded:: 1.6
771 """ 777 """
772 778
773 name = 'Treetop' 779 name = 'Treetop'
774 aliases = ['treetop'] 780 aliases = ['treetop']
775 filenames = ['*.treetop', '*.tt'] 781 filenames = ['*.treetop', '*.tt']
776 782
777 def __init__(self, **options): 783 def __init__(self, **options):
778 super(TreetopLexer, self).__init__(RubyLexer, TreetopBaseLexer, **options) 784 super(TreetopLexer, self).__init__(RubyLexer, TreetopBaseLexer, **options)
785
786
787 class EbnfLexer(RegexLexer):
788 """
789 Lexer for `ISO/IEC 14977 EBNF
790 <http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form>`_
791 grammars.
792
793 .. versionadded:: 2.0
794 """
795
796 name = 'EBNF'
797 aliases = ['ebnf']
798 filenames = ['*.ebnf']
799 mimetypes = ['text/x-ebnf']
800
801 tokens = {
802 'root': [
803 include('whitespace'),
804 include('comment_start'),
805 include('identifier'),
806 (r'=', Operator, 'production'),
807 ],
808 'production': [
809 include('whitespace'),
810 include('comment_start'),
811 include('identifier'),
812 (r'"[^"]*"', String.Double),
813 (r"'[^']*'", String.Single),
814 (r'(\?[^?]*\?)', Name.Entity),
815 (r'[\[\]{}(),|]', Punctuation),
816 (r'-', Operator),
817 (r';', Punctuation, '#pop'),
818 (r'\.', Punctuation, '#pop'),
819 ],
820 'whitespace': [
821 (r'\s+', Text),
822 ],
823 'comment_start': [
824 (r'\(\*', Comment.Multiline, 'comment'),
825 ],
826 'comment': [
827 (r'[^*)]', Comment.Multiline),
828 include('comment_start'),
829 (r'\*\)', Comment.Multiline, '#pop'),
830 (r'[*)]', Comment.Multiline),
831 ],
832 'identifier': [
833 (r'([a-zA-Z][\w \-]*)', Keyword),
834 ],
835 }