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