pygmentize 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. data/LICENSE +19 -0
  2. data/lib/pygments.rb +23 -0
  3. data/pygmentize.gemspec +11 -0
  4. data/test/pygments.rb +19 -0
  5. data/vendor/pygmentize.py +7 -0
  6. data/vendor/pygments/AUTHORS +73 -0
  7. data/vendor/pygments/LICENSE +25 -0
  8. data/vendor/pygments/__init__.py +91 -0
  9. data/vendor/pygments/__init__.pyc +0 -0
  10. data/vendor/pygments/cmdline.py +430 -0
  11. data/vendor/pygments/cmdline.pyc +0 -0
  12. data/vendor/pygments/console.py +74 -0
  13. data/vendor/pygments/console.pyc +0 -0
  14. data/vendor/pygments/filter.py +74 -0
  15. data/vendor/pygments/filter.pyc +0 -0
  16. data/vendor/pygments/filters/__init__.py +357 -0
  17. data/vendor/pygments/filters/__init__.pyc +0 -0
  18. data/vendor/pygments/formatter.py +92 -0
  19. data/vendor/pygments/formatter.pyc +0 -0
  20. data/vendor/pygments/formatters/__init__.py +68 -0
  21. data/vendor/pygments/formatters/__init__.pyc +0 -0
  22. data/vendor/pygments/formatters/_mapping.py +92 -0
  23. data/vendor/pygments/formatters/_mapping.pyc +0 -0
  24. data/vendor/pygments/formatters/bbcode.py +109 -0
  25. data/vendor/pygments/formatters/bbcode.pyc +0 -0
  26. data/vendor/pygments/formatters/html.py +723 -0
  27. data/vendor/pygments/formatters/html.pyc +0 -0
  28. data/vendor/pygments/formatters/img.py +553 -0
  29. data/vendor/pygments/formatters/img.pyc +0 -0
  30. data/vendor/pygments/formatters/latex.py +354 -0
  31. data/vendor/pygments/formatters/latex.pyc +0 -0
  32. data/vendor/pygments/formatters/other.py +117 -0
  33. data/vendor/pygments/formatters/other.pyc +0 -0
  34. data/vendor/pygments/formatters/rtf.py +136 -0
  35. data/vendor/pygments/formatters/rtf.pyc +0 -0
  36. data/vendor/pygments/formatters/svg.py +154 -0
  37. data/vendor/pygments/formatters/svg.pyc +0 -0
  38. data/vendor/pygments/formatters/terminal.py +109 -0
  39. data/vendor/pygments/formatters/terminal.pyc +0 -0
  40. data/vendor/pygments/formatters/terminal256.py +219 -0
  41. data/vendor/pygments/formatters/terminal256.pyc +0 -0
  42. data/vendor/pygments/lexer.py +660 -0
  43. data/vendor/pygments/lexer.pyc +0 -0
  44. data/vendor/pygments/lexers/__init__.py +226 -0
  45. data/vendor/pygments/lexers/__init__.pyc +0 -0
  46. data/vendor/pygments/lexers/_asybuiltins.py +1645 -0
  47. data/vendor/pygments/lexers/_clbuiltins.py +232 -0
  48. data/vendor/pygments/lexers/_luabuiltins.py +256 -0
  49. data/vendor/pygments/lexers/_mapping.py +234 -0
  50. data/vendor/pygments/lexers/_mapping.pyc +0 -0
  51. data/vendor/pygments/lexers/_phpbuiltins.py +3389 -0
  52. data/vendor/pygments/lexers/_vimbuiltins.py +3 -0
  53. data/vendor/pygments/lexers/agile.py +1485 -0
  54. data/vendor/pygments/lexers/agile.pyc +0 -0
  55. data/vendor/pygments/lexers/asm.py +353 -0
  56. data/vendor/pygments/lexers/compiled.py +2365 -0
  57. data/vendor/pygments/lexers/dotnet.py +355 -0
  58. data/vendor/pygments/lexers/functional.py +756 -0
  59. data/vendor/pygments/lexers/functional.pyc +0 -0
  60. data/vendor/pygments/lexers/math.py +461 -0
  61. data/vendor/pygments/lexers/other.py +2297 -0
  62. data/vendor/pygments/lexers/parsers.py +695 -0
  63. data/vendor/pygments/lexers/special.py +100 -0
  64. data/vendor/pygments/lexers/special.pyc +0 -0
  65. data/vendor/pygments/lexers/templates.py +1387 -0
  66. data/vendor/pygments/lexers/text.py +1586 -0
  67. data/vendor/pygments/lexers/web.py +1619 -0
  68. data/vendor/pygments/lexers/web.pyc +0 -0
  69. data/vendor/pygments/plugin.py +74 -0
  70. data/vendor/pygments/plugin.pyc +0 -0
  71. data/vendor/pygments/scanner.py +104 -0
  72. data/vendor/pygments/style.py +117 -0
  73. data/vendor/pygments/style.pyc +0 -0
  74. data/vendor/pygments/styles/__init__.py +68 -0
  75. data/vendor/pygments/styles/__init__.pyc +0 -0
  76. data/vendor/pygments/styles/autumn.py +65 -0
  77. data/vendor/pygments/styles/borland.py +51 -0
  78. data/vendor/pygments/styles/bw.py +49 -0
  79. data/vendor/pygments/styles/colorful.py +81 -0
  80. data/vendor/pygments/styles/default.py +73 -0
  81. data/vendor/pygments/styles/default.pyc +0 -0
  82. data/vendor/pygments/styles/emacs.py +72 -0
  83. data/vendor/pygments/styles/friendly.py +72 -0
  84. data/vendor/pygments/styles/fruity.py +43 -0
  85. data/vendor/pygments/styles/manni.py +75 -0
  86. data/vendor/pygments/styles/monokai.py +106 -0
  87. data/vendor/pygments/styles/murphy.py +80 -0
  88. data/vendor/pygments/styles/native.py +65 -0
  89. data/vendor/pygments/styles/pastie.py +75 -0
  90. data/vendor/pygments/styles/perldoc.py +69 -0
  91. data/vendor/pygments/styles/tango.py +141 -0
  92. data/vendor/pygments/styles/trac.py +63 -0
  93. data/vendor/pygments/styles/vim.py +63 -0
  94. data/vendor/pygments/styles/vs.py +38 -0
  95. data/vendor/pygments/token.py +198 -0
  96. data/vendor/pygments/token.pyc +0 -0
  97. data/vendor/pygments/unistring.py +130 -0
  98. data/vendor/pygments/unistring.pyc +0 -0
  99. data/vendor/pygments/util.py +226 -0
  100. data/vendor/pygments/util.pyc +0 -0
  101. metadata +166 -0
