ThirdParty/Pygments/pygments/lexers/asm.py

changeset 4172
4f20dba37ab6
parent 3145
a9de05d4a22f
child 4697
c2e9bf425554
--- a/ThirdParty/Pygments/pygments/lexers/asm.py	Wed Mar 11 18:25:37 2015 +0100
+++ b/ThirdParty/Pygments/pygments/lexers/asm.py	Wed Mar 11 18:32:27 2015 +0100
@@ -5,21 +5,21 @@
 
     Lexers for assembly languages.
 
-    :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
+    :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
     :license: BSD, see LICENSE for details.
 """
 
-from __future__ import unicode_literals
-
 import re
 
 from pygments.lexer import RegexLexer, include, bygroups, using, DelegatingLexer
-from pygments.lexers.compiled import DLexer, CppLexer, CLexer
+from pygments.lexers.c_cpp import CppLexer, CLexer
+from pygments.lexers.d import DLexer
 from pygments.token import Text, Name, Number, String, Comment, Punctuation, \
-     Other, Keyword, Operator
+    Other, Keyword, Operator
 
-__all__ = ['GasLexer', 'ObjdumpLexer','DObjdumpLexer', 'CppObjdumpLexer',
-           'CObjdumpLexer', 'LlvmLexer', 'NasmLexer', 'Ca65Lexer']
+__all__ = ['GasLexer', 'ObjdumpLexer', 'DObjdumpLexer', 'CppObjdumpLexer',
+           'CObjdumpLexer', 'LlvmLexer', 'NasmLexer', 'NasmObjdumpLexer',
+           'Ca65Lexer']
 
 
 class GasLexer(RegexLexer):
@@ -27,13 +27,13 @@
     For Gas (AT&T) assembly code.
     """
     name = 'GAS'
-    aliases = ['gas']
+    aliases = ['gas', 'asm']
     filenames = ['*.s', '*.S']
     mimetypes = ['text/x-gas']
 
     #: optional Comment or Whitespace
     string = r'"(\\"|[^"])*"'
-    char = r'[a-zA-Z$._0-9@-]'
+    char = r'[\w$.@-]'
     identifier = r'(?:[a-zA-Z$_]' + char + '*|\.' + char + '+)'
     number = r'(?:0[xX][a-zA-Z0-9]+|\d+)'
 
@@ -98,18 +98,12 @@
             return 0.1
 
 
-class ObjdumpLexer(RegexLexer):
-    """
-    For the output of 'objdump -dr'
+def _objdump_lexer_tokens(asm_lexer):
     """
