74 r'string|strong0|strong1|struct|table|task|' |
74 r'string|strong0|strong1|struct|table|task|' |
75 r'tran|tranif0|tranif1|type|typedef|' |
75 r'tran|tranif0|tranif1|type|typedef|' |
76 r'unsigned|var|vectored|void|wait|weak0|weak1|while|' |
76 r'unsigned|var|vectored|void|wait|weak0|weak1|while|' |
77 r'xnor|xor)\b', Keyword), |
77 r'xnor|xor)\b', Keyword), |
78 |
78 |
79 (r'(`accelerate|`autoexpand_vectornets|`celldefine|`default_nettype|' |
79 (r'`(accelerate|autoexpand_vectornets|celldefine|default_nettype|' |
80 r'`else|`elsif|`endcelldefine|`endif|`endprotect|`endprotected|' |
80 r'else|elsif|endcelldefine|endif|endprotect|endprotected|' |
81 r'`expand_vectornets|`ifdef|`ifndef|`include|`noaccelerate|`noexpand_vectornets|' |
81 r'expand_vectornets|ifdef|ifndef|include|noaccelerate|noexpand_vectornets|' |
82 r'`noremove_gatenames|`noremove_netnames|`nounconnected_drive|' |
82 r'noremove_gatenames|noremove_netnames|nounconnected_drive|' |
83 r'`protect|`protected|`remove_gatenames|`remove_netnames|`resetall|' |
83 r'protect|protected|remove_gatenames|remove_netnames|resetall|' |
84 r'`timescale|`unconnected_drive|`undef)\b', Comment.Preproc), |
84 r'timescale|unconnected_drive|undef)\b', Comment.Preproc), |
85 |
85 |
86 (r'(\$bits|\$bitstoreal|\$bitstoshortreal|\$countdrivers|\$display|\$fclose|' |
86 (r'\$(bits|bitstoreal|bitstoshortreal|countdrivers|display|fclose|' |
87 r'\$fdisplay|\$finish|\$floor|\$fmonitor|\$fopen|\$fstrobe|\$fwrite|' |
87 r'fdisplay|finish|floor|fmonitor|fopen|fstrobe|fwrite|' |
88 r'\$getpattern|\$history|\$incsave|\$input|\$itor|\$key|\$list|\$log|' |
88 r'getpattern|history|incsave|input|itor|key|list|log|' |
89 r'\$monitor|\$monitoroff|\$monitoron|\$nokey|\$nolog|\$printtimescale|' |
89 r'monitor|monitoroff|monitoron|nokey|nolog|printtimescale|' |
90 r'\$random|\$readmemb|\$readmemh|\$realtime|\$realtobits|\$reset|\$reset_count|' |
90 r'random|readmemb|readmemh|realtime|realtobits|reset|reset_count|' |
91 r'\$reset_value|\$restart|\$rtoi|\$save|\$scale|\$scope|\$shortrealtobits|' |
91 r'reset_value|restart|rtoi|save|scale|scope|shortrealtobits|' |
92 r'\$showscopes|\$showvariables|\$showvars|\$sreadmemb|\$sreadmemh|' |
92 r'showscopes|showvariables|showvars|sreadmemb|sreadmemh|' |
93 r'\$stime|\$stop|\$strobe|\$time|\$timeformat|\$write)\b', Name.Builtin), |
93 r'stime|stop|strobe|time|timeformat|write)\b', Name.Builtin), |
94 |
94 |
95 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), |
95 (r'(byte|shortint|int|longint|integer|time|' |
96 (r'(byte|shortint|int|longint|interger|time|' |
|
97 r'bit|logic|reg|' |
96 r'bit|logic|reg|' |
98 r'supply0|supply1|tri|triand|trior|tri0|tri1|trireg|uwire|wire|wand|wor' |
97 r'supply0|supply1|tri|triand|trior|tri0|tri1|trireg|uwire|wire|wand|wor' |
99 r'shortreal|real|realtime)\b', Keyword.Type), |
98 r'shortreal|real|realtime)\b', Keyword.Type), |
100 ('[a-zA-Z_][a-zA-Z0-9_]*:(?!:)', Name.Label), |
99 ('[a-zA-Z_][a-zA-Z0-9_]*:(?!:)', Name.Label), |
101 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), |
100 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), |
102 ], |
|
103 'classname': [ |
|
104 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'), |
|
105 ], |
101 ], |
106 'string': [ |
102 'string': [ |
107 (r'"', String, '#pop'), |
103 (r'"', String, '#pop'), |
108 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), |
104 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), |
109 (r'[^\\"\n]+', String), # all other characters |
105 (r'[^\\"\n]+', String), # all other characters |
131 if value.isupper(): |
127 if value.isupper(): |
132 token = Name.Constant |
128 token = Name.Constant |
133 yield index, token, value |
129 yield index, token, value |
134 |
130 |
135 |
131 |
|
132 class SystemVerilogLexer(RegexLexer): |
|
133 """ |
|
134 Extends verilog lexer to recognise all SystemVerilog keywords from IEEE |
|
135 1800-2009 standard. |
|
136 |
|
137 *New in Pygments 1.5.* |
|
138 """ |
|
139 name = 'systemverilog' |
|
140 aliases = ['sv'] |
|
141 filenames = ['*.sv', '*.svh'] |
|
142 mimetypes = ['text/x-systemverilog'] |
|
143 |
|
144 #: optional Comment or Whitespace |
|
145 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' |
|
146 |
|
147 tokens = { |
|
148 'root': [ |
|
149 (r'^\s*`define', Comment.Preproc, 'macro'), |
|
150 (r'^(\s*)(package)(\s+)', bygroups(Text, Keyword.Namespace, Text)), |
|
151 (r'^(\s*)(import)(\s+)', bygroups(Text, Keyword.Namespace, Text), 'import'), |
|
152 |
|
153 (r'\n', Text), |
|
154 (r'\s+', Text), |
|
155 (r'\\\n', Text), # line continuation |
|
156 (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single), |
|
157 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
158 (r'[{}#@]', Punctuation), |
|
159 (r'L?"', String, 'string'), |
|
160 (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), |
|
161 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), |
|
162 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), |
|
163 (r'([0-9]+)|(\'h)[0-9a-fA-F]+', Number.Hex), |
|
164 (r'([0-9]+)|(\'b)[0-1]+', Number.Hex), # should be binary |
|
165 (r'([0-9]+)|(\'d)[0-9]+', Number.Integer), |
|
166 (r'([0-9]+)|(\'o)[0-7]+', Number.Oct), |
|
167 (r'\'[01xz]', Number), |
|
168 (r'\d+[Ll]?', Number.Integer), |
|
169 (r'\*/', Error), |
|
170 (r'[~!%^&*+=|?:<>/-]', Operator), |
|
171 (r'[()\[\],.;\']', Punctuation), |
|
172 (r'`[a-zA-Z_][a-zA-Z0-9_]*', Name.Constant), |
|
173 |
|
174 (r'(accept_on|alias|always|always_comb|always_ff|always_latch|' |
|
175 r'and|assert|assign|assume|automatic|before|begin|bind|bins|' |
|
176 r'binsof|bit|break|buf|bufif0|bufif1|byte|case|casex|casez|' |
|
177 r'cell|chandle|checker|class|clocking|cmos|config|const|constraint|' |
|
178 r'context|continue|cover|covergroup|coverpoint|cross|deassign|' |
|
179 r'default|defparam|design|disable|dist|do|edge|else|end|endcase|' |
|
180 r'endchecker|endclass|endclocking|endconfig|endfunction|endgenerate|' |
|
181 r'endgroup|endinterface|endmodule|endpackage|endprimitive|' |
|
182 r'endprogram|endproperty|endsequence|endspecify|endtable|' |
|
183 r'endtask|enum|event|eventually|expect|export|extends|extern|' |
|
184 r'final|first_match|for|force|foreach|forever|fork|forkjoin|' |
|
185 r'function|generate|genvar|global|highz0|highz1|if|iff|ifnone|' |
|
186 r'ignore_bins|illegal_bins|implies|import|incdir|include|' |
|
187 r'initial|inout|input|inside|instance|int|integer|interface|' |
|
188 r'intersect|join|join_any|join_none|large|let|liblist|library|' |
|
189 r'local|localparam|logic|longint|macromodule|matches|medium|' |
|
190 r'modport|module|nand|negedge|new|nexttime|nmos|nor|noshowcancelled|' |
|
191 r'not|notif0|notif1|null|or|output|package|packed|parameter|' |
|
192 r'pmos|posedge|primitive|priority|program|property|protected|' |
|
193 r'pull0|pull1|pulldown|pullup|pulsestyle_ondetect|pulsestyle_onevent|' |
|
194 r'pure|rand|randc|randcase|randsequence|rcmos|real|realtime|' |
|
195 r'ref|reg|reject_on|release|repeat|restrict|return|rnmos|' |
|
196 r'rpmos|rtran|rtranif0|rtranif1|s_always|s_eventually|s_nexttime|' |
|
197 r's_until|s_until_with|scalared|sequence|shortint|shortreal|' |
|
198 r'showcancelled|signed|small|solve|specify|specparam|static|' |
|
199 r'string|strong|strong0|strong1|struct|super|supply0|supply1|' |
|
200 r'sync_accept_on|sync_reject_on|table|tagged|task|this|throughout|' |
|
201 r'time|timeprecision|timeunit|tran|tranif0|tranif1|tri|tri0|' |
|
202 r'tri1|triand|trior|trireg|type|typedef|union|unique|unique0|' |
|
203 r'unsigned|until|until_with|untyped|use|uwire|var|vectored|' |
|
204 r'virtual|void|wait|wait_order|wand|weak|weak0|weak1|while|' |
|
205 r'wildcard|wire|with|within|wor|xnor|xor)\b', Keyword ), |
|
206 |
|
207 (r'(`__FILE__|`__LINE__|`begin_keywords|`celldefine|`default_nettype|' |
|
208 r'`define|`else|`elsif|`end_keywords|`endcelldefine|`endif|' |
|
209 r'`ifdef|`ifndef|`include|`line|`nounconnected_drive|`pragma|' |
|
210 r'`resetall|`timescale|`unconnected_drive|`undef|`undefineall)\b', |
|
211 Comment.Preproc ), |
|
212 |
|
213 (r'(\$display|\$displayb|\$displayh|\$displayo|\$dumpall|\$dumpfile|' |
|
214 r'\$dumpflush|\$dumplimit|\$dumpoff|\$dumpon|\$dumpports|' |
|
215 r'\$dumpportsall|\$dumpportsflush|\$dumpportslimit|\$dumpportsoff|' |
|
216 r'\$dumpportson|\$dumpvars|\$fclose|\$fdisplay|\$fdisplayb|' |
|
217 r'\$fdisplayh|\$fdisplayo|\$feof|\$ferror|\$fflush|\$fgetc|' |
|
218 r'\$fgets|\$fmonitor|\$fmonitorb|\$fmonitorh|\$fmonitoro|' |
|
219 r'\$fopen|\$fread|\$fscanf|\$fseek|\$fstrobe|\$fstrobeb|\$fstrobeh|' |
|
220 r'\$fstrobeo|\$ftell|\$fwrite|\$fwriteb|\$fwriteh|\$fwriteo|' |
|
221 r'\$monitor|\$monitorb|\$monitorh|\$monitoro|\$monitoroff|' |
|
222 r'\$monitoron|\$plusargs|\$readmemb|\$readmemh|\$rewind|\$sformat|' |
|
223 r'\$sformatf|\$sscanf|\$strobe|\$strobeb|\$strobeh|\$strobeo|' |
|
224 r'\$swrite|\$swriteb|\$swriteh|\$swriteo|\$test|\$ungetc|' |
|
225 r'\$value\$plusargs|\$write|\$writeb|\$writeh|\$writememb|' |
|
226 r'\$writememh|\$writeo)\b' , Name.Builtin ), |
|
227 |
|
228 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), |
|
229 (r'(byte|shortint|int|longint|integer|time|' |
|
230 r'bit|logic|reg|' |
|
231 r'supply0|supply1|tri|triand|trior|tri0|tri1|trireg|uwire|wire|wand|wor' |
|
232 r'shortreal|real|realtime)\b', Keyword.Type), |
|
233 ('[a-zA-Z_][a-zA-Z0-9_]*:(?!:)', Name.Label), |
|
234 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), |
|
235 ], |
|
236 'classname': [ |
|
237 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'), |
|
238 ], |
|
239 'string': [ |
|
240 (r'"', String, '#pop'), |
|
241 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), |
|
242 (r'[^\\"\n]+', String), # all other characters |
|
243 (r'\\\n', String), # line continuation |
|
244 (r'\\', String), # stray backslash |
|
245 ], |
|
246 'macro': [ |
|
247 (r'[^/\n]+', Comment.Preproc), |
|
248 (r'/[*](.|\n)*?[*]/', Comment.Multiline), |
|
249 (r'//.*?\n', Comment.Single, '#pop'), |
|
250 (r'/', Comment.Preproc), |
|
251 (r'(?<=\\)\n', Comment.Preproc), |
|
252 (r'\n', Comment.Preproc, '#pop'), |
|
253 ], |
|
254 'import': [ |
|
255 (r'[a-zA-Z0-9_:]+\*?', Name.Namespace, '#pop') |
|
256 ] |
|
257 } |
|
258 |
|
259 def get_tokens_unprocessed(self, text): |
|
260 for index, token, value in \ |
|
261 RegexLexer.get_tokens_unprocessed(self, text): |
|
262 # Convention: mark all upper case names as constants |
|
263 if token is Name: |
|
264 if value.isupper(): |
|
265 token = Name.Constant |
|
266 yield index, token, value |
|
267 |
|
268 def analyse_text(text): |
|
269 if text.startswith('//') or text.startswith('/*'): |
|
270 return 0.5 |
|
271 |
|
272 |
|
273 class VhdlLexer(RegexLexer): |
|
274 """ |
|
275 For VHDL source code. |
|
276 |
|
277 *New in Pygments 1.5.* |
|
278 """ |
|
279 name = 'vhdl' |
|
280 aliases = ['vhdl'] |
|
281 filenames = ['*.vhdl', '*.vhd'] |
|
282 mimetypes = ['text/x-vhdl'] |
|
283 flags = re.MULTILINE | re.IGNORECASE |
|
284 |
|
285 tokens = { |
|
286 'root': [ |
|
287 (r'\n', Text), |
|
288 (r'\s+', Text), |
|
289 (r'\\\n', Text), # line continuation |
|
290 (r'--(?![!#$%&*+./<=>?@\^|_~]).*?$', Comment.Single), |
|
291 (r"'(U|X|0|1|Z|W|L|H|-)'", String.Char), |
|
292 (r'[~!%^&*+=|?:<>/-]', Operator), |
|
293 (r"'[a-zA-Z_][a-zA-Z0-9_]*", Name.Attribute), |
|
294 (r'[()\[\],.;\']', Punctuation), |
|
295 (r'"[^\n\\]*"', String), |
|
296 |
|
297 (r'(library)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)', |
|
298 bygroups(Keyword, Text, Name.Namespace)), |
|
299 (r'(use)(\s+)(entity)', bygroups(Keyword, Text, Keyword)), |
|
300 (r'(use)(\s+)([a-zA-Z_][\.a-zA-Z0-9_]*)', |
|
301 bygroups(Keyword, Text, Name.Namespace)), |
|
302 (r'(entity|component)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)', |
|
303 bygroups(Keyword, Text, Name.Class)), |
|
304 (r'(architecture|configuration)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)(\s+)' |
|
305 r'(of)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)(\s+)(is)', |
|
306 bygroups(Keyword, Text, Name.Class, Text, Keyword, Text, |
|
307 Name.Class, Text, Keyword)), |
|
308 |
|
309 (r'(end)(\s+)', bygroups(using(this), Text), 'endblock'), |
|
310 |
|
311 include('types'), |
|
312 include('keywords'), |
|
313 include('numbers'), |
|
314 |
|
315 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name), |
|
316 ], |
|
317 'endblock': [ |
|
318 include('keywords'), |
|
319 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class), |
|
320 (r'(\s+)', Text), |
|
321 (r';', Punctuation, '#pop'), |
|
322 ], |
|
323 'types': [ |
|
324 (r'(boolean|bit|character|severity_level|integer|time|delay_length|' |
|
325 r'natural|positive|string|bit_vector|file_open_kind|' |
|
326 r'file_open_status|std_ulogic|std_ulogic_vector|std_logic|' |
|
327 r'std_logic_vector)\b', Keyword.Type), |
|
328 ], |
|
329 'keywords': [ |
|
330 (r'(abs|access|after|alias|all|and|' |
|
331 r'architecture|array|assert|attribute|begin|block|' |
|
332 r'body|buffer|bus|case|component|configuration|' |
|
333 r'constant|disconnect|downto|else|elsif|end|' |
|
334 r'entity|exit|file|for|function|generate|' |
|
335 r'generic|group|guarded|if|impure|in|' |
|
336 r'inertial|inout|is|label|library|linkage|' |
|
337 r'literal|loop|map|mod|nand|new|' |
|
338 r'next|nor|not|null|of|on|' |
|
339 r'open|or|others|out|package|port|' |
|
340 r'postponed|procedure|process|pure|range|record|' |
|
341 r'register|reject|return|rol|ror|select|' |
|
342 r'severity|signal|shared|sla|sli|sra|' |
|
343 r'srl|subtype|then|to|transport|type|' |
|
344 r'units|until|use|variable|wait|when|' |
|
345 r'while|with|xnor|xor)\b', Keyword), |
|
346 ], |
|
347 'numbers': [ |
|
348 (r'\d{1,2}#[0-9a-fA-F_]+#?', Number.Integer), |
|
349 (r'[0-1_]+(\.[0-1_])', Number.Integer), |
|
350 (r'\d+', Number.Integer), |
|
351 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float), |
|
352 (r'H"[0-9a-fA-F_]+"', Number.Oct), |
|
353 (r'O"[0-7_]+"', Number.Oct), |
|
354 (r'B"[0-1_]+"', Number.Oct), |
|
355 ], |
|
356 } |