@@ -0,0 +1,695 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.lexers.parsers
4
+ ~~~~~~~~~~~~~~~~~~~~~~~
5
+
6
+ Lexers for parser generators.
7
+
8
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ import re
13
+
14
+ from pygments.lexer import RegexLexer, DelegatingLexer, \
15
+ include, bygroups, using
16
+ from pygments.token import Punctuation, Other, Text, Comment, Operator, \
17
+ Keyword, Name, String, Number, Whitespace
18
+ from pygments.lexers.compiled import JavaLexer, CLexer, CppLexer, \
19
+ ObjectiveCLexer, DLexer
20
+ from pygments.lexers.dotnet import CSharpLexer
21
+ from pygments.lexers.agile import RubyLexer, PythonLexer, PerlLexer
22
+ from pygments.lexers.web import ActionScriptLexer
23
+
24
+
25
+ __all__ = ['RagelLexer', 'RagelEmbeddedLexer', 'RagelCLexer', 'RagelDLexer',
26
+ 'RagelCppLexer', 'RagelObjectiveCLexer', 'RagelRubyLexer',
27
+ 'RagelJavaLexer', 'AntlrLexer', 'AntlrPythonLexer',
28
+ 'AntlrPerlLexer', 'AntlrRubyLexer', 'AntlrCppLexer',
29
+ #'AntlrCLexer',
30
+ 'AntlrCSharpLexer', 'AntlrObjectiveCLexer',
31
+ 'AntlrJavaLexer', "AntlrActionScriptLexer"]
32
+
33
+
34
+ class RagelLexer(RegexLexer):
35
+ """
36
+ A pure `Ragel <http://www.complang.org/ragel/>`_ lexer. Use this for
37
+ fragments of Ragel. For ``.rl`` files, use RagelEmbeddedLexer instead
38
+ (or one of the language-specific subclasses).
39
+
40
+ *New in Pygments 1.1.*
41
+ """
42
+
43
+ name = 'Ragel'
44
+ aliases = ['ragel']
45
+ filenames = []
46
+
47
+ tokens = {
48
+ 'whitespace': [
49
+ (r'\s+', Whitespace)
50
+ ],
51
+ 'comments': [
52
+ (r'\#.*$', Comment),
53
+ ],
54
+ 'keywords': [
55
+ (r'(access|action|alphtype)\b', Keyword),
56
+ (r'(getkey|write|machine|include)\b', Keyword),
57
+ (r'(any|ascii|extend|alpha|digit|alnum|lower|upper)\b', Keyword),
58
+ (r'(xdigit|cntrl|graph|print|punct|space|zlen|empty)\b', Keyword)
59
+ ],
60
+ 'numbers': [
61
+ (r'0x[0-9A-Fa-f]+', Number.Hex),
62
+ (r'[+-]?[0-9]+', Number.Integer),
63
+ ],
64
+ 'literals': [
65
+ (r'"(\\\\|\\"|[^"])*"', String), # double quote string
66
+ (r"'(\\\\|\\'|[^'])*'", String), # single quote string
67
+ (r'\[(\\\\|\\\]|[^\]])*\]', String), # square bracket literals
68
+ (r'/(?!\*)(\\\\|\\/|[^/])*/', String.Regex), # regular expressions
69
+ ],
70
+ 'identifiers': [
71
+ (r'[a-zA-Z_][a-zA-Z_0-9]*', Name.Variable),
72
+ ],
73
+ 'operators': [
74
+ (r',', Operator), # Join
75
+ (r'\||&|-|--', Operator), # Union, Intersection and Subtraction
76
+ (r'\.|<:|:>|:>>', Operator), # Concatention
77
+ (r':', Operator), # Label
78
+ (r'->', Operator), # Epsilon Transition
79
+ (r'(>|\$|%|<|@|<>)(/|eof\b)', Operator), # EOF Actions
80
+ (r'(>|\$|%|<|@|<>)(!|err\b)', Operator), # Global Error Actions
81
+ (r'(>|\$|%|<|@|<>)(\^|lerr\b)', Operator), # Local Error Actions
82
+ (r'(>|\$|%|<|@|<>)(~|to\b)', Operator), # To-State Actions
83
+ (r'(>|\$|%|<|@|<>)(\*|from\b)', Operator), # From-State Actions
84
+ (r'>|@|\$|%', Operator), # Transition Actions and Priorities
85
+ (r'\*|\?|\+|{[0-9]*,[0-9]*}', Operator), # Repetition
86
+ (r'!|\^', Operator), # Negation
87
+ (r'\(|\)', Operator), # Grouping
88
+ ],
89
+ 'root': [
90
+ include('literals'),
91
+ include('whitespace'),
92
+ include('comments'),
93
+ include('keywords'),
94
+ include('numbers'),
95
+ include('identifiers'),
96
+ include('operators'),
97
+ (r'{', Punctuation, 'host'),
98
+ (r'=', Operator),
99
+ (r';', Punctuation),
100
+ ],
101
+ 'host': [
102
+ (r'(' + r'|'.join(( # keep host code in largest possible chunks
103
+ r'[^{}\'"/#]+', # exclude unsafe characters
104
+ r'[^\\][\\][{}]', # allow escaped { or }
105
+
106
+ # strings and comments may safely contain unsafe characters
107
+ r'"(\\\\|\\"|[^"])*"', # double quote string
108
+ r"'(\\\\|\\'|[^'])*'", # single quote string
109
+ r'//.*$\n?', # single line comment
110
+ r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
111
+ r'\#.*$\n?', # ruby comment
112
+
113
+ # regular expression: There's no reason for it to start
114
+ # with a * and this stops confusion with comments.
115
+ r'/(?!\*)(\\\\|\\/|[^/])*/',
116
+
117
+ # / is safe now that we've handled regex and javadoc comments
118
+ r'/',
119
+ )) + r')+', Other),
120
+
121
+ (r'{', Punctuation, '#push'),
122
+ (r'}', Punctuation, '#pop'),
123
+ ],
124
+ }
125
+
126
+
127
+ class RagelEmbeddedLexer(RegexLexer):
128
+ """
129
+ A lexer for `Ragel`_ embedded in a host language file.
130
+
131
+ This will only highlight Ragel statements. If you want host language
132
+ highlighting then call the language-specific Ragel lexer.
133
+
134
+ *New in Pygments 1.1.*
135
+ """
136
+
137
+ name = 'Embedded Ragel'
138
+ aliases = ['ragel-em']
139
+ filenames = ['*.rl']
140
+
141
+ tokens = {
142
+ 'root': [
143
+ (r'(' + r'|'.join(( # keep host code in largest possible chunks
144
+ r'[^%\'"/#]+', # exclude unsafe characters
145
+ r'%(?=[^%]|$)', # a single % sign is okay, just not 2 of them
146
+
147
+ # strings and comments may safely contain unsafe characters
148
+ r'"(\\\\|\\"|[^"])*"', # double quote string
149
+ r"'(\\\\|\\'|[^'])*'", # single quote string
150
+ r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
151
+ r'//.*$\n?', # single line comment
152
+ r'\#.*$\n?', # ruby/ragel comment
153
+ r'/(?!\*)(\\\\|\\/|[^/])*/', # regular expression
154
+
155
+ # / is safe now that we've handled regex and javadoc comments
156
+ r'/',
157
+ )) + r')+', Other),
158
+
159
+ # Single Line FSM.
160
+ # Please don't put a quoted newline in a single line FSM.
161
+ # That's just mean. It will break this.
162
+ (r'(%%)(?![{%])(.*)($|;)(\n?)', bygroups(Punctuation,
163
+ using(RagelLexer),
164
+ Punctuation, Text)),
165
+
166
+ # Multi Line FSM.
167
+ (r'(%%%%|%%){', Punctuation, 'multi-line-fsm'),
168
+ ],
169
+ 'multi-line-fsm': [
170
+ (r'(' + r'|'.join(( # keep ragel code in largest possible chunks.
171
+ r'(' + r'|'.join((
172
+ r'[^}\'"\[/#]', # exclude unsafe characters
173
+ r'}(?=[^%]|$)', # } is okay as long as it's not followed by %
174
+ r'}%(?=[^%]|$)', # ...well, one %'s okay, just not two...
175
+ r'[^\\][\\][{}]', # ...and } is okay if it's escaped
176
+
177
+ # allow / if it's preceded with one of these symbols
178
+ # (ragel EOF actions)
179
+ r'(>|\$|%|<|@|<>)/',
180
+
181
+ # specifically allow regex followed immediately by *
182
+ # so it doesn't get mistaken for a comment
183
+ r'/(?!\*)(\\\\|\\/|[^/])*/\*',
184
+
185
+ # allow / as long as it's not followed by another / or by a *
186
+ r'/(?=[^/\*]|$)',
187
+
188
+ # We want to match as many of these as we can in one block.
189
+ # Not sure if we need the + sign here,
190
+ # does it help performance?
191
+ )) + r')+',
192
+
193
+ # strings and comments may safely contain unsafe characters
194
+ r'"(\\\\|\\"|[^"])*"', # double quote string
195
+ r"'(\\\\|\\'|[^'])*'", # single quote string
196
+ r"\[(\\\\|\\\]|[^\]])*\]", # square bracket literal
197
+ r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
198
+ r'//.*$\n?', # single line comment
199
+ r'\#.*$\n?', # ruby/ragel comment
200
+ )) + r')+', using(RagelLexer)),
201
+
202
+ (r'}%%', Punctuation, '#pop'),
203
+ ]
204
+ }
205
+
206
+ def analyse_text(text):
207
+ return '@LANG: indep' in text or 0.1
208
+
209
+
210
+ class RagelRubyLexer(DelegatingLexer):
211
+ """
212
+ A lexer for `Ragel`_ in a Ruby host file.
213
+
214
+ *New in Pygments 1.1.*
215
+ """
216
+
217
+ name = 'Ragel in Ruby Host'
218
+ aliases = ['ragel-ruby', 'ragel-rb']
219
+ filenames = ['*.rl']
220
+
221
+ def __init__(self, **options):
222
+ super(RagelRubyLexer, self).__init__(RubyLexer, RagelEmbeddedLexer,
223
+ **options)
224
+
225
+ def analyse_text(text):
226
+ return '@LANG: ruby' in text
227
+
228
+
229
+ class RagelCLexer(DelegatingLexer):
230
+ """
231
+ A lexer for `Ragel`_ in a C host file.
232
+
233
+ *New in Pygments 1.1.*
234
+ """
235
+
236
+ name = 'Ragel in C Host'
237
+ aliases = ['ragel-c']
238
+ filenames = ['*.rl']
239
+
240
+ def __init__(self, **options):
241
+ super(RagelCLexer, self).__init__(CLexer, RagelEmbeddedLexer,
242
+ **options)
243
+
244
+ def analyse_text(text):
245
+ return '@LANG: c' in text
246
+
247
+
248
+ class RagelDLexer(DelegatingLexer):
249
+ """
250
+ A lexer for `Ragel`_ in a D host file.
251
+
252
+ *New in Pygments 1.1.*
253
+ """
254
+
255
+ name = 'Ragel in D Host'
256
+ aliases = ['ragel-d']
257
+ filenames = ['*.rl']
258
+
259
+ def __init__(self, **options):
260
+ super(RagelDLexer, self).__init__(DLexer, RagelEmbeddedLexer, **options)
261
+
262
+ def analyse_text(text):
263
+ return '@LANG: d' in text
264
+
265
+
266
+ class RagelCppLexer(DelegatingLexer):
267
+ """
268
+ A lexer for `Ragel`_ in a CPP host file.
269
+
270
+ *New in Pygments 1.1.*
271
+ """
272
+
273
+ name = 'Ragel in CPP Host'
274
+ aliases = ['ragel-cpp']
275
+ filenames = ['*.rl']
276
+
277
+ def __init__(self, **options):
278
+ super(RagelCppLexer, self).__init__(CppLexer, RagelEmbeddedLexer, **options)
279
+
280
+ def analyse_text(text):
281
+ return '@LANG: c++' in text
282
+
283
+
284
+ class RagelObjectiveCLexer(DelegatingLexer):
285
+ """
286
+ A lexer for `Ragel`_ in an Objective C host file.
287
+
288
+ *New in Pygments 1.1.*
289
+ """
290
+
291
+ name = 'Ragel in Objective C Host'
292
+ aliases = ['ragel-objc']
293
+ filenames = ['*.rl']
294
+
295
+ def __init__(self, **options):
296
+ super(RagelObjectiveCLexer, self).__init__(ObjectiveCLexer,
297
+ RagelEmbeddedLexer,
298
+ **options)
299
+
300
+ def analyse_text(text):
301
+ return '@LANG: objc' in text
302
+
303
+
304
+ class RagelJavaLexer(DelegatingLexer):
305
+ """
306
+ A lexer for `Ragel`_ in a Java host file.
307
+
308
+ *New in Pygments 1.1.*
309
+ """
310
+
311
+ name = 'Ragel in Java Host'
312
+ aliases = ['ragel-java']
313
+ filenames = ['*.rl']
314
+
315
+ def __init__(self, **options):
316
+ super(RagelJavaLexer, self).__init__(JavaLexer, RagelEmbeddedLexer,
317
+ **options)
318
+
319
+ def analyse_text(text):
320
+ return '@LANG: java' in text
321
+
322
+
323
+ class AntlrLexer(RegexLexer):
324
+ """
325
+ Generic `ANTLR`_ Lexer.
326
+ Should not be called directly, instead
327
+ use DelegatingLexer for your target language.
328
+
329
+ *New in Pygments 1.1.*
330
+
331
+ .. _ANTLR: http://www.antlr.org/
332
+ """
333
+
334
+ name = 'ANTLR'
335
+ aliases = ['antlr']
336
+ filenames = []
337
+
338
+ _id = r'[A-Za-z][A-Za-z_0-9]*'
339
+ _TOKEN_REF = r'[A-Z][A-Za-z_0-9]*'
340
+ _RULE_REF = r'[a-z][A-Za-z_0-9]*'
341
+ _STRING_LITERAL = r'\'(?:\\\\|\\\'|[^\']*)\''
342
+ _INT = r'[0-9]+'
343
+
344
+ tokens = {
345
+ 'whitespace': [
346
+ (r'\s+', Whitespace),
347
+ ],
348
+ 'comments': [
349
+ (r'//.*$', Comment),
350
+ (r'/\*(.|\n)*?\*/', Comment),
351
+ ],
352
+ 'root': [
353
+ include('whitespace'),
354
+ include('comments'),
355
+
356
+ (r'(lexer|parser|tree)?(\s*)(grammar\b)(\s*)(' + _id + ')(;)',
357
+ bygroups(Keyword, Whitespace, Keyword, Whitespace, Name.Class,
358
+ Punctuation)),
359
+ # optionsSpec
360
+ (r'options\b', Keyword, 'options'),
361
+ # tokensSpec
362
+ (r'tokens\b', Keyword, 'tokens'),
363
+ # attrScope
364
+ (r'(scope)(\s*)(' + _id + ')(\s*)({)',
365
+ bygroups(Keyword, Whitespace, Name.Variable, Whitespace,
366
+ Punctuation), 'action'),
367
+ # exception
368
+ (r'(catch|finally)\b', Keyword, 'exception'),
369
+ # action
370
+ (r'(@' + _id + ')(\s*)(::)?(\s*)(' + _id + ')(\s*)({)',
371
+ bygroups(Name.Label, Whitespace, Punctuation, Whitespace,
372
+ Name.Label, Whitespace, Punctuation), 'action'),
373
+ # rule
374
+ (r'((?:protected|private|public|fragment)\b)?(\s*)(' + _id + ')(!)?', \
375
+ bygroups(Keyword, Whitespace, Name.Label, Punctuation),
376
+ ('rule-alts', 'rule-prelims')),
377
+ ],
378
+ 'exception': [
379
+ (r'\n', Whitespace, '#pop'),
380
+ (r'\s', Whitespace),
381
+ include('comments'),
382
+
383
+ (r'\[', Punctuation, 'nested-arg-action'),
384
+ (r'\{', Punctuation, 'action'),
385
+ ],
386
+ 'rule-prelims': [
387
+ include('whitespace'),
388
+ include('comments'),
389
+
390
+ (r'returns\b', Keyword),
391
+ (r'\[', Punctuation, 'nested-arg-action'),
392
+ (r'\{', Punctuation, 'action'),
393
+ # throwsSpec
394
+ (r'(throws)(\s+)(' + _id + ')',
395
+ bygroups(Keyword, Whitespace, Name.Label)),
396
+ (r'(?:(,)(\s*)(' + _id + '))+',
397
+ bygroups(Punctuation, Whitespace, Name.Label)), # Additional throws
398
+ # optionsSpec
399
+ (r'options\b', Keyword, 'options'),
400
+ # ruleScopeSpec - scope followed by target language code or name of action
401
+ # TODO finish implementing other possibilities for scope
402
+ # L173 ANTLRv3.g from ANTLR book
403
+ (r'(scope)(\s+)({)', bygroups(Keyword, Whitespace, Punctuation),
404
+ 'action'),
405
+ (r'(scope)(\s+)(' + _id + ')(\s*)(;)',
406
+ bygroups(Keyword, Whitespace, Name.Label, Whitespace, Punctuation)),
407
+ # ruleAction
408
+ (r'(@' + _id + ')(\s*)({)',
409
+ bygroups(Name.Label, Whitespace, Punctuation), 'action'),
410
+ # finished prelims, go to rule alts!
411
+ (r':', Punctuation, '#pop')
412
+ ],
413
+ 'rule-alts': [
414
+ include('whitespace'),
415
+ include('comments'),
416
+
417
+ # These might need to go in a separate 'block' state triggered by (
418
+ (r'options\b', Keyword, 'options'),
419
+ (r':', Punctuation),
420
+
421
+ # literals
422
+ (r"'(\\\\|\\'|[^'])*'", String),
423
+ (r'"(\\\\|\\"|[^"])*"', String),
424
+ (r'<<([^>]|>[^>])>>', String),
425
+ # identifiers
426
+ # Tokens start with capital letter.
427
+ (r'\$?[A-Z_][A-Za-z_0-9]*', Name.Constant),
428
+ # Rules start with small letter.
429
+ (r'\$?[a-z_][A-Za-z_0-9]*', Name.Variable),
430
+ # operators
431
+ (r'(\+|\||->|=>|=|\(|\)|\.\.|\.|\?|\*|\^|!|\#|~)', Operator),
432
+ (r',', Punctuation),
433
+ (r'\[', Punctuation, 'nested-arg-action'),
434
+ (r'\{', Punctuation, 'action'),
435
+ (r';', Punctuation, '#pop')
436
+ ],
437
+ 'tokens': [
438
+ include('whitespace'),
439
+ include('comments'),
440
+ (r'{', Punctuation),
441
+ (r'(' + _TOKEN_REF + r')(\s*)(=)?(\s*)(' + _STRING_LITERAL
442
+ + ')?(\s*)(;)',
443
+ bygroups(Name.Label, Whitespace, Punctuation, Whitespace,
444
+ String, Whitespace, Punctuation)),
445
+ (r'}', Punctuation, '#pop'),
446
+ ],
447
+ 'options': [
448
+ include('whitespace'),
449
+ include('comments'),
450
+ (r'{', Punctuation),
451
+ (r'(' + _id + r')(\s*)(=)(\s*)(' +
452
+ '|'.join((_id, _STRING_LITERAL, _INT, '\*'))+ ')(\s*)(;)',
453
+ bygroups(Name.Variable, Whitespace, Punctuation, Whitespace,
454
+ Text, Whitespace, Punctuation)),
455
+ (r'}', Punctuation, '#pop'),
456
+ ],
457
+ 'action': [
458
+ (r'(' + r'|'.join(( # keep host code in largest possible chunks
459
+ r'[^\${}\'"/\\]+', # exclude unsafe characters
460
+
461
+ # strings and comments may safely contain unsafe characters
462
+ r'"(\\\\|\\"|[^"])*"', # double quote string
463
+ r"'(\\\\|\\'|[^'])*'", # single quote string
464
+ r'//.*$\n?', # single line comment
465
+ r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
466
+
467
+ # regular expression: There's no reason for it to start
468
+ # with a * and this stops confusion with comments.
469
+ r'/(?!\*)(\\\\|\\/|[^/])*/',
470
+
471
+ # backslashes are okay, as long as we are not backslashing a %
472
+ r'\\(?!%)',
473
+
474
+ # Now that we've handled regex and javadoc comments
475
+ # it's safe to let / through.
476
+ r'/',
477
+ )) + r')+', Other),
478
+ (r'(\\)(%)', bygroups(Punctuation, Other)),
479
+ (r'(\$[a-zA-Z]+)(\.?)(text|value)?',
480
+ bygroups(Name.Variable, Punctuation, Name.Property)),
481
+ (r'{', Punctuation, '#push'),
482
+ (r'}', Punctuation, '#pop'),
483
+ ],
484
+ 'nested-arg-action': [
485
+ (r'(' + r'|'.join(( # keep host code in largest possible chunks.
486
+ r'[^\$\[\]\'"/]+', # exclude unsafe characters
487
+
488
+ # strings and comments may safely contain unsafe characters
489
+ r'"(\\\\|\\"|[^"])*"', # double quote string
490
+ r"'(\\\\|\\'|[^'])*'", # single quote string
491
+ r'//.*$\n?', # single line comment
492
+ r'/\*(.|\n)*?\*/', # multi-line javadoc-style comment
493
+
494
+ # regular expression: There's no reason for it to start
495
+ # with a * and this stops confusion with comments.
496
+ r'/(?!\*)(\\\\|\\/|[^/])*/',
497
+
498
+ # Now that we've handled regex and javadoc comments
499
+ # it's safe to let / through.
500
+ r'/',
501
+ )) + r')+', Other),
502
+
503
+
504
+ (r'\[', Punctuation, '#push'),
505
+ (r'\]', Punctuation, '#pop'),
506
+ (r'(\$[a-zA-Z]+)(\.?)(text|value)?',
507
+ bygroups(Name.Variable, Punctuation, Name.Property)),
508
+ (r'(\\\\|\\\]|\\\[|[^\[\]])+', Other),
509
+ ]
510
+ }
511
+
512
+ def analyse_text(text):
513
+ return re.search(r'^\s*grammar\s+[a-zA-Z0-9]+\s*;', text, re.M)
514
+
515
+ # http://www.antlr.org/wiki/display/ANTLR3/Code+Generation+Targets
516
+
517
+ # TH: I'm not aware of any language features of C++ that will cause
518
+ # incorrect lexing of C files. Antlr doesn't appear to make a distinction,
519
+ # so just assume they're C++. No idea how to make Objective C work in the
520
+ # future.
521
+
522
+ #class AntlrCLexer(DelegatingLexer):
523
+ # """
524
+ # ANTLR with C Target
525
+ #
526
+ # *New in Pygments 1.1*
527
+ # """
528
+ #
529
+ # name = 'ANTLR With C Target'
530
+ # aliases = ['antlr-c']
531
+ # filenames = ['*.G', '*.g']
532
+ #
533
+ # def __init__(self, **options):
534
+ # super(AntlrCLexer, self).__init__(CLexer, AntlrLexer, **options)
535
+ #
536
+ # def analyse_text(text):
537
+ # return re.match(r'^\s*language\s*=\s*C\s*;', text)
538
+
539
+ class AntlrCppLexer(DelegatingLexer):
540
+ """
541
+ `ANTLR`_ with CPP Target
542
+
543
+ *New in Pygments 1.1.*
544
+ """
545
+
546
+ name = 'ANTLR With CPP Target'
547
+ aliases = ['antlr-cpp']
548
+ filenames = ['*.G', '*.g']
549
+
550
+ def __init__(self, **options):
551
+ super(AntlrCppLexer, self).__init__(CppLexer, AntlrLexer, **options)
552
+
553
+ def analyse_text(text):
554
+ return AntlrLexer.analyse_text(text) and \
555
+ re.search(r'^\s*language\s*=\s*C\s*;', text, re.M)
556
+
557
+
558
+ class AntlrObjectiveCLexer(DelegatingLexer):
559
+ """
560
+ `ANTLR`_ with Objective-C Target
561
+
562
+ *New in Pygments 1.1.*
563
+ """
564
+
565
+ name = 'ANTLR With ObjectiveC Target'
566
+ aliases = ['antlr-objc']
567
+ filenames = ['*.G', '*.g']
568
+
569
+ def __init__(self, **options):
570
+ super(AntlrObjectiveCLexer, self).__init__(ObjectiveCLexer,
571
+ AntlrLexer, **options)
572
+
573
+ def analyse_text(text):
574
+ return AntlrLexer.analyse_text(text) and \
575
+ re.search(r'^\s*language\s*=\s*ObjC\s*;', text)
576
+
577
+
578
+ class AntlrCSharpLexer(DelegatingLexer):
579
+ """
580
+ `ANTLR`_ with C# Target
581
+
582
+ *New in Pygments 1.1.*
583
+ """
584
+
585
+ name = 'ANTLR With C# Target'
586
+ aliases = ['antlr-csharp', 'antlr-c#']
587
+ filenames = ['*.G', '*.g']
588
+
589
+ def __init__(self, **options):
590
+ super(AntlrCSharpLexer, self).__init__(CSharpLexer, AntlrLexer,
591
+ **options)
592
+
593
+ def analyse_text(text):
594
+ return AntlrLexer.analyse_text(text) and \
595
+ re.search(r'^\s*language\s*=\s*CSharp2\s*;', text, re.M)
596
+
597
+
598
+ class AntlrPythonLexer(DelegatingLexer):
599
+ """
600
+ `ANTLR`_ with Python Target
601
+
602
+ *New in Pygments 1.1.*
603
+ """
604
+
605
+ name = 'ANTLR With Python Target'
606
+ aliases = ['antlr-python']
607
+ filenames = ['*.G', '*.g']
608
+
609
+ def __init__(self, **options):
610
+ super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer,
611
+ **options)
612
+
613
+ def analyse_text(text):
614
+ return AntlrLexer.analyse_text(text) and \
615
+ re.search(r'^\s*language\s*=\s*Python\s*;', text, re.M)
616
+
617
+
618
+ class AntlrJavaLexer(DelegatingLexer):
619
+ """
620
+ `ANTLR`_ with Java Target
621
+
622
+ *New in Pygments 1.1*
623
+ """
624
+
625
+ name = 'ANTLR With Java Target'
626
+ aliases = ['antlr-java']
627
+ filenames = ['*.G', '*.g']
628
+
629
+ def __init__(self, **options):
630
+ super(AntlrJavaLexer, self).__init__(JavaLexer, AntlrLexer,
631
+ **options)
632
+
633
+ def analyse_text(text):
634
+ # Antlr language is Java by default
635
+ return AntlrLexer.analyse_text(text) and 0.9
636
+
637
+
638
+ class AntlrRubyLexer(DelegatingLexer):
639
+ """
640
+ `ANTLR`_ with Ruby Target
641
+
642
+ *New in Pygments 1.1.*
643
+ """
644
+
645
+ name = 'ANTLR With Ruby Target'
646
+ aliases = ['antlr-ruby', 'antlr-rb']
647
+ filenames = ['*.G', '*.g']
648
+
649
+ def __init__(self, **options):
650
+ super(AntlrRubyLexer, self).__init__(RubyLexer, AntlrLexer,
651
+ **options)
652
+
653
+ def analyse_text(text):
654
+ return AntlrLexer.analyse_text(text) and \
655
+ re.search(r'^\s*language\s*=\s*Ruby\s*;', text, re.M)
656
+
657
+
658
+ class AntlrPerlLexer(DelegatingLexer):
659
+ """
660
+ `ANTLR`_ with Perl Target
661
+
662
+ *New in Pygments 1.1.*
663
+ """
664
+
665
+ name = 'ANTLR With Perl Target'
666
+ aliases = ['antlr-perl']
667
+ filenames = ['*.G', '*.g']
668
+
669
+ def __init__(self, **options):
670
+ super(AntlrPerlLexer, self).__init__(PerlLexer, AntlrLexer,
671
+ **options)
672
+
673
+ def analyse_text(text):
674
+ return AntlrLexer.analyse_text(text) and \
675
+ re.search(r'^\s*language\s*=\s*Perl5\s*;', text, re.M)
676
+
677
+
678
+ class AntlrActionScriptLexer(DelegatingLexer):
679
+ """
680
+ `ANTLR`_ with ActionScript Target
681
+
682
+ *New in Pygments 1.1.*
683
+ """
684
+
685
+ name = 'ANTLR With ActionScript Target'
686
+ aliases = ['antlr-as', 'antlr-actionscript']
687
+ filenames = ['*.G', '*.g']
688
+
689
+ def __init__(self, **options):
690
+ super(AntlrActionScriptLexer, self).__init__(ActionScriptLexer,
691
+ AntlrLexer, **options)
692
+
693
+ def analyse_text(text):
694
+ return AntlrLexer.analyse_text(text) and \
695
+ re.search(r'^\s*language\s*=\s*ActionScript\s*;', text, re.M)