15 from pygments.lexers.compiled import DLexer, CppLexer, CLexer |
15 from pygments.lexers.compiled import DLexer, CppLexer, CLexer |
16 from pygments.token import Text, Name, Number, String, Comment, Punctuation, \ |
16 from pygments.token import Text, Name, Number, String, Comment, Punctuation, \ |
17 Other, Keyword, Operator |
17 Other, Keyword, Operator |
18 |
18 |
19 __all__ = ['GasLexer', 'ObjdumpLexer','DObjdumpLexer', 'CppObjdumpLexer', |
19 __all__ = ['GasLexer', 'ObjdumpLexer','DObjdumpLexer', 'CppObjdumpLexer', |
20 'CObjdumpLexer', 'LlvmLexer', 'NasmLexer'] |
20 'CObjdumpLexer', 'LlvmLexer', 'NasmLexer', 'Ca65Lexer'] |
21 |
21 |
22 |
22 |
23 class GasLexer(RegexLexer): |
23 class GasLexer(RegexLexer): |
24 """ |
24 """ |
25 For Gas (AT&T) assembly code. |
25 For Gas (AT&T) assembly code. |
29 filenames = ['*.s', '*.S'] |
29 filenames = ['*.s', '*.S'] |
30 mimetypes = ['text/x-gas'] |
30 mimetypes = ['text/x-gas'] |
31 |
31 |
32 #: optional Comment or Whitespace |
32 #: optional Comment or Whitespace |
33 string = r'"(\\"|[^"])*"' |
33 string = r'"(\\"|[^"])*"' |
34 char = r'[a-zA-Z$._0-9@]' |
34 char = r'[a-zA-Z$._0-9@-]' |
35 identifier = r'(?:[a-zA-Z$_]' + char + '*|\.' + char + '+)' |
35 identifier = r'(?:[a-zA-Z$_]' + char + '*|\.' + char + '+)' |
36 number = r'(?:0[xX][a-zA-Z0-9]+|\d+)' |
36 number = r'(?:0[xX][a-zA-Z0-9]+|\d+)' |
37 |
37 |
38 tokens = { |
38 tokens = { |
39 'root': [ |
39 'root': [ |
206 tokens = { |
206 tokens = { |
207 'root': [ |
207 'root': [ |
208 include('whitespace'), |
208 include('whitespace'), |
209 |
209 |
210 # Before keywords, because keywords are valid label names :(... |
210 # Before keywords, because keywords are valid label names :(... |
211 (r'^\s*' + identifier + '\s*:', Name.Label), |
211 (identifier + '\s*:', Name.Label), |
212 |
212 |
213 include('keyword'), |
213 include('keyword'), |
214 |
214 |
215 (r'%' + identifier, Name.Variable),#Name.Identifier.Local), |
215 (r'%' + identifier, Name.Variable),#Name.Identifier.Local), |
216 (r'@' + identifier, Name.Variable.Global),#Name.Identifier.Global), |
216 (r'@' + identifier, Name.Variable.Global),#Name.Identifier.Global), |
238 |
238 |
239 r'|private|linker_private|internal|available_externally|linkonce' |
239 r'|private|linker_private|internal|available_externally|linkonce' |
240 r'|linkonce_odr|weak|weak_odr|appending|dllimport|dllexport' |
240 r'|linkonce_odr|weak|weak_odr|appending|dllimport|dllexport' |
241 r'|common|default|hidden|protected|extern_weak|external' |
241 r'|common|default|hidden|protected|extern_weak|external' |
242 r'|thread_local|zeroinitializer|undef|null|to|tail|target|triple' |
242 r'|thread_local|zeroinitializer|undef|null|to|tail|target|triple' |
243 r'|deplibs|datalayout|volatile|nuw|nsw|exact|inbounds|align' |
243 r'|datalayout|volatile|nuw|nsw|nnan|ninf|nsz|arcp|fast|exact|inbounds' |
244 r'|addrspace|section|alias|module|asm|sideeffect|gc|dbg' |
244 r'|align|addrspace|section|alias|module|asm|sideeffect|gc|dbg' |
245 |
245 |
246 r'|ccc|fastcc|coldcc|x86_stdcallcc|x86_fastcallcc|arm_apcscc' |
246 r'|ccc|fastcc|coldcc|x86_stdcallcc|x86_fastcallcc|arm_apcscc' |
247 r'|arm_aapcscc|arm_aapcs_vfpcc' |
247 r'|arm_aapcscc|arm_aapcs_vfpcc' |
248 |
248 |
249 r'|cc|c' |
249 r'|cc|c' |
302 binn = r'[01]+b' |
302 binn = r'[01]+b' |
303 decn = r'[0-9]+' |
303 decn = r'[0-9]+' |
304 floatn = decn + r'\.e?' + decn |
304 floatn = decn + r'\.e?' + decn |
305 string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`" |
305 string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`" |
306 declkw = r'(?:res|d)[bwdqt]|times' |
306 declkw = r'(?:res|d)[bwdqt]|times' |
307 register = (r'[a-d][lh]|e?[a-d]x|e?[sb]p|e?[sd]i|[c-gs]s|st[0-7]|' |
307 register = (r'r[0-9][0-5]?[bwd]|' |
|
308 r'[a-d][lh]|[er]?[a-d]x|[er]?[sb]p|[er]?[sd]i|[c-gs]s|st[0-7]|' |
308 r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]') |
309 r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]') |
309 wordop = r'seg|wrt|strict' |
310 wordop = r'seg|wrt|strict' |
310 type = r'byte|[dq]?word' |
311 type = r'byte|[dq]?word' |
311 directives = (r'BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|' |
312 directives = (r'BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|' |
312 r'ORG|ALIGN|STRUC|ENDSTRUC|COMMON|CPU|GROUP|UPPERCASE|IMPORT|' |
313 r'ORG|ALIGN|STRUC|ENDSTRUC|COMMON|CPU|GROUP|UPPERCASE|IMPORT|' |
355 (r'[$]+', Keyword.Constant), |
356 (r'[$]+', Keyword.Constant), |
356 (wordop, Operator.Word), |
357 (wordop, Operator.Word), |
357 (type, Keyword.Type) |
358 (type, Keyword.Type) |
358 ], |
359 ], |
359 } |
360 } |
|
361 |
|
362 |
|
363 class Ca65Lexer(RegexLexer): |
|
364 """ |
|
365 For ca65 assembler sources. |
|
366 |
|
367 *New in Pygments 1.6.* |
|
368 """ |
|
369 name = 'ca65' |
|
370 aliases = ['ca65'] |
|
371 filenames = ['*.s'] |
|
372 |
|
373 flags = re.IGNORECASE |
|
374 |
|
375 tokens = { |
|
376 'root': [ |
|
377 (r';.*', Comment.Single), |
|
378 (r'\s+', Text), |
|
379 (r'[a-z_.@$][\w.@$]*:', Name.Label), |
|
380 (r'((ld|st)[axy]|(in|de)[cxy]|asl|lsr|ro[lr]|adc|sbc|cmp|cp[xy]' |
|
381 r'|cl[cvdi]|se[cdi]|jmp|jsr|bne|beq|bpl|bmi|bvc|bvs|bcc|bcs' |
|
382 r'|p[lh][ap]|rt[is]|brk|nop|ta[xy]|t[xy]a|txs|tsx|and|ora|eor' |
|
383 r'|bit)\b', Keyword), |
|
384 (r'\.[a-z0-9_]+', Keyword.Pseudo), |
|
385 (r'[-+~*/^&|!<>=]', Operator), |
|
386 (r'"[^"\n]*.', String), |
|
387 (r"'[^'\n]*.", String.Char), |
|
388 (r'\$[0-9a-f]+|[0-9a-f]+h\b', Number.Hex), |
|
389 (r'\d+|%[01]+', Number.Integer), |
|
390 (r'[#,.:()=]', Punctuation), |
|
391 (r'[a-z_.@$][\w.@$]*', Name), |
|
392 ] |
|
393 } |
|
394 |
|
395 def analyse_text(self, text): |
|
396 # comments in GAS start with "#" |
|
397 if re.match(r'^\s*;', text, re.MULTILINE): |
|
398 return 0.9 |