pygments.rb 0.2.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pygments/version.rb +1 -1
- data/vendor/pygments-main/AUTHORS +14 -0
- data/vendor/pygments-main/CHANGES +34 -3
- data/vendor/pygments-main/Makefile +1 -1
- data/vendor/pygments-main/docs/generate.py +1 -1
- data/vendor/pygments-main/external/markdown-processor.py +1 -1
- data/vendor/pygments-main/external/moin-parser.py +1 -1
- data/vendor/pygments-main/external/rst-directive-old.py +1 -1
- data/vendor/pygments-main/external/rst-directive.py +1 -1
- data/vendor/pygments-main/pygments/__init__.py +1 -1
- data/vendor/pygments-main/pygments/cmdline.py +4 -1
- data/vendor/pygments-main/pygments/console.py +1 -1
- data/vendor/pygments-main/pygments/filter.py +1 -1
- data/vendor/pygments-main/pygments/filters/__init__.py +1 -1
- data/vendor/pygments-main/pygments/formatter.py +1 -1
- data/vendor/pygments-main/pygments/formatters/__init__.py +1 -1
- data/vendor/pygments-main/pygments/formatters/_mapping.py +1 -1
- data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
- data/vendor/pygments-main/pygments/formatters/html.py +2 -2
- data/vendor/pygments-main/pygments/formatters/img.py +1 -1
- data/vendor/pygments-main/pygments/formatters/latex.py +3 -2
- data/vendor/pygments-main/pygments/formatters/other.py +1 -1
- data/vendor/pygments-main/pygments/formatters/rtf.py +1 -1
- data/vendor/pygments-main/pygments/formatters/svg.py +1 -1
- data/vendor/pygments-main/pygments/formatters/terminal.py +5 -2
- data/vendor/pygments-main/pygments/formatters/terminal256.py +5 -2
- data/vendor/pygments-main/pygments/lexer.py +29 -10
- data/vendor/pygments-main/pygments/lexers/__init__.py +14 -11
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_mapping.py +41 -23
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -3
- data/vendor/pygments-main/pygments/lexers/agile.py +148 -443
- data/vendor/pygments-main/pygments/lexers/asm.py +5 -3
- data/vendor/pygments-main/pygments/lexers/compiled.py +298 -294
- data/vendor/pygments-main/pygments/lexers/dotnet.py +40 -34
- data/vendor/pygments-main/pygments/lexers/functional.py +723 -4
- data/vendor/pygments-main/pygments/lexers/hdl.py +228 -6
- data/vendor/pygments-main/pygments/lexers/jvm.py +678 -0
- data/vendor/pygments-main/pygments/lexers/math.py +65 -2
- data/vendor/pygments-main/pygments/lexers/other.py +875 -481
- data/vendor/pygments-main/pygments/lexers/parsers.py +1 -1
- data/vendor/pygments-main/pygments/lexers/shell.py +360 -0
- data/vendor/pygments-main/pygments/lexers/special.py +1 -1
- data/vendor/pygments-main/pygments/lexers/sql.py +565 -0
- data/vendor/pygments-main/pygments/lexers/templates.py +1 -1
- data/vendor/pygments-main/pygments/lexers/text.py +237 -100
- data/vendor/pygments-main/pygments/lexers/web.py +146 -10
- data/vendor/pygments-main/pygments/plugin.py +1 -1
- data/vendor/pygments-main/pygments/scanner.py +1 -1
- data/vendor/pygments-main/pygments/style.py +1 -1
- data/vendor/pygments-main/pygments/styles/__init__.py +2 -1
- data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
- data/vendor/pygments-main/pygments/styles/borland.py +1 -1
- data/vendor/pygments-main/pygments/styles/bw.py +1 -1
- data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
- data/vendor/pygments-main/pygments/styles/default.py +1 -1
- data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
- data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
- data/vendor/pygments-main/pygments/styles/fruity.py +1 -2
- data/vendor/pygments-main/pygments/styles/manni.py +1 -1
- data/vendor/pygments-main/pygments/styles/monokai.py +1 -1
- data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
- data/vendor/pygments-main/pygments/styles/native.py +1 -1
- data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
- data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
- data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
- data/vendor/pygments-main/pygments/styles/tango.py +1 -1
- data/vendor/pygments-main/pygments/styles/trac.py +1 -1
- data/vendor/pygments-main/pygments/styles/vim.py +1 -1
- data/vendor/pygments-main/pygments/styles/vs.py +1 -1
- data/vendor/pygments-main/pygments/token.py +1 -1
- data/vendor/pygments-main/pygments/unistring.py +1 -1
- data/vendor/pygments-main/pygments/util.py +2 -2
- data/vendor/pygments-main/scripts/check_sources.py +2 -2
- data/vendor/pygments-main/scripts/find_codetags.py +1 -1
- data/vendor/pygments-main/scripts/find_error.py +5 -2
- data/vendor/pygments-main/scripts/get_vimkw.py +9 -4
- data/vendor/pygments-main/setup.py +1 -1
- data/vendor/pygments-main/tests/examplefiles/classes.dylan +16 -0
- data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
- data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
- data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
- data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
- data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
- data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
- data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
- data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
- data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +4 -2
- data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
- data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
- data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
- data/vendor/pygments-main/tests/examplefiles/test.cs +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
- data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
- data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
- data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
- data/vendor/pygments-main/tests/old_run.py +1 -1
- data/vendor/pygments-main/tests/run.py +1 -1
- data/vendor/pygments-main/tests/test_basic_api.py +4 -3
- data/vendor/pygments-main/tests/test_clexer.py +1 -1
- data/vendor/pygments-main/tests/test_cmdline.py +1 -1
- data/vendor/pygments-main/tests/test_examplefiles.py +4 -3
- data/vendor/pygments-main/tests/test_html_formatter.py +33 -1
- data/vendor/pygments-main/tests/test_latex_formatter.py +1 -1
- data/vendor/pygments-main/tests/test_perllexer.py +137 -0
- data/vendor/pygments-main/tests/test_regexlexer.py +1 -1
- data/vendor/pygments-main/tests/test_token.py +1 -1
- data/vendor/pygments-main/tests/test_using_api.py +1 -1
- data/vendor/pygments-main/tests/test_util.py +35 -5
- metadata +30 -4
@@ -5,18 +5,17 @@
|
|
5
5
|
|
6
6
|
Lexers for hardware descriptor languages.
|
7
7
|
|
8
|
-
:copyright: Copyright
|
8
|
+
:copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
|
9
9
|
:license: BSD, see LICENSE for details.
|
10
10
|
"""
|
11
11
|
|
12
12
|
import re
|
13
|
-
|
14
|
-
from pygments.lexer import RegexLexer, include, bygroups
|
13
|
+
from pygments.lexer import RegexLexer, bygroups, include, using, this
|
15
14
|
from pygments.token import \
|
16
15
|
Text, Comment, Operator, Keyword, Name, String, Number, Punctuation, \
|
17
16
|
Error
|
18
17
|
|
19
|
-
__all__ = ['VerilogLexer']
|
18
|
+
__all__ = ['VerilogLexer', 'SystemVerilogLexer', 'VhdlLexer']
|
20
19
|
|
21
20
|
|
22
21
|
class VerilogLexer(RegexLexer):
|
@@ -27,7 +26,7 @@ class VerilogLexer(RegexLexer):
|
|
27
26
|
"""
|
28
27
|
name = 'verilog'
|
29
28
|
aliases = ['v']
|
30
|
-
filenames = ['*.v'
|
29
|
+
filenames = ['*.v']
|
31
30
|
mimetypes = ['text/x-verilog']
|
32
31
|
|
33
32
|
#: optional Comment or Whitespace
|
@@ -92,8 +91,143 @@ class VerilogLexer(RegexLexer):
|
|
92
91
|
r'\$showscopes|\$showvariables|\$showvars|\$sreadmemb|\$sreadmemh|'
|
93
92
|
r'\$stime|\$stop|\$strobe|\$time|\$timeformat|\$write)\b', Name.Builtin),
|
94
93
|
|
94
|
+
(r'(byte|shortint|int|longint|integer|time|'
|
95
|
+
r'bit|logic|reg|'
|
96
|
+
r'supply0|supply1|tri|triand|trior|tri0|tri1|trireg|uwire|wire|wand|wor'
|
97
|
+
r'shortreal|real|realtime)\b', Keyword.Type),
|
98
|
+
('[a-zA-Z_][a-zA-Z0-9_]*:(?!:)', Name.Label),
|
99
|
+
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
|
100
|
+
],
|
101
|
+
'string': [
|
102
|
+
(r'"', String, '#pop'),
|
103
|
+
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
|
104
|
+
(r'[^\\"\n]+', String), # all other characters
|
105
|
+
(r'\\\n', String), # line continuation
|
106
|
+
(r'\\', String), # stray backslash
|
107
|
+
],
|
108
|
+
'macro': [
|
109
|
+
(r'[^/\n]+', Comment.Preproc),
|
110
|
+
(r'/[*](.|\n)*?[*]/', Comment.Multiline),
|
111
|
+
(r'//.*?\n', Comment.Single, '#pop'),
|
112
|
+
(r'/', Comment.Preproc),
|
113
|
+
(r'(?<=\\)\n', Comment.Preproc),
|
114
|
+
(r'\n', Comment.Preproc, '#pop'),
|
115
|
+
],
|
116
|
+
'import': [
|
117
|
+
(r'[a-zA-Z0-9_:]+\*?', Name.Namespace, '#pop')
|
118
|
+
]
|
119
|
+
}
|
120
|
+
|
121
|
+
def get_tokens_unprocessed(self, text):
|
122
|
+
for index, token, value in \
|
123
|
+
RegexLexer.get_tokens_unprocessed(self, text):
|
124
|
+
# Convention: mark all upper case names as constants
|
125
|
+
if token is Name:
|
126
|
+
if value.isupper():
|
127
|
+
token = Name.Constant
|
128
|
+
yield index, token, value
|
129
|
+
|
130
|
+
|
131
|
+
class SystemVerilogLexer(RegexLexer):
|
132
|
+
"""
|
133
|
+
Extends verilog lexer to recognise all SystemVerilog keywords from IEEE
|
134
|
+
1800-2009 standard.
|
135
|
+
|
136
|
+
*New in Pygments 1.5.*
|
137
|
+
"""
|
138
|
+
name = 'systemverilog'
|
139
|
+
aliases = ['sv']
|
140
|
+
filenames = ['*.sv', '*.svh']
|
141
|
+
mimetypes = ['text/x-systemverilog']
|
142
|
+
|
143
|
+
#: optional Comment or Whitespace
|
144
|
+
_ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
|
145
|
+
|
146
|
+
tokens = {
|
147
|
+
'root': [
|
148
|
+
(r'^\s*`define', Comment.Preproc, 'macro'),
|
149
|
+
(r'\n', Text),
|
150
|
+
(r'\s+', Text),
|
151
|
+
(r'\\\n', Text), # line continuation
|
152
|
+
(r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
|
153
|
+
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
|
154
|
+
(r'[{}#@]', Punctuation),
|
155
|
+
(r'L?"', String, 'string'),
|
156
|
+
(r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
|
157
|
+
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
|
158
|
+
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
|
159
|
+
(r'([0-9]+)|(\'h)[0-9a-fA-F]+', Number.Hex),
|
160
|
+
(r'([0-9]+)|(\'b)[0-1]+', Number.Hex), # should be binary
|
161
|
+
(r'([0-9]+)|(\'d)[0-9]+', Number.Integer),
|
162
|
+
(r'([0-9]+)|(\'o)[0-7]+', Number.Oct),
|
163
|
+
(r'\'[01xz]', Number),
|
164
|
+
(r'\d+[Ll]?', Number.Integer),
|
165
|
+
(r'\*/', Error),
|
166
|
+
(r'[~!%^&*+=|?:<>/-]', Operator),
|
167
|
+
(r'[()\[\],.;\']', Punctuation),
|
168
|
+
(r'`[a-zA-Z_][a-zA-Z0-9_]*', Name.Constant),
|
169
|
+
|
170
|
+
(r'^\s*(package)(\s+)', bygroups(Keyword.Namespace, Text)),
|
171
|
+
(r'^\s*(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
(r'(accept_on|alias|always|always_comb|always_ff|always_latch|'
|
176
|
+
r'and|assert|assign|assume|automatic|before|begin|bind|bins|'
|
177
|
+
r'binsof|bit|break|buf|bufif0|bufif1|byte|case|casex|casez|'
|
178
|
+
r'cell|chandle|checker|class|clocking|cmos|config|const|constraint|'
|
179
|
+
r'context|continue|cover|covergroup|coverpoint|cross|deassign|'
|
180
|
+
r'default|defparam|design|disable|dist|do|edge|else|end|endcase|'
|
181
|
+
r'endchecker|endclass|endclocking|endconfig|endfunction|endgenerate|'
|
182
|
+
r'endgroup|endinterface|endmodule|endpackage|endprimitive|'
|
183
|
+
r'endprogram|endproperty|endsequence|endspecify|endtable|'
|
184
|
+
r'endtask|enum|event|eventually|expect|export|extends|extern|'
|
185
|
+
r'final|first_match|for|force|foreach|forever|fork|forkjoin|'
|
186
|
+
r'function|generate|genvar|global|highz0|highz1|if|iff|ifnone|'
|
187
|
+
r'ignore_bins|illegal_bins|implies|import|incdir|include|'
|
188
|
+
r'initial|inout|input|inside|instance|int|integer|interface|'
|
189
|
+
r'intersect|join|join_any|join_none|large|let|liblist|library|'
|
190
|
+
r'local|localparam|logic|longint|macromodule|matches|medium|'
|
191
|
+
r'modport|module|nand|negedge|new|nexttime|nmos|nor|noshowcancelled|'
|
192
|
+
r'not|notif0|notif1|null|or|output|package|packed|parameter|'
|
193
|
+
r'pmos|posedge|primitive|priority|program|property|protected|'
|
194
|
+
r'pull0|pull1|pulldown|pullup|pulsestyle_ondetect|pulsestyle_onevent|'
|
195
|
+
r'pure|rand|randc|randcase|randsequence|rcmos|real|realtime|'
|
196
|
+
r'ref|reg|reject_on|release|repeat|restrict|return|rnmos|'
|
197
|
+
r'rpmos|rtran|rtranif0|rtranif1|s_always|s_eventually|s_nexttime|'
|
198
|
+
r's_until|s_until_with|scalared|sequence|shortint|shortreal|'
|
199
|
+
r'showcancelled|signed|small|solve|specify|specparam|static|'
|
200
|
+
r'string|strong|strong0|strong1|struct|super|supply0|supply1|'
|
201
|
+
r'sync_accept_on|sync_reject_on|table|tagged|task|this|throughout|'
|
202
|
+
r'time|timeprecision|timeunit|tran|tranif0|tranif1|tri|tri0|'
|
203
|
+
r'tri1|triand|trior|trireg|type|typedef|union|unique|unique0|'
|
204
|
+
r'unsigned|until|until_with|untyped|use|uwire|var|vectored|'
|
205
|
+
r'virtual|void|wait|wait_order|wand|weak|weak0|weak1|while|'
|
206
|
+
r'wildcard|wire|with|within|wor|xnor|xor)\b', Keyword ),
|
207
|
+
|
208
|
+
(r'(`__FILE__|`__LINE__|`begin_keywords|`celldefine|`default_nettype|'
|
209
|
+
r'`define|`else|`elsif|`end_keywords|`endcelldefine|`endif|'
|
210
|
+
r'`ifdef|`ifndef|`include|`line|`nounconnected_drive|`pragma|'
|
211
|
+
r'`resetall|`timescale|`unconnected_drive|`undef|`undefineall)\b',
|
212
|
+
Comment.Preproc ),
|
213
|
+
|
214
|
+
(r'(\$display|\$displayb|\$displayh|\$displayo|\$dumpall|\$dumpfile|'
|
215
|
+
r'\$dumpflush|\$dumplimit|\$dumpoff|\$dumpon|\$dumpports|'
|
216
|
+
r'\$dumpportsall|\$dumpportsflush|\$dumpportslimit|\$dumpportsoff|'
|
217
|
+
r'\$dumpportson|\$dumpvars|\$fclose|\$fdisplay|\$fdisplayb|'
|
218
|
+
r'\$fdisplayh|\$fdisplayo|\$feof|\$ferror|\$fflush|\$fgetc|'
|
219
|
+
r'\$fgets|\$fmonitor|\$fmonitorb|\$fmonitorh|\$fmonitoro|'
|
220
|
+
r'\$fopen|\$fread|\$fscanf|\$fseek|\$fstrobe|\$fstrobeb|\$fstrobeh|'
|
221
|
+
r'\$fstrobeo|\$ftell|\$fwrite|\$fwriteb|\$fwriteh|\$fwriteo|'
|
222
|
+
r'\$monitor|\$monitorb|\$monitorh|\$monitoro|\$monitoroff|'
|
223
|
+
r'\$monitoron|\$plusargs|\$readmemb|\$readmemh|\$rewind|\$sformat|'
|
224
|
+
r'\$sformatf|\$sscanf|\$strobe|\$strobeb|\$strobeh|\$strobeo|'
|
225
|
+
r'\$swrite|\$swriteb|\$swriteh|\$swriteo|\$test|\$ungetc|'
|
226
|
+
r'\$value\$plusargs|\$write|\$writeb|\$writeh|\$writememb|'
|
227
|
+
r'\$writememh|\$writeo)\b' , Name.Builtin ),
|
228
|
+
|
95
229
|
(r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
|
96
|
-
(r'(byte|shortint|int|longint|
|
230
|
+
(r'(byte|shortint|int|longint|integer|time|'
|
97
231
|
r'bit|logic|reg|'
|
98
232
|
r'supply0|supply1|tri|triand|trior|tri0|tri1|trireg|uwire|wire|wand|wor'
|
99
233
|
r'shortreal|real|realtime)\b', Keyword.Type),
|
@@ -132,4 +266,92 @@ class VerilogLexer(RegexLexer):
|
|
132
266
|
token = Name.Constant
|
133
267
|
yield index, token, value
|
134
268
|
|
269
|
+
def analyse_text(text):
|
270
|
+
if text.startswith('//') or text.startswith('/*'):
|
271
|
+
return 0.5
|
272
|
+
|
273
|
+
|
274
|
+
class VhdlLexer(RegexLexer):
|
275
|
+
"""
|
276
|
+
For VHDL source code.
|
277
|
+
|
278
|
+
*New in Pygments 1.5.*
|
279
|
+
"""
|
280
|
+
name = 'vhdl'
|
281
|
+
aliases = ['vhdl']
|
282
|
+
filenames = ['*.vhdl', '*.vhd']
|
283
|
+
mimetypes = ['text/x-vhdl']
|
284
|
+
flags = re.MULTILINE | re.IGNORECASE
|
285
|
+
|
286
|
+
tokens = {
|
287
|
+
'root': [
|
288
|
+
(r'\n', Text),
|
289
|
+
(r'\s+', Text),
|
290
|
+
(r'\\\n', Text), # line continuation
|
291
|
+
(r'--(?![!#$%&*+./<=>?@\^|_~]).*?$', Comment.Single),
|
292
|
+
(r"'(U|X|0|1|Z|W|L|H|-)'", String.Char),
|
293
|
+
(r'[~!%^&*+=|?:<>/-]', Operator),
|
294
|
+
(r"'[a-zA-Z_][a-zA-Z0-9_]*", Name.Attribute),
|
295
|
+
(r'[()\[\],.;\']', Punctuation),
|
296
|
+
(r'"[^\n\\]*"', String),
|
297
|
+
|
298
|
+
(r'(library)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)',
|
299
|
+
bygroups(Keyword, Text, Name.Namespace)),
|
300
|
+
(r'(use)(\s+)(entity)', bygroups(Keyword, Text, Keyword)),
|
301
|
+
(r'(use)(\s+)([a-zA-Z_][\.a-zA-Z0-9_]*)',
|
302
|
+
bygroups(Keyword, Text, Name.Namespace)),
|
303
|
+
(r'(entity|component)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)',
|
304
|
+
bygroups(Keyword, Text, Name.Class)),
|
305
|
+
(r'(architecture|configuration)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)(\s+)'
|
306
|
+
r'(of)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)(\s+)(is)',
|
307
|
+
bygroups(Keyword, Text, Name.Class, Text, Keyword, Text,
|
308
|
+
Name.Class, Text, Keyword)),
|
309
|
+
|
310
|
+
(r'(end)(\s+)', bygroups(using(this), Text), 'endblock'),
|
311
|
+
|
312
|
+
include('types'),
|
313
|
+
include('keywords'),
|
314
|
+
include('numbers'),
|
135
315
|
|
316
|
+
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
|
317
|
+
],
|
318
|
+
'endblock': [
|
319
|
+
include('keywords'),
|
320
|
+
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class),
|
321
|
+
(r'(\s+)', Text),
|
322
|
+
(r';', Punctuation, '#pop'),
|
323
|
+
],
|
324
|
+
'types': [
|
325
|
+
(r'(boolean|bit|character|severity_level|integer|time|delay_length|'
|
326
|
+
r'natural|positive|string|bit_vector|file_open_kind|'
|
327
|
+
r'file_open_status|std_ulogic|std_ulogic_vector|std_logic|'
|
328
|
+
r'std_logic_vector)\b', Keyword.Type),
|
329
|
+
],
|
330
|
+
'keywords': [
|
331
|
+
(r'(abs|access|after|alias|all|and|'
|
332
|
+
r'architecture|array|assert|attribute|begin|block|'
|
333
|
+
r'body|buffer|bus|case|component|configuration|'
|
334
|
+
r'constant|disconnect|downto|else|elsif|end|'
|
335
|
+
r'entity|exit|file|for|function|generate|'
|
336
|
+
r'generic|group|guarded|if|impure|in|'
|
337
|
+
r'inertial|inout|is|label|library|linkage|'
|
338
|
+
r'literal|loop|map|mod|nand|new|'
|
339
|
+
r'next|nor|not|null|of|on|'
|
340
|
+
r'open|or|others|out|package|port|'
|
341
|
+
r'postponed|procedure|process|pure|range|record|'
|
342
|
+
r'register|reject|return|rol|ror|select|'
|
343
|
+
r'severity|signal|shared|sla|sli|sra|'
|
344
|
+
r'srl|subtype|then|to|transport|type|'
|
345
|
+
r'units|until|use|variable|wait|when|'
|
346
|
+
r'while|with|xnor|xor)\b', Keyword),
|
347
|
+
],
|
348
|
+
'numbers': [
|
349
|
+
(r'\d{1,2}#[0-9a-fA-F_]+#?', Number.Integer),
|
350
|
+
(r'[0-1_]+(\.[0-1_])', Number.Integer),
|
351
|
+
(r'\d+', Number.Integer),
|
352
|
+
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
|
353
|
+
(r'H"[0-9a-fA-F_]+"', Number.Oct),
|
354
|
+
(r'O"[0-7_]+"', Number.Oct),
|
355
|
+
(r'B"[0-1_]+"', Number.Oct),
|
356
|
+
],
|
357
|
+
}
|
@@ -0,0 +1,678 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
pygments.lexers.jvm
|
4
|
+
~~~~~~~~~~~~~~~~~~~
|
5
|
+
|
6
|
+
Pygments lexers for JVM languages.
|
7
|
+
|
8
|
+
:copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
|
9
|
+
:license: BSD, see LICENSE for details.
|
10
|
+
"""
|
11
|
+
|
12
|
+
import re
|
13
|
+
|
14
|
+
from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \
|
15
|
+
this
|
16
|
+
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
|
17
|
+
Number, Punctuation
|
18
|
+
|
19
|
+
|
20
|
+
__all__ = ['JavaLexer', 'ScalaLexer', 'GosuLexer', 'GosuTemplateLexer',
|
21
|
+
'GroovyLexer', 'IokeLexer', 'ClojureLexer']
|
22
|
+
|
23
|
+
|
24
|
+
class JavaLexer(RegexLexer):
|
25
|
+
"""
|
26
|
+
For `Java <http://www.sun.com/java/>`_ source code.
|
27
|
+
"""
|
28
|
+
|
29
|
+
name = 'Java'
|
30
|
+
aliases = ['java']
|
31
|
+
filenames = ['*.java']
|
32
|
+
mimetypes = ['text/x-java']
|
33
|
+
|
34
|
+
flags = re.MULTILINE | re.DOTALL
|
35
|
+
|
36
|
+
#: optional Comment or Whitespace
|
37
|
+
_ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
|
38
|
+
|
39
|
+
tokens = {
|
40
|
+
'root': [
|
41
|
+
# method names
|
42
|
+
(r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments
|
43
|
+
r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
|
44
|
+
r'(\s*)(\()', # signature start
|
45
|
+
bygroups(using(this), Name.Function, Text, Operator)),
|
46
|
+
(r'[^\S\n]+', Text),
|
47
|
+
(r'//.*?\n', Comment.Single),
|
48
|
+
(r'/\*.*?\*/', Comment.Multiline),
|
49
|
+
(r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator),
|
50
|
+
(r'(assert|break|case|catch|continue|default|do|else|finally|for|'
|
51
|
+
r'if|goto|instanceof|new|return|switch|this|throw|try|while)\b',
|
52
|
+
Keyword),
|
53
|
+
(r'(abstract|const|enum|extends|final|implements|native|private|'
|
54
|
+
r'protected|public|static|strictfp|super|synchronized|throws|'
|
55
|
+
r'transient|volatile)\b', Keyword.Declaration),
|
56
|
+
(r'(boolean|byte|char|double|float|int|long|short|void)\b',
|
57
|
+
Keyword.Type),
|
58
|
+
(r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
|
59
|
+
(r'(true|false|null)\b', Keyword.Constant),
|
60
|
+
(r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text), 'class'),
|
61
|
+
(r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
|
62
|
+
(r'"(\\\\|\\"|[^"])*"', String),
|
63
|
+
(r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
|
64
|
+
(r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)),
|
65
|
+
(r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label),
|
66
|
+
(r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
|
67
|
+
(r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator),
|
68
|
+
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
|
69
|
+
(r'0x[0-9a-f]+', Number.Hex),
|
70
|
+
(r'[0-9]+L?', Number.Integer),
|
71
|
+
(r'\n', Text)
|
72
|
+
],
|
73
|
+
'class': [
|
74
|
+
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
|
75
|
+
],
|
76
|
+
'import': [
|
77
|
+
(r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop')
|
78
|
+
],
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
class ScalaLexer(RegexLexer):
|
83
|
+
"""
|
84
|
+
For `Scala <http://www.scala-lang.org>`_ source code.
|
85
|
+
"""
|
86
|
+
|
87
|
+
name = 'Scala'
|
88
|
+
aliases = ['scala']
|
89
|
+
filenames = ['*.scala']
|
90
|
+
mimetypes = ['text/x-scala']
|
91
|
+
|
92
|
+
flags = re.MULTILINE | re.DOTALL
|
93
|
+
|
94
|
+
#: optional Comment or Whitespace
|
95
|
+
_ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
|
96
|
+
|
97
|
+
# don't use raw unicode strings!
|
98
|
+
op = u'[-~\\^\\*!%&\\\\<>\\|+=:/?@\u00a6-\u00a7\u00a9\u00ac\u00ae\u00b0-\u00b1\u00b6\u00d7\u00f7\u03f6\u0482\u0606-\u0608\u060e-\u060f\u06e9\u06fd-\u06fe\u07f6\u09fa\u0b70\u0bf3-\u0bf8\u0bfa\u0c7f\u0cf1-\u0cf2\u0d79\u0f01-\u0f03\u0f13-\u0f17\u0f1a-\u0f1f\u0f34\u0f36\u0f38\u0fbe-\u0fc5\u0fc7-\u0fcf\u109e-\u109f\u1360\u1390-\u1399\u1940\u19e0-\u19ff\u1b61-\u1b6a\u1b74-\u1b7c\u2044\u2052\u207a-\u207c\u208a-\u208c\u2100-\u2101\u2103-\u2106\u2108-\u2109\u2114\u2116-\u2118\u211e-\u2123\u2125\u2127\u2129\u212e\u213a-\u213b\u2140-\u2144\u214a-\u214d\u214f\u2190-\u2328\u232b-\u244a\u249c-\u24e9\u2500-\u2767\u2794-\u27c4\u27c7-\u27e5\u27f0-\u2982\u2999-\u29d7\u29dc-\u29fb\u29fe-\u2b54\u2ce5-\u2cea\u2e80-\u2ffb\u3004\u3012-\u3013\u3020\u3036-\u3037\u303e-\u303f\u3190-\u3191\u3196-\u319f\u31c0-\u31e3\u3200-\u321e\u322a-\u3250\u3260-\u327f\u328a-\u32b0\u32c0-\u33ff\u4dc0-\u4dff\ua490-\ua4c6\ua828-\ua82b\ufb29\ufdfd\ufe62\ufe64-\ufe66\uff0b\uff1c-\uff1e\uff5c\uff5e\uffe2\uffe4\uffe8-\uffee\ufffc-\ufffd]+'
|
99
|
+
|
100
|
+
letter = u'[a-zA-Z\\$_\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02af\u0370-\u0373\u0376-\u0377\u037b-\u037d\u0386\u0388-\u03f5\u03f7-\u0481\u048a-\u0556\u0561-\u0587\u05d0-\u05f2\u0621-\u063f\u0641-\u064a\u066e-\u066f\u0671-\u06d3\u06d5\u06ee-\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u0904-\u0939\u093d\u0950\u0958-\u0961\u0972-\u097f\u0985-\u09b9\u09bd\u09ce\u09dc-\u09e1\u09f0-\u09f1\u0a05-\u0a39\u0a59-\u0a5e\u0a72-\u0a74\u0a85-\u0ab9\u0abd\u0ad0-\u0ae1\u0b05-\u0b39\u0b3d\u0b5c-\u0b61\u0b71\u0b83-\u0bb9\u0bd0\u0c05-\u0c3d\u0c58-\u0c61\u0c85-\u0cb9\u0cbd\u0cde-\u0ce1\u0d05-\u0d3d\u0d60-\u0d61\u0d7a-\u0d7f\u0d85-\u0dc6\u0e01-\u0e30\u0e32-\u0e33\u0e40-\u0e45\u0e81-\u0eb0\u0eb2-\u0eb3\u0ebd-\u0ec4\u0edc-\u0f00\u0f40-\u0f6c\u0f88-\u0f8b\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065-\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10fa\u1100-\u135a\u1380-\u138f\u13a0-\u166c\u166f-\u1676\u1681-\u169a\u16a0-\u16ea\u16ee-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u1770\u1780-\u17b3\u17dc\u1820-\u1842\u1844-\u18a8\u18aa-\u191c\u1950-\u19a9\u19c1-\u19c7\u1a00-\u1a16\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae-\u1baf\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c77\u1d00-\u1d2b\u1d62-\u1d77\u1d79-\u1d9a\u1e00-\u1fbc\u1fbe\u1fc2-\u1fcc\u1fd0-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ffc\u2071\u207f\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c7c\u2c80-\u2ce4\u2d00-\u2d65\u2d80-\u2dde\u3006-\u3007\u3021-\u3029\u3038-\u303a\u303c\u3041-\u3096\u309f\u30a1-\u30fa\u30ff-\u318e\u31a0-\u31b7\u31f0-\u31ff\u3400-\u4db5\u4e00-\ua014\ua016-\ua48c\ua500-\ua60b\ua610-\ua61f\ua62a-\ua66e\ua680-\ua697\ua722-\ua76f\ua771-\ua787\ua78b-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua90a-\ua925\ua930-\ua946\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uac00-\ud7a3\uf900-\ufb1d\ufb1f-\ufb28\ufb2a-\ufd3d\ufd50-\ufdfb\ufe70-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uff6f\uff71-\uff9d\uffa0-\uffdc]'
|
101
|
+
|
102
|
+
upper = u'[A-Z\\$_\u00c0-\u00d6\u00d8-\u00de\u0100\u0102\u0104\u0106\u0108\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130\u0132\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a\u015c\u015e\u0160\u0162\u0164\u0166\u0168\u016a\u016c\u016e\u0170\u0172\u0174\u0176\u0178-\u0179\u017b\u017d\u0181-\u0182\u0184\u0186-\u0187\u0189-\u018b\u018e-\u0191\u0193-\u0194\u0196-\u0198\u019c-\u019d\u019f-\u01a0\u01a2\u01a4\u01a6-\u01a7\u01a9\u01ac\u01ae-\u01af\u01b1-\u01b3\u01b5\u01b7-\u01b8\u01bc\u01c4\u01c7\u01ca\u01cd\u01cf\u01d1\u01d3\u01d5\u01d7\u01d9\u01db\u01de\u01e0\u01e2\u01e4\u01e6\u01e8\u01ea\u01ec\u01ee\u01f1\u01f4\u01f6-\u01f8\u01fa\u01fc\u01fe\u0200\u0202\u0204\u0206\u0208\u020a\u020c\u020e\u0210\u0212\u0214\u0216\u0218\u021a\u021c\u021e\u0220\u0222\u0224\u0226\u0228\u022a\u022c\u022e\u0230\u0232\u023a-\u023b\u023d-\u023e\u0241\u0243-\u0246\u0248\u024a\u024c\u024e\u0370\u0372\u0376\u0386\u0388-\u038f\u0391-\u03ab\u03cf\u03d2-\u03d4\u03d8\u03da\u03dc\u03de\u03e0\u03e2\u03e4\u03e6\u03e8\u03ea\u03ec\u03ee\u03f4\u03f7\u03f9-\u03fa\u03fd-\u042f\u0460\u0462\u0464\u0466\u0468\u046a\u046c\u046e\u0470\u0472\u0474\u0476\u0478\u047a\u047c\u047e\u0480\u048a\u048c\u048e\u0490\u0492\u0494\u0496\u0498\u049a\u049c\u049e\u04a0\u04a2\u04a4\u04a6\u04a8\u04aa\u04ac\u04ae\u04b0\u04b2\u04b4\u04b6\u04b8\u04ba\u04bc\u04be\u04c0-\u04c1\u04c3\u04c5\u04c7\u04c9\u04cb\u04cd\u04d0\u04d2\u04d4\u04d6\u04d8\u04da\u04dc\u04de\u04e0\u04e2\u04e4\u04e6\u04e8\u04ea\u04ec\u04ee\u04f0\u04f2\u04f4\u04f6\u04f8\u04fa\u04fc\u04fe\u0500\u0502\u0504\u0506\u0508\u050a\u050c\u050e\u0510\u0512\u0514\u0516\u0518\u051a\u051c\u051e\u0520\u0522\u0531-\u0556\u10a0-\u10c5\u1e00\u1e02\u1e04\u1e06\u1e08\u1e0a\u1e0c\u1e0e\u1e10\u1e12\u1e14\u1e16\u1e18\u1e1a\u1e1c\u1e1e\u1e20\u1e22\u1e24\u1e26\u1e28\u1e2a\u1e2c\u1e2e\u1e30\u1e32\u1e34\u1e36\u1e38\u1e3a\u1e3c\u1e3e\u1e40\u1e42\u1e44\u1e46\u1e48\u1e4a\u1e4c\u1e4e\u1e50\u1e52\u1e54\u1e56\u1e58\u1e5a\u1e5c\u1e5e\u1e60\u1e62\u1e64\u1e66\u1e68\u1e6a\u1e6c\u1e6e\u1e70\u1e72\u1e74\u1e76\u1e78\u1e7a\u1e7c\u1e7e\u1e80\u1e82\u1e84\u1e86\u1e88\u1e8a\u1e8c\u1e8e\u1e90\u1e92\u1e94\u1e9e\u1ea0\u1ea2\u1ea4\u1ea6\u1ea8\u1eaa\u1eac\u1eae\u1eb0\u1eb2\u1eb4\u1eb6\u1eb8\u1eba\u1ebc\u1ebe\u1ec0\u1ec2\u1ec4\u1ec6\u1ec8\u1eca\u1ecc\u1ece\u1ed0\u1ed2\u1ed4\u1ed6\u1ed8\u1eda\u1edc\u1ede\u1ee0\u1ee2\u1ee4\u1ee6\u1ee8\u1eea\u1eec\u1eee\u1ef0\u1ef2\u1ef4\u1ef6\u1ef8\u1efa\u1efc\u1efe\u1f08-\u1f0f\u1f18-\u1f1d\u1f28-\u1f2f\u1f38-\u1f3f\u1f48-\u1f4d\u1f59-\u1f5f\u1f68-\u1f6f\u1fb8-\u1fbb\u1fc8-\u1fcb\u1fd8-\u1fdb\u1fe8-\u1fec\u1ff8-\u1ffb\u2102\u2107\u210b-\u210d\u2110-\u2112\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u2130-\u2133\u213e-\u213f\u2145\u2183\u2c00-\u2c2e\u2c60\u2c62-\u2c64\u2c67\u2c69\u2c6b\u2c6d-\u2c6f\u2c72\u2c75\u2c80\u2c82\u2c84\u2c86\u2c88\u2c8a\u2c8c\u2c8e\u2c90\u2c92\u2c94\u2c96\u2c98\u2c9a\u2c9c\u2c9e\u2ca0\u2ca2\u2ca4\u2ca6\u2ca8\u2caa\u2cac\u2cae\u2cb0\u2cb2\u2cb4\u2cb6\u2cb8\u2cba\u2cbc\u2cbe\u2cc0\u2cc2\u2cc4\u2cc6\u2cc8\u2cca\u2ccc\u2cce\u2cd0\u2cd2\u2cd4\u2cd6\u2cd8\u2cda\u2cdc\u2cde\u2ce0\u2ce2\ua640\ua642\ua644\ua646\ua648\ua64a\ua64c\ua64e\ua650\ua652\ua654\ua656\ua658\ua65a\ua65c\ua65e\ua662\ua664\ua666\ua668\ua66a\ua66c\ua680\ua682\ua684\ua686\ua688\ua68a\ua68c\ua68e\ua690\ua692\ua694\ua696\ua722\ua724\ua726\ua728\ua72a\ua72c\ua72e\ua732\ua734\ua736\ua738\ua73a\ua73c\ua73e\ua740\ua742\ua744\ua746\ua748\ua74a\ua74c\ua74e\ua750\ua752\ua754\ua756\ua758\ua75a\ua75c\ua75e\ua760\ua762\ua764\ua766\ua768\ua76a\ua76c\ua76e\ua779\ua77b\ua77d-\ua77e\ua780\ua782\ua784\ua786\ua78b\uff21-\uff3a]'
|
103
|
+
|
104
|
+
idrest = ur'%s(?:%s|[0-9])*(?:(?<=_)%s)?' % (letter, letter, op)
|
105
|
+
|
106
|
+
tokens = {
|
107
|
+
'root': [
|
108
|
+
# method names
|
109
|
+
(r'(class|trait|object)(\s+)', bygroups(Keyword, Text), 'class'),
|
110
|
+
(ur"'%s" % idrest, Text.Symbol),
|
111
|
+
(r'[^\S\n]+', Text),
|
112
|
+
(r'//.*?\n', Comment.Single),
|
113
|
+
(r'/\*', Comment.Multiline, 'comment'),
|
114
|
+
(ur'@%s' % idrest, Name.Decorator),
|
115
|
+
(ur'(abstract|ca(?:se|tch)|d(?:ef|o)|e(?:lse|xtends)|'
|
116
|
+
ur'f(?:inal(?:ly)?|or(?:Some)?)|i(?:f|mplicit)|'
|
117
|
+
ur'lazy|match|new|override|pr(?:ivate|otected)'
|
118
|
+
ur'|re(?:quires|turn)|s(?:ealed|uper)|'
|
119
|
+
ur't(?:h(?:is|row)|ry)|va[lr]|w(?:hile|ith)|yield)\b|'
|
120
|
+
u'(<[%:-]|=>|>:|[#=@_\u21D2\u2190])(\b|(?=\\s)|$)', Keyword),
|
121
|
+
(ur':(?!%s)' % op, Keyword, 'type'),
|
122
|
+
(ur'%s%s\b' % (upper, idrest), Name.Class),
|
123
|
+
(r'(true|false|null)\b', Keyword.Constant),
|
124
|
+
(r'(import|package)(\s+)', bygroups(Keyword, Text), 'import'),
|
125
|
+
(r'(type)(\s+)', bygroups(Keyword, Text), 'type'),
|
126
|
+
(r'""".*?"""', String),
|
127
|
+
(r'"(\\\\|\\"|[^"])*"', String),
|
128
|
+
(ur"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
|
129
|
+
# (ur'(\.)(%s|%s|`[^`]+`)' % (idrest, op), bygroups(Operator,
|
130
|
+
# Name.Attribute)),
|
131
|
+
(idrest, Name),
|
132
|
+
(r'`[^`]+`', Name),
|
133
|
+
(r'\[', Operator, 'typeparam'),
|
134
|
+
(r'[\(\)\{\};,.#]', Operator),
|
135
|
+
(op, Operator),
|
136
|
+
(ur'([0-9][0-9]*\.[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?',
|
137
|
+
Number.Float),
|
138
|
+
(r'0x[0-9a-f]+', Number.Hex),
|
139
|
+
(r'[0-9]+L?', Number.Integer),
|
140
|
+
(r'\n', Text)
|
141
|
+
],
|
142
|
+
'class': [
|
143
|
+
(ur'(%s|%s|`[^`]+`)(\s*)(\[)' % (idrest, op),
|
144
|
+
bygroups(Name.Class, Text, Operator), 'typeparam'),
|
145
|
+
(r'[\s\n]+', Text),
|
146
|
+
(r'{', Operator, '#pop'),
|
147
|
+
(r'\(', Operator, '#pop'),
|
148
|
+
(r'//.*?\n', Comment.Single, '#pop'),
|
149
|
+
(ur'%s|%s|`[^`]+`' % (idrest, op), Name.Class, '#pop'),
|
150
|
+
],
|
151
|
+
'type': [
|
152
|
+
(r'\s+', Text),
|
153
|
+
(u'<[%:]|>:|[#_\u21D2]|forSome|type', Keyword),
|
154
|
+
(r'([,\);}]|=>|=)([\s\n]*)', bygroups(Operator, Text), '#pop'),
|
155
|
+
(r'[\(\{]', Operator, '#push'),
|
156
|
+
(ur'((?:%s|%s|`[^`]+`)(?:\.(?:%s|%s|`[^`]+`))*)(\s*)(\[)' %
|
157
|
+
(idrest, op, idrest, op),
|
158
|
+
bygroups(Keyword.Type, Text, Operator), ('#pop', 'typeparam')),
|
159
|
+
(ur'((?:%s|%s|`[^`]+`)(?:\.(?:%s|%s|`[^`]+`))*)(\s*)$' %
|
160
|
+
(idrest, op, idrest, op),
|
161
|
+
bygroups(Keyword.Type, Text), '#pop'),
|
162
|
+
(r'//.*?\n', Comment.Single, '#pop'),
|
163
|
+
(ur'\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type)
|
164
|
+
],
|
165
|
+
'typeparam': [
|
166
|
+
(r'[\s\n,]+', Text),
|
167
|
+
(u'<[%:]|=>|>:|[#_\u21D2]|forSome|type', Keyword),
|
168
|
+
(r'([\]\)\}])', Operator, '#pop'),
|
169
|
+
(r'[\(\[\{]', Operator, '#push'),
|
170
|
+
(ur'\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type)
|
171
|
+
],
|
172
|
+
'comment': [
|
173
|
+
(r'[^/\*]+', Comment.Multiline),
|
174
|
+
(r'/\*', Comment.Multiline, '#push'),
|
175
|
+
(r'\*/', Comment.Multiline, '#pop'),
|
176
|
+
(r'[*/]', Comment.Multiline)
|
177
|
+
],
|
178
|
+
'import': [
|
179
|
+
(ur'(%s|\.)+' % idrest, Name.Namespace, '#pop')
|
180
|
+
],
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
class GosuLexer(RegexLexer):
|
185
|
+
"""
|
186
|
+
For Gosu source code.
|
187
|
+
|
188
|
+
*New in Pygments 1.5.*
|
189
|
+
"""
|
190
|
+
|
191
|
+
name = 'Gosu'
|
192
|
+
aliases = ['gosu']
|
193
|
+
filenames = ['*.gs', '*.gsx', '*.gsp', '*.vark']
|
194
|
+
mimetypes = ['text/x-gosu']
|
195
|
+
|
196
|
+
flags = re.MULTILINE | re.DOTALL
|
197
|
+
|
198
|
+
#: optional Comment or Whitespace
|
199
|
+
_ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
|
200
|
+
|
201
|
+
tokens = {
|
202
|
+
'root': [
|
203
|
+
# method names
|
204
|
+
(r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # modifiers etc.
|
205
|
+
r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
|
206
|
+
r'(\s*)(\()', # signature start
|
207
|
+
bygroups(using(this), Name.Function, Text, Operator)),
|
208
|
+
(r'[^\S\n]+', Text),
|
209
|
+
(r'//.*?\n', Comment.Single),
|
210
|
+
(r'/\*.*?\*/', Comment.Multiline),
|
211
|
+
(r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator),
|
212
|
+
(r'(in|as|typeof|statictypeof|typeis|typeas|if|else|foreach|for|'
|
213
|
+
r'index|while|do|continue|break|return|try|catch|finally|this|'
|
214
|
+
r'throw|new|switch|case|default|eval|super|outer|classpath|'
|
215
|
+
r'using)\b', Keyword),
|
216
|
+
(r'(var|delegate|construct|function|private|internal|protected|'
|
217
|
+
r'public|abstract|override|final|static|extends|transient|'
|
218
|
+
r'implements|represents|readonly)\b', Keyword.Declaration),
|
219
|
+
(r'(property\s+)(get|set|)', Keyword.Declaration),
|
220
|
+
(r'(boolean|byte|char|double|float|int|long|short|void|block)\b',
|
221
|
+
Keyword.Type),
|
222
|
+
(r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
|
223
|
+
(r'(true|false|null|NaN|Infinity)\b', Keyword.Constant),
|
224
|
+
(r'(class|interface|enhancement|enum)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)',
|
225
|
+
bygroups(Keyword.Declaration, Text, Name.Class)),
|
226
|
+
(r'(uses)(\s+)([a-zA-Z0-9_.]+\*?)',
|
227
|
+
bygroups(Keyword.Namespace, Text, Name.Namespace)),
|
228
|
+
(r'"', String, 'string'),
|
229
|
+
(r'(\??[\.#])([a-zA-Z_][a-zA-Z0-9_]*)',
|
230
|
+
bygroups(Operator, Name.Attribute)),
|
231
|
+
(r'(:)([a-zA-Z_][a-zA-Z0-9_]*)',
|
232
|
+
bygroups(Operator, Name.Attribute)),
|
233
|
+
(r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
|
234
|
+
(r'and|or|not|[\\~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator),
|
235
|
+
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
|
236
|
+
(r'[0-9]+', Number.Integer),
|
237
|
+
(r'\n', Text)
|
238
|
+
],
|
239
|
+
'templateText': [
|
240
|
+
(r'(\\<)|(\\\$)', String),
|
241
|
+
(r'(<%@\s+)(extends|params)',
|
242
|
+
bygroups(Operator, Name.Decorator), 'stringTemplate'),
|
243
|
+
(r'<%!--.*?--%>', Comment.Multiline),
|
244
|
+
(r'(<%)|(<%=)', Operator, 'stringTemplate'),
|
245
|
+
(r'\$\{', Operator, 'stringTemplateShorthand'),
|
246
|
+
(r'.', String)
|
247
|
+
],
|
248
|
+
'string': [
|
249
|
+
(r'"', String, '#pop'),
|
250
|
+
include('templateText')
|
251
|
+
],
|
252
|
+
'stringTemplate': [
|
253
|
+
(r'"', String, 'string'),
|
254
|
+
(r'%>', Operator, '#pop'),
|
255
|
+
include('root')
|
256
|
+
],
|
257
|
+
'stringTemplateShorthand': [
|
258
|
+
(r'"', String, 'string'),
|
259
|
+
(r'\{', Operator, 'stringTemplateShorthand'),
|
260
|
+
(r'\}', Operator, '#pop'),
|
261
|
+
include('root')
|
262
|
+
],
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
class GosuTemplateLexer(Lexer):
|
267
|
+
"""
|
268
|
+
For Gosu templates.
|
269
|
+
|
270
|
+
*New in Pygments 1.5.*
|
271
|
+
"""
|
272
|
+
|
273
|
+
name = 'Gosu Template'
|
274
|
+
aliases = ['gst']
|
275
|
+
filenames = ['*.gst']
|
276
|
+
mimetypes = ['text/x-gosu-template']
|
277
|
+
lexer = GosuLexer()
|
278
|
+
|
279
|
+
def get_tokens_unprocessed(self, text):
|
280
|
+
stack = ['templateText']
|
281
|
+
for item in self.lexer.get_tokens_unprocessed(text, stack):
|
282
|
+
yield item
|
283
|
+
|
284
|
+
|
285
|
+
class GroovyLexer(RegexLexer):
|
286
|
+
"""
|
287
|
+
For `Groovy <http://groovy.codehaus.org/>`_ source code.
|
288
|
+
|
289
|
+
*New in Pygments 1.5.*
|
290
|
+
"""
|
291
|
+
|
292
|
+
name = 'Groovy'
|
293
|
+
aliases = ['groovy']
|
294
|
+
filenames = ['*.groovy']
|
295
|
+
mimetypes = ['text/x-groovy']
|
296
|
+
|
297
|
+
flags = re.MULTILINE | re.DOTALL
|
298
|
+
|
299
|
+
#: optional Comment or Whitespace
|
300
|
+
_ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
|
301
|
+
|
302
|
+
tokens = {
|
303
|
+
'root': [
|
304
|
+
# method names
|
305
|
+
(r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments
|
306
|
+
r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
|
307
|
+
r'(\s*)(\()', # signature start
|
308
|
+
bygroups(using(this), Name.Function, Text, Operator)),
|
309
|
+
(r'[^\S\n]+', Text),
|
310
|
+
(r'//.*?\n', Comment.Single),
|
311
|
+
(r'/\*.*?\*/', Comment.Multiline),
|
312
|
+
(r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator),
|
313
|
+
(r'(assert|break|case|catch|continue|default|do|else|finally|for|'
|
314
|
+
r'if|goto|instanceof|new|return|switch|this|throw|try|while|in|as)\b',
|
315
|
+
Keyword),
|
316
|
+
(r'(abstract|const|enum|extends|final|implements|native|private|'
|
317
|
+
r'protected|public|static|strictfp|super|synchronized|throws|'
|
318
|
+
r'transient|volatile)\b', Keyword.Declaration),
|
319
|
+
(r'(def|boolean|byte|char|double|float|int|long|short|void)\b',
|
320
|
+
Keyword.Type),
|
321
|
+
(r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
|
322
|
+
(r'(true|false|null)\b', Keyword.Constant),
|
323
|
+
(r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text),
|
324
|
+
'class'),
|
325
|
+
(r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
|
326
|
+
(r'"(\\\\|\\"|[^"])*"', String.Double),
|
327
|
+
(r"'(\\\\|\\'|[^'])*'", String.Single),
|
328
|
+
(r'\$/((?!/\$).)*/\$', String),
|
329
|
+
(r'/(\\\\|\\"|[^/])*/', String),
|
330
|
+
(r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
|
331
|
+
(r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)),
|
332
|
+
(r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label),
|
333
|
+
(r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
|
334
|
+
(r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator),
|
335
|
+
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
|
336
|
+
(r'0x[0-9a-f]+', Number.Hex),
|
337
|
+
(r'[0-9]+L?', Number.Integer),
|
338
|
+
(r'\n', Text)
|
339
|
+
],
|
340
|
+
'class': [
|
341
|
+
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
|
342
|
+
],
|
343
|
+
'import': [
|
344
|
+
(r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop')
|
345
|
+
],
|
346
|
+
}
|
347
|
+
|
348
|
+
|
349
|
+
class IokeLexer(RegexLexer):
|
350
|
+
"""
|
351
|
+
For `Ioke <http://ioke.org/>`_ (a strongly typed, dynamic,
|
352
|
+
prototype based programming language) source.
|
353
|
+
|
354
|
+
*New in Pygments 1.4.*
|
355
|
+
"""
|
356
|
+
name = 'Ioke'
|
357
|
+
filenames = ['*.ik']
|
358
|
+
aliases = ['ioke', 'ik']
|
359
|
+
mimetypes = ['text/x-iokesrc']
|
360
|
+
tokens = {
|
361
|
+
'interpolatableText': [
|
362
|
+
(r'(\\b|\\e|\\t|\\n|\\f|\\r|\\"|\\\\|\\#|\\\Z|\\u[0-9a-fA-F]{1,4}'
|
363
|
+
r'|\\[0-3]?[0-7]?[0-7])', String.Escape),
|
364
|
+
(r'#{', Punctuation, 'textInterpolationRoot')
|
365
|
+
],
|
366
|
+
|
367
|
+
'text': [
|
368
|
+
(r'(?<!\\)"', String, '#pop'),
|
369
|
+
include('interpolatableText'),
|
370
|
+
(r'[^"]', String)
|
371
|
+
],
|
372
|
+
|
373
|
+
'documentation': [
|
374
|
+
(r'(?<!\\)"', String.Doc, '#pop'),
|
375
|
+
include('interpolatableText'),
|
376
|
+
(r'[^"]', String.Doc)
|
377
|
+
],
|
378
|
+
|
379
|
+
'textInterpolationRoot': [
|
380
|
+
(r'}', Punctuation, '#pop'),
|
381
|
+
include('root')
|
382
|
+
],
|
383
|
+
|
384
|
+
'slashRegexp': [
|
385
|
+
(r'(?<!\\)/[oxpniums]*', String.Regex, '#pop'),
|
386
|
+
include('interpolatableText'),
|
387
|
+
(r'\\/', String.Regex),
|
388
|
+
(r'[^/]', String.Regex)
|
389
|
+
],
|
390
|
+
|
391
|
+
'squareRegexp': [
|
392
|
+
(r'(?<!\\)][oxpniums]*', String.Regex, '#pop'),
|
393
|
+
include('interpolatableText'),
|
394
|
+
(r'\\]', String.Regex),
|
395
|
+
(r'[^\]]', String.Regex)
|
396
|
+
],
|
397
|
+
|
398
|
+
'squareText': [
|
399
|
+
(r'(?<!\\)]', String, '#pop'),
|
400
|
+
include('interpolatableText'),
|
401
|
+
(r'[^\]]', String)
|
402
|
+
],
|
403
|
+
|
404
|
+
'root': [
|
405
|
+
(r'\n', Text),
|
406
|
+
(r'\s+', Text),
|
407
|
+
|
408
|
+
# Comments
|
409
|
+
(r';(.*?)\n', Comment),
|
410
|
+
(r'\A#!(.*?)\n', Comment),
|
411
|
+
|
412
|
+
#Regexps
|
413
|
+
(r'#/', String.Regex, 'slashRegexp'),
|
414
|
+
(r'#r\[', String.Regex, 'squareRegexp'),
|
415
|
+
|
416
|
+
#Symbols
|
417
|
+
(r':[a-zA-Z0-9_!:?]+', String.Symbol),
|
418
|
+
(r'[a-zA-Z0-9_!:?]+:(?![a-zA-Z0-9_!?])', String.Other),
|
419
|
+
(r':"(\\\\|\\"|[^"])*"', String.Symbol),
|
420
|
+
|
421
|
+
#Documentation
|
422
|
+
(r'((?<=fn\()|(?<=fnx\()|(?<=method\()|(?<=macro\()|(?<=lecro\()'
|
423
|
+
r'|(?<=syntax\()|(?<=dmacro\()|(?<=dlecro\()|(?<=dlecrox\()'
|
424
|
+
r'|(?<=dsyntax\())[\s\n\r]*"', String.Doc, 'documentation'),
|
425
|
+
|
426
|
+
#Text
|
427
|
+
(r'"', String, 'text'),
|
428
|
+
(r'#\[', String, 'squareText'),
|
429
|
+
|
430
|
+
#Mimic
|
431
|
+
(r'[a-zA-Z0-9_][a-zA-Z0-9!?_:]+(?=\s*=.*mimic\s)', Name.Entity),
|
432
|
+
|
433
|
+
#Assignment
|
434
|
+
(r'[a-zA-Z_][a-zA-Z0-9_!:?]*(?=[\s]*[+*/-]?=[^=].*($|\.))',
|
435
|
+
Name.Variable),
|
436
|
+
|
437
|
+
# keywords
|
438
|
+
(r'(break|cond|continue|do|ensure|for|for:dict|for:set|if|let|'
|
439
|
+
r'loop|p:for|p:for:dict|p:for:set|return|unless|until|while|'
|
440
|
+
r'with)(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
|
441
|
+
|
442
|
+
# Origin
|
443
|
+
(r'(eval|mimic|print|println)(?![a-zA-Z0-9!:_?])', Keyword),
|
444
|
+
|
445
|
+
# Base
|
446
|
+
(r'(cell\?|cellNames|cellOwner\?|cellOwner|cells|cell|'
|
447
|
+
r'documentation|hash|identity|mimic|removeCell\!|undefineCell\!)'
|
448
|
+
r'(?![a-zA-Z0-9!:_?])', Keyword),
|
449
|
+
|
450
|
+
# Ground
|
451
|
+
(r'(stackTraceAsText)(?![a-zA-Z0-9!:_?])', Keyword),
|
452
|
+
|
453
|
+
#DefaultBehaviour Literals
|
454
|
+
(r'(dict|list|message|set)(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
|
455
|
+
|
456
|
+
#DefaultBehaviour Case
|
457
|
+
(r'(case|case:and|case:else|case:nand|case:nor|case:not|case:or|'
|
458
|
+
r'case:otherwise|case:xor)(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
|
459
|
+
|
460
|
+
#DefaultBehaviour Reflection
|
461
|
+
(r'(asText|become\!|derive|freeze\!|frozen\?|in\?|is\?|kind\?|'
|
462
|
+
r'mimic\!|mimics|mimics\?|prependMimic\!|removeAllMimics\!|'
|
463
|
+
r'removeMimic\!|same\?|send|thaw\!|uniqueHexId)'
|
464
|
+
r'(?![a-zA-Z0-9!:_?])', Keyword),
|
465
|
+
|
466
|
+
#DefaultBehaviour Aspects
|
467
|
+
(r'(after|around|before)(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
|
468
|
+
|
469
|
+
# DefaultBehaviour
|
470
|
+
(r'(kind|cellDescriptionDict|cellSummary|genSym|inspect|notice)'
|
471
|
+
r'(?![a-zA-Z0-9!:_?])', Keyword),
|
472
|
+
(r'(use|destructuring)', Keyword.Reserved),
|
473
|
+
|
474
|
+
#DefaultBehavior BaseBehavior
|
475
|
+
(r'(cell\?|cellOwner\?|cellOwner|cellNames|cells|cell|'
|
476
|
+
r'documentation|identity|removeCell!|undefineCell)'
|
477
|
+
r'(?![a-zA-Z0-9!:_?])', Keyword),
|
478
|
+
|
479
|
+
#DefaultBehavior Internal
|
480
|
+
(r'(internal:compositeRegexp|internal:concatenateText|'
|
481
|
+
r'internal:createDecimal|internal:createNumber|'
|
482
|
+
r'internal:createRegexp|internal:createText)'
|
483
|
+
r'(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
|
484
|
+
|
485
|
+
#DefaultBehaviour Conditions
|
486
|
+
(r'(availableRestarts|bind|error\!|findRestart|handle|'
|
487
|
+
r'invokeRestart|rescue|restart|signal\!|warn\!)'
|
488
|
+
r'(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
|
489
|
+
|
490
|
+
# constants
|
491
|
+
(r'(nil|false|true)(?![a-zA-Z0-9!:_?])', Name.Constant),
|
492
|
+
|
493
|
+
# names
|
494
|
+
(r'(Arity|Base|Call|Condition|DateTime|Aspects|Pointcut|'
|
495
|
+
r'Assignment|BaseBehavior|Boolean|Case|AndCombiner|Else|'
|
496
|
+
r'NAndCombiner|NOrCombiner|NotCombiner|OrCombiner|XOrCombiner|'
|
497
|
+
r'Conditions|Definitions|FlowControl|Internal|Literals|'
|
498
|
+
r'Reflection|DefaultMacro|DefaultMethod|DefaultSyntax|Dict|'
|
499
|
+
r'FileSystem|Ground|Handler|Hook|IO|IokeGround|Struct|'
|
500
|
+
r'LexicalBlock|LexicalMacro|List|Message|Method|Mixins|'
|
501
|
+
r'NativeMethod|Number|Origin|Pair|Range|Reflector|Regexp Match|'
|
502
|
+
r'Regexp|Rescue|Restart|Runtime|Sequence|Set|Symbol|'
|
503
|
+
r'System|Text|Tuple)(?![a-zA-Z0-9!:_?])', Name.Builtin),
|
504
|
+
|
505
|
+
# functions
|
506
|
+
(ur'(generateMatchMethod|aliasMethod|\u03bb|\u028E|fnx|fn|method|'
|
507
|
+
ur'dmacro|dlecro|syntax|macro|dlecrox|lecrox|lecro|syntax)'
|
508
|
+
ur'(?![a-zA-Z0-9!:_?])', Name.Function),
|
509
|
+
|
510
|
+
# Numbers
|
511
|
+
(r'-?0[xX][0-9a-fA-F]+', Number.Hex),
|
512
|
+
(r'-?(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
|
513
|
+
(r'-?\d+', Number.Integer),
|
514
|
+
|
515
|
+
(r'#\(', Punctuation),
|
516
|
+
|
517
|
+
# Operators
|
518
|
+
(ur'(&&>>|\|\|>>|\*\*>>|:::|::|\.\.\.|===|\*\*>|\*\*=|&&>|&&=|'
|
519
|
+
ur'\|\|>|\|\|=|\->>|\+>>|!>>|<>>>|<>>|&>>|%>>|#>>|@>>|/>>|\*>>|'
|
520
|
+
ur'\?>>|\|>>|\^>>|~>>|\$>>|=>>|<<=|>>=|<=>|<\->|=~|!~|=>|\+\+|'
|
521
|
+
ur'\-\-|<=|>=|==|!=|&&|\.\.|\+=|\-=|\*=|\/=|%=|&=|\^=|\|=|<\-|'
|
522
|
+
ur'\+>|!>|<>|&>|%>|#>|\@>|\/>|\*>|\?>|\|>|\^>|~>|\$>|<\->|\->|'
|
523
|
+
ur'<<|>>|\*\*|\?\||\?&|\|\||>|<|\*|\/|%|\+|\-|&|\^|\||=|\$|!|~|'
|
524
|
+
ur'\?|#|\u2260|\u2218|\u2208|\u2209)', Operator),
|
525
|
+
(r'(and|nand|or|xor|nor|return|import)(?![a-zA-Z0-9_!?])',
|
526
|
+
Operator),
|
527
|
+
|
528
|
+
# Punctuation
|
529
|
+
(r'(\`\`|\`|\'\'|\'|\.|\,|@|@@|\[|\]|\(|\)|{|})', Punctuation),
|
530
|
+
|
531
|
+
#kinds
|
532
|
+
(r'[A-Z][a-zA-Z0-9_!:?]*', Name.Class),
|
533
|
+
|
534
|
+
#default cellnames
|
535
|
+
(r'[a-z_][a-zA-Z0-9_!:?]*', Name)
|
536
|
+
]
|
537
|
+
}
|
538
|
+
|
539
|
+
|
540
|
+
class ClojureLexer(RegexLexer):
|
541
|
+
"""
|
542
|
+
Lexer for `Clojure <http://clojure.org/>`_ source code.
|
543
|
+
|
544
|
+
*New in Pygments 0.11.*
|
545
|
+
"""
|
546
|
+
name = 'Clojure'
|
547
|
+
aliases = ['clojure', 'clj']
|
548
|
+
filenames = ['*.clj']
|
549
|
+
mimetypes = ['text/x-clojure', 'application/x-clojure']
|
550
|
+
|
551
|
+
special_forms = [
|
552
|
+
'.', 'def', 'do', 'fn', 'if', 'let', 'new', 'quote', 'var', 'loop'
|
553
|
+
]
|
554
|
+
|
555
|
+
# It's safe to consider 'ns' a declaration thing because it defines a new
|
556
|
+
# namespace.
|
557
|
+
declarations = [
|
558
|
+
'def-', 'defn', 'defn-', 'defmacro', 'defmulti', 'defmethod',
|
559
|
+
'defstruct', 'defonce', 'declare', 'definline', 'definterface',
|
560
|
+
'defprotocol', 'defrecord', 'deftype', 'defproject', 'ns'
|
561
|
+
]
|
562
|
+
|
563
|
+
builtins = [
|
564
|
+
'*', '+', '-', '->', '/', '<', '<=', '=', '==', '>', '>=', '..',
|
565
|
+
'accessor', 'agent', 'agent-errors', 'aget', 'alength', 'all-ns',
|
566
|
+
'alter', 'and', 'append-child', 'apply', 'array-map', 'aset',
|
567
|
+
'aset-boolean', 'aset-byte', 'aset-char', 'aset-double', 'aset-float',
|
568
|
+
'aset-int', 'aset-long', 'aset-short', 'assert', 'assoc', 'await',
|
569
|
+
'await-for', 'bean', 'binding', 'bit-and', 'bit-not', 'bit-or',
|
570
|
+
'bit-shift-left', 'bit-shift-right', 'bit-xor', 'boolean', 'branch?',
|
571
|
+
'butlast', 'byte', 'cast', 'char', 'children', 'class',
|
572
|
+
'clear-agent-errors', 'comment', 'commute', 'comp', 'comparator',
|
573
|
+
'complement', 'concat', 'conj', 'cons', 'constantly', 'cond', 'if-not',
|
574
|
+
'construct-proxy', 'contains?', 'count', 'create-ns', 'create-struct',
|
575
|
+
'cycle', 'dec', 'deref', 'difference', 'disj', 'dissoc', 'distinct',
|
576
|
+
'doall', 'doc', 'dorun', 'doseq', 'dosync', 'dotimes', 'doto',
|
577
|
+
'double', 'down', 'drop', 'drop-while', 'edit', 'end?', 'ensure',
|
578
|
+
'eval', 'every?', 'false?', 'ffirst', 'file-seq', 'filter', 'find',
|
579
|
+
'find-doc', 'find-ns', 'find-var', 'first', 'float', 'flush', 'for',
|
580
|
+
'fnseq', 'frest', 'gensym', 'get-proxy-class', 'get',
|
581
|
+
'hash-map', 'hash-set', 'identical?', 'identity', 'if-let', 'import',
|
582
|
+
'in-ns', 'inc', 'index', 'insert-child', 'insert-left', 'insert-right',
|
583
|
+
'inspect-table', 'inspect-tree', 'instance?', 'int', 'interleave',
|
584
|
+
'intersection', 'into', 'into-array', 'iterate', 'join', 'key', 'keys',
|
585
|
+
'keyword', 'keyword?', 'last', 'lazy-cat', 'lazy-cons', 'left',
|
586
|
+
'lefts', 'line-seq', 'list*', 'list', 'load', 'load-file',
|
587
|
+
'locking', 'long', 'loop', 'macroexpand', 'macroexpand-1',
|
588
|
+
'make-array', 'make-node', 'map', 'map-invert', 'map?', 'mapcat',
|
589
|
+
'max', 'max-key', 'memfn', 'merge', 'merge-with', 'meta', 'min',
|
590
|
+
'min-key', 'name', 'namespace', 'neg?', 'new', 'newline', 'next',
|
591
|
+
'nil?', 'node', 'not', 'not-any?', 'not-every?', 'not=', 'ns-imports',
|
592
|
+
'ns-interns', 'ns-map', 'ns-name', 'ns-publics', 'ns-refers',
|
593
|
+
'ns-resolve', 'ns-unmap', 'nth', 'nthrest', 'or', 'parse', 'partial',
|
594
|
+
'path', 'peek', 'pop', 'pos?', 'pr', 'pr-str', 'print', 'print-str',
|
595
|
+
'println', 'println-str', 'prn', 'prn-str', 'project', 'proxy',
|
596
|
+
'proxy-mappings', 'quot', 'rand', 'rand-int', 'range', 're-find',
|
597
|
+
're-groups', 're-matcher', 're-matches', 're-pattern', 're-seq',
|
598
|
+
'read', 'read-line', 'reduce', 'ref', 'ref-set', 'refer', 'rem',
|
599
|
+
'remove', 'remove-method', 'remove-ns', 'rename', 'rename-keys',
|
600
|
+
'repeat', 'replace', 'replicate', 'resolve', 'rest', 'resultset-seq',
|
601
|
+
'reverse', 'rfirst', 'right', 'rights', 'root', 'rrest', 'rseq',
|
602
|
+
'second', 'select', 'select-keys', 'send', 'send-off', 'seq',
|
603
|
+
'seq-zip', 'seq?', 'set', 'short', 'slurp', 'some', 'sort',
|
604
|
+
'sort-by', 'sorted-map', 'sorted-map-by', 'sorted-set',
|
605
|
+
'special-symbol?', 'split-at', 'split-with', 'str', 'string?',
|
606
|
+
'struct', 'struct-map', 'subs', 'subvec', 'symbol', 'symbol?',
|
607
|
+
'sync', 'take', 'take-nth', 'take-while', 'test', 'time', 'to-array',
|
608
|
+
'to-array-2d', 'tree-seq', 'true?', 'union', 'up', 'update-proxy',
|
609
|
+
'val', 'vals', 'var-get', 'var-set', 'var?', 'vector', 'vector-zip',
|
610
|
+
'vector?', 'when', 'when-first', 'when-let', 'when-not',
|
611
|
+
'with-local-vars', 'with-meta', 'with-open', 'with-out-str',
|
612
|
+
'xml-seq', 'xml-zip', 'zero?', 'zipmap', 'zipper']
|
613
|
+
|
614
|
+
# valid names for identifiers
|
615
|
+
# well, names can only not consist fully of numbers
|
616
|
+
# but this should be good enough for now
|
617
|
+
|
618
|
+
# TODO / should divide keywords/symbols into namespace/rest
|
619
|
+
# but that's hard, so just pretend / is part of the name
|
620
|
+
valid_name = r'(?!#)[\w!$%*+<=>?/.#-]+'
|
621
|
+
|
622
|
+
def _multi_escape(entries):
|
623
|
+
return '(%s)' % ('|'.join(re.escape(entry) + ' ' for entry in entries))
|
624
|
+
|
625
|
+
tokens = {
|
626
|
+
'root': [
|
627
|
+
# the comments - always starting with semicolon
|
628
|
+
# and going to the end of the line
|
629
|
+
(r';.*$', Comment.Single),
|
630
|
+
|
631
|
+
# whitespaces - usually not relevant
|
632
|
+
(r'[,\s]+', Text),
|
633
|
+
|
634
|
+
# numbers
|
635
|
+
(r'-?\d+\.\d+', Number.Float),
|
636
|
+
(r'-?\d+', Number.Integer),
|
637
|
+
(r'0x-?[abcdef\d]+', Number.Hex),
|
638
|
+
|
639
|
+
# strings, symbols and characters
|
640
|
+
(r'"(\\\\|\\"|[^"])*"', String),
|
641
|
+
(r"'" + valid_name, String.Symbol),
|
642
|
+
(r"\\(.|[a-z]+)", String.Char),
|
643
|
+
|
644
|
+
# keywords
|
645
|
+
(r':' + valid_name, String.Symbol),
|
646
|
+
|
647
|
+
# special operators
|
648
|
+
(r'~@|[`\'#^~&]', Operator),
|
649
|
+
|
650
|
+
# highlight the special forms
|
651
|
+
(_multi_escape(special_forms), Keyword),
|
652
|
+
|
653
|
+
# Technically, only the special forms are 'keywords'. The problem
|
654
|
+
# is that only treating them as keywords means that things like
|
655
|
+
# 'defn' and 'ns' need to be highlighted as builtins. This is ugly
|
656
|
+
# and weird for most styles. So, as a compromise we're going to
|
657
|
+
# highlight them as Keyword.Declarations.
|
658
|
+
(_multi_escape(declarations), Keyword.Declaration),
|
659
|
+
|
660
|
+
# highlight the builtins
|
661
|
+
(_multi_escape(builtins), Name.Builtin),
|
662
|
+
|
663
|
+
# the remaining functions
|
664
|
+
(r'(?<=\()' + valid_name, Name.Function),
|
665
|
+
|
666
|
+
# find the remaining variables
|
667
|
+
(valid_name, Name.Variable),
|
668
|
+
|
669
|
+
# Clojure accepts vector notation
|
670
|
+
(r'(\[|\])', Punctuation),
|
671
|
+
|
672
|
+
# Clojure accepts map notation
|
673
|
+
(r'(\{|\})', Punctuation),
|
674
|
+
|
675
|
+
# the famous parentheses!
|
676
|
+
(r'(\(|\))', Punctuation),
|
677
|
+
],
|
678
|
+
}
|