-    name = 'objdump'
-    aliases = ['objdump']
-    filenames = ['*.objdump']
-    mimetypes = ['text/x-objdump']
-
-    hex = r'[0-9A-Za-z]'
-
-    tokens = {
+    Common objdump lexer tokens to wrap an ASM lexer.
+    """
+    hex_re = r'[0-9A-Za-z]'
+    return {
         'root': [
             # File name & format:
             ('(.*?)(:)( +file format )(.*?)$',
@@ -119,33 +113,33 @@
                 bygroups(Text, Name.Label, Punctuation)),
             # Function labels
             # (With offset)
-            ('('+hex+'+)( )(<)(.*?)([-+])(0[xX][A-Za-z0-9]+)(>:)$',
+            ('('+hex_re+'+)( )(<)(.*?)([-+])(0[xX][A-Za-z0-9]+)(>:)$',
                 bygroups(Number.Hex, Text, Punctuation, Name.Function,
                          Punctuation, Number.Hex, Punctuation)),
             # (Without offset)
-            ('('+hex+'+)( )(<)(.*?)(>:)$',
+            ('('+hex_re+'+)( )(<)(.*?)(>:)$',
                 bygroups(Number.Hex, Text, Punctuation, Name.Function,
                          Punctuation)),
             # Code line with disassembled instructions
-            ('( *)('+hex+r'+:)(\t)((?:'+hex+hex+' )+)( *\t)([a-zA-Z].*?)$',
+            ('( *)('+hex_re+r'+:)(\t)((?:'+hex_re+hex_re+' )+)( *\t)([a-zA-Z].*?)$',
                 bygroups(Text, Name.Label, Text, Number.Hex, Text,
-                         using(GasLexer))),
+                         using(asm_lexer))),
             # Code line with ascii
-            ('( *)('+hex+r'+:)(\t)((?:'+hex+hex+' )+)( *)(.*?)$',
+            ('( *)('+hex_re+r'+:)(\t)((?:'+hex_re+hex_re+' )+)( *)(.*?)$',
                 bygroups(Text, Name.Label, Text, Number.Hex, Text, String)),
             # Continued code line, only raw opcodes without disassembled
             # instruction
-            ('( *)('+hex+r'+:)(\t)((?:'+hex+hex+' )+)$',
+            ('( *)('+hex_re+r'+:)(\t)((?:'+hex_re+hex_re+' )+)$',
                 bygroups(Text, Name.Label, Text, Number.Hex)),
             # Skipped a few bytes
             (r'\t\.\.\.$', Text),
             # Relocation line
             # (With offset)
-            (r'(\t\t\t)('+hex+r'+:)( )([^\t]+)(\t)(.*?)([-+])(0x' + hex + '+)$',
+            (r'(\t\t\t)('+hex_re+r'+:)( )([^\t]+)(\t)(.*?)([-+])(0x'+hex_re+'+)$',
                 bygroups(Text, Name.Label, Text, Name.Property, Text,
                          Name.Constant, Punctuation, Number.Hex)),
             # (Without offset)
-            (r'(\t\t\t)('+hex+r'+:)( )([^\t]+)(\t)(.*?)$',
+            (r'(\t\t\t)('+hex_re+r'+:)( )([^\t]+)(\t)(.*?)$',
                 bygroups(Text, Name.Label, Text, Name.Property, Text,
                          Name.Constant)),
             (r'[^\n]+\n', Other)
@@ -153,6 +147,18 @@
     }
 
 
+class ObjdumpLexer(RegexLexer):
+    """
+    For the output of 'objdump -dr'
+    """
+    name = 'objdump'
+    aliases = ['objdump']
+    filenames = ['*.objdump']
+    mimetypes = ['text/x-objdump']
+
+    tokens = _objdump_lexer_tokens(GasLexer)
+
+
 class DObjdumpLexer(DelegatingLexer):
     """
     For the output of 'objdump -Sr on compiled D files'
@@ -203,7 +209,7 @@
 
     #: optional Comment or Whitespace
     string = r'"[^"]*?"'
-    identifier = r'([-a-zA-Z$._][-a-zA-Z$._0-9]*|' + string + ')'
+    identifier = r'([-a-zA-Z$._][\w\-$.]*|' + string + ')'
 
     tokens = {
         'root': [
@@ -214,10 +220,11 @@
 
             include('keyword'),
 
-            (r'%' + identifier, Name.Variable),#Name.Identifier.Local),
-            (r'@' + identifier, Name.Variable.Global),#Name.Identifier.Global),
-            (r'%\d+', Name.Variable.Anonymous),#Name.Identifier.Anonymous),
-            (r'@\d+', Name.Variable.Global),#Name.Identifier.Anonymous),
+            (r'%' + identifier, Name.Variable),
+            (r'@' + identifier, Name.Variable.Global),
+            (r'%\d+', Name.Variable.Anonymous),
+            (r'@\d+', Name.Variable.Global),
+            (r'#\d+', Name.Variable.Global),
             (r'!' + identifier, Name.Variable),
             (r'!\d+', Name.Variable.Anonymous),
             (r'c?' + string, String),
@@ -244,17 +251,24 @@
              r'|thread_local|zeroinitializer|undef|null|to|tail|target|triple'
              r'|datalayout|volatile|nuw|nsw|nnan|ninf|nsz|arcp|fast|exact|inbounds'
              r'|align|addrspace|section|alias|module|asm|sideeffect|gc|dbg'
+             r'|linker_private_weak'
+             r'|attributes|blockaddress|initialexec|localdynamic|localexec'
+             r'|prefix|unnamed_addr'
 
              r'|ccc|fastcc|coldcc|x86_stdcallcc|x86_fastcallcc|arm_apcscc'
-             r'|arm_aapcscc|arm_aapcs_vfpcc'
+             r'|arm_aapcscc|arm_aapcs_vfpcc|ptx_device|ptx_kernel'
+             r'|intel_ocl_bicc|msp430_intrcc|spir_func|spir_kernel'
+             r'|x86_64_sysvcc|x86_64_win64cc|x86_thiscallcc'
 
              r'|cc|c'
 
              r'|signext|zeroext|inreg|sret|nounwind|noreturn|noalias|nocapture'
              r'|byval|nest|readnone|readonly'
-
              r'|inlinehint|noinline|alwaysinline|optsize|ssp|sspreq|noredzone'
              r'|noimplicitfloat|naked'
+             r'|builtin|cold|nobuiltin|noduplicate|nonlazybind|optnone'
+             r'|returns_twice|sanitize_address|sanitize_memory|sanitize_thread'
+             r'|sspstrong|uwtable|returned'
 
              r'|type|opaque'
 
@@ -263,24 +277,30 @@
              r'|oeq|one|olt|ogt|ole'
              r'|oge|ord|uno|ueq|une'
              r'|x'
+             r'|acq_rel|acquire|alignstack|atomic|catch|cleanup|filter'
+             r'|inteldialect|max|min|monotonic|nand|personality|release'
+             r'|seq_cst|singlethread|umax|umin|unordered|xchg'
 
              # instructions
              r'|add|fadd|sub|fsub|mul|fmul|udiv|sdiv|fdiv|urem|srem|frem|shl'
              r'|lshr|ashr|and|or|xor|icmp|fcmp'
 
              r'|phi|call|trunc|zext|sext|fptrunc|fpext|uitofp|sitofp|fptoui'
-             r'fptosi|inttoptr|ptrtoint|bitcast|select|va_arg|ret|br|switch'
+             r'|fptosi|inttoptr|ptrtoint|bitcast|select|va_arg|ret|br|switch'
              r'|invoke|unwind|unreachable'
+             r'|indirectbr|landingpad|resume'
 
              r'|malloc|alloca|free|load|store|getelementptr'
 
              r'|extractelement|insertelement|shufflevector|getresult'
              r'|extractvalue|insertvalue'
 
+             r'|atomicrmw|cmpxchg|fence'
+
              r')\b', Keyword),
 
             # Types
-            (r'void|float|double|x86_fp80|fp128|ppc_fp128|label|metadata',
+            (r'void|half|float|double|x86_fp80|fp128|ppc_fp128|label|metadata',
              Keyword.Type),
 
             # Integer types
@@ -298,8 +318,8 @@
     filenames = ['*.asm', '*.ASM']
     mimetypes = ['text/x-nasm']
 
-    identifier = r'[a-zA-Z$._?][a-zA-Z0-9$._?#@~]*'
-    hexn = r'(?:0[xX][0-9a-fA-F]+|$0[0-9a-fA-F]*|[0-9]+[0-9a-fA-F]*h)'
+    identifier = r'[a-z$._?][\w$.?#@~]*'
+    hexn = r'(?:0x[0-9a-f]+|$0[0-9a-f]*|[0-9]+[0-9a-f]*h)'
     octn = r'[0-7]+q'
     binn = r'[01]+b'
     decn = r'[0-9]+'
@@ -318,8 +338,8 @@
     flags = re.IGNORECASE | re.MULTILINE
     tokens = {
         'root': [
+            (r'^\s*%', Comment.Preproc, 'preproc'),
             include('whitespace'),
-            (r'^\s*%', Comment.Preproc, 'preproc'),
             (identifier + ':', Name.Label),
             (r'(%s)(\s+)(equ)' % identifier,
                 bygroups(Name.Constant, Keyword.Declaration, Keyword.Declaration),
@@ -333,7 +353,7 @@
             (string, String),
             (hexn, Number.Hex),
             (octn, Number.Oct),
-            (binn, Number),
+            (binn, Number.Bin),
             (floatn, Number.Float),
             (decn, Number.Integer),
             include('punctuation'),
@@ -362,13 +382,27 @@
     }
 
 
+class NasmObjdumpLexer(ObjdumpLexer):
+    """
+    For the output of 'objdump -d -M intel'.
+
+    .. versionadded:: 2.0
+    """
+    name = 'objdump-nasm'
+    aliases = ['objdump-nasm']
+    filenames = ['*.objdump-intel']
+    mimetypes = ['text/x-nasm-objdump']
+
+    tokens = _objdump_lexer_tokens(NasmLexer)
+
+
 class Ca65Lexer(RegexLexer):
     """
     For ca65 assembler sources.
 
-    *New in Pygments 1.6.*
+    .. versionadded:: 1.6
     """
-    name = 'ca65'
+    name = 'ca65 assembler'
     aliases = ['ca65']
     filenames = ['*.s']
 
@@ -383,13 +417,14 @@
              r'|cl[cvdi]|se[cdi]|jmp|jsr|bne|beq|bpl|bmi|bvc|bvs|bcc|bcs'
              r'|p[lh][ap]|rt[is]|brk|nop|ta[xy]|t[xy]a|txs|tsx|and|ora|eor'
              r'|bit)\b', Keyword),
-            (r'\.[a-z0-9_]+', Keyword.Pseudo),
+            (r'\.\w+', Keyword.Pseudo),
             (r'[-+~*/^&|!<>=]', Operator),
             (r'"[^"\n]*.', String),
             (r"'[^'\n]*.", String.Char),
             (r'\$[0-9a-f]+|[0-9a-f]+h\b', Number.Hex),
-            (r'\d+|%[01]+', Number.Integer),
-            (r'[#,.:()=]', Punctuation),
+            (r'\d+', Number.Integer),
+            (r'%[01]+', Number.Bin),
+            (r'[#,.:()=\[\]]', Punctuation),
             (r'[a-z_.@$][\w.@$]*', Name),
         ]
     }

eric ide

mercurial