2013-09-22 20:39:16 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
pygments.lexers.asm
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Lexers for assembly languages.
|
|
|
|
|
2016-06-13 14:41:17 +00:00
|
|
|
:copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
|
2013-09-22 20:39:16 +00:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from pygments.lexer import RegexLexer, include, bygroups, using, DelegatingLexer
|
2014-12-01 06:10:30 +00:00
|
|
|
from pygments.lexers.c_cpp import CppLexer, CLexer
|
|
|
|
from pygments.lexers.d import DLexer
|
2013-09-22 20:39:16 +00:00
|
|
|
from pygments.token import Text, Name, Number, String, Comment, Punctuation, \
|
2014-12-01 06:10:30 +00:00
|
|
|
Other, Keyword, Operator
|
2013-09-22 20:39:16 +00:00
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
__all__ = ['GasLexer', 'ObjdumpLexer', 'DObjdumpLexer', 'CppObjdumpLexer',
|
|
|
|
'CObjdumpLexer', 'LlvmLexer', 'NasmLexer', 'NasmObjdumpLexer',
|
|
|
|
'Ca65Lexer']
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GasLexer(RegexLexer):
|
|
|
|
"""
|
|
|
|
For Gas (AT&T) assembly code.
|
|
|
|
"""
|
|
|
|
name = 'GAS'
|
|
|
|
aliases = ['gas', 'asm']
|
|
|
|
filenames = ['*.s', '*.S']
|
|
|
|
mimetypes = ['text/x-gas']
|
|
|
|
|
|
|
|
#: optional Comment or Whitespace
|
|
|
|
string = r'"(\\"|[^"])*"'
|
2014-12-01 06:10:30 +00:00
|
|
|
char = r'[\w$.@-]'
|
2013-09-22 20:39:16 +00:00
|
|
|
identifier = r'(?:[a-zA-Z$_]' + char + '*|\.' + char + '+)'
|
|
|
|
number = r'(?:0[xX][a-zA-Z0-9]+|\d+)'
|
|
|
|
|
|
|
|
tokens = {
|
|
|
|
'root': [
|
|
|
|
include('whitespace'),
|
|
|
|
(identifier + ':', Name.Label),
|
|
|
|
(r'\.' + identifier, Name.Attribute, 'directive-args'),
|
|
|
|
(r'lock|rep(n?z)?|data\d+', Name.Attribute),
|
|
|
|
(identifier, Name.Function, 'instruction-args'),
|
|
|
|
(r'[\r\n]+', Text)
|
|
|
|
],
|
|
|
|
'directive-args': [
|
|
|
|
(identifier, Name.Constant),
|
|
|
|
(string, String),
|
|
|
|
('@' + identifier, Name.Attribute),
|
|
|
|
(number, Number.Integer),
|
|
|
|
(r'[\r\n]+', Text, '#pop'),
|
|
|
|
|
|
|
|
(r'#.*?$', Comment, '#pop'),
|
|
|
|
|
|
|
|
include('punctuation'),
|
|
|
|
include('whitespace')
|
|
|
|
],
|
|
|
|
'instruction-args': [
|
|
|
|
# For objdump-disassembled code, shouldn't occur in
|
|
|
|
# actual assembler input
|
|
|
|
('([a-z0-9]+)( )(<)('+identifier+')(>)',
|
|
|
|
bygroups(Number.Hex, Text, Punctuation, Name.Constant,
|
|
|
|
Punctuation)),
|
|
|
|
('([a-z0-9]+)( )(<)('+identifier+')([-+])('+number+')(>)',
|
|
|
|
bygroups(Number.Hex, Text, Punctuation, Name.Constant,
|
|
|
|
Punctuation, Number.Integer, Punctuation)),
|
|
|
|
|
|
|
|
# Address constants
|
|
|
|
(identifier, Name.Constant),
|
|
|
|
(number, Number.Integer),
|
|
|
|
# Registers
|
|
|
|
('%' + identifier, Name.Variable),
|
|
|
|
# Numeric constants
|
|
|
|
('$'+number, Number.Integer),
|
|
|
|
(r"$'(.|\\')'", String.Char),
|
|
|
|
(r'[\r\n]+', Text, '#pop'),
|
|
|
|
(r'#.*?$', Comment, '#pop'),
|
|
|
|
include('punctuation'),
|
|
|
|
include('whitespace')
|
|
|
|
],
|
|
|
|
'whitespace': [
|
|
|
|
(r'\n', Text),
|
|
|
|
(r'\s+', Text),
|
|
|
|
(r'#.*?\n', Comment)
|
|
|
|
],
|
|
|
|
'punctuation': [
|
2016-06-13 14:41:17 +00:00
|
|
|
(r'[-*,.()\[\]!:]+', Punctuation)
|
2013-09-22 20:39:16 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
def analyse_text(text):
|
|
|
|
if re.match(r'^\.(text|data|section)', text, re.M):
|
|
|
|
return True
|
|
|
|
elif re.match(r'^\.\w+', text, re.M):
|
|
|
|
return 0.1
|
|
|
|
|
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
def _objdump_lexer_tokens(asm_lexer):
|
2013-09-22 20:39:16 +00:00
|
|
|
"""
|
2014-12-01 06:10:30 +00:00
|
|
|
Common objdump lexer tokens to wrap an ASM lexer.
|
2013-09-22 20:39:16 +00:00
|
|
|
"""
|
2014-12-01 06:10:30 +00:00
|
|
|
hex_re = r'[0-9A-Za-z]'
|
|
|
|
return {
|
2013-09-22 20:39:16 +00:00
|
|
|
'root': [
|
|
|
|
# File name & format:
|
|
|
|
('(.*?)(:)( +file format )(.*?)$',
|
|
|
|
bygroups(Name.Label, Punctuation, Text, String)),
|
|
|
|
# Section header
|
|
|
|
('(Disassembly of section )(.*?)(:)$',
|
|
|
|
bygroups(Text, Name.Label, Punctuation)),
|
|
|
|
# Function labels
|
|
|
|
# (With offset)
|
2014-12-01 06:10:30 +00:00
|
|
|
('('+hex_re+'+)( )(<)(.*?)([-+])(0[xX][A-Za-z0-9]+)(>:)$',
|
2013-09-22 20:39:16 +00:00
|
|
|
bygroups(Number.Hex, Text, Punctuation, Name.Function,
|
|
|
|
Punctuation, Number.Hex, Punctuation)),
|
|
|
|
# (Without offset)
|
2014-12-01 06:10:30 +00:00
|
|
|
('('+hex_re+'+)( )(<)(.*?)(>:)$',
|
2013-09-22 20:39:16 +00:00
|
|
|
bygroups(Number.Hex, Text, Punctuation, Name.Function,
|
|
|
|
Punctuation)),
|
|
|
|
# Code line with disassembled instructions
|
2014-12-01 06:10:30 +00:00
|
|
|
('( *)('+hex_re+r'+:)(\t)((?:'+hex_re+hex_re+' )+)( *\t)([a-zA-Z].*?)$',
|
2013-09-22 20:39:16 +00:00
|
|
|
bygroups(Text, Name.Label, Text, Number.Hex, Text,
|
2014-12-01 06:10:30 +00:00
|
|
|
using(asm_lexer))),
|
2013-09-22 20:39:16 +00:00
|
|
|
# Code line with ascii
|
2014-12-01 06:10:30 +00:00
|
|
|
('( *)('+hex_re+r'+:)(\t)((?:'+hex_re+hex_re+' )+)( *)(.*?)$',
|
2013-09-22 20:39:16 +00:00
|
|
|
bygroups(Text, Name.Label, Text, Number.Hex, Text, String)),
|
|
|
|
# Continued code line, only raw opcodes without disassembled
|
|
|
|
# instruction
|
2014-12-01 06:10:30 +00:00
|
|
|
('( *)('+hex_re+r'+:)(\t)((?:'+hex_re+hex_re+' )+)$',
|
2013-09-22 20:39:16 +00:00
|
|
|
bygroups(Text, Name.Label, Text, Number.Hex)),
|
|
|
|
# Skipped a few bytes
|
|
|
|
(r'\t\.\.\.$', Text),
|
|
|
|
# Relocation line
|
|
|
|
# (With offset)
|
2014-12-01 06:10:30 +00:00
|
|
|
(r'(\t\t\t)('+hex_re+r'+:)( )([^\t]+)(\t)(.*?)([-+])(0x'+hex_re+'+)$',
|
2013-09-22 20:39:16 +00:00
|
|
|
bygroups(Text, Name.Label, Text, Name.Property, Text,
|
|
|
|
Name.Constant, Punctuation, Number.Hex)),
|
|
|
|
# (Without offset)
|
2014-12-01 06:10:30 +00:00
|
|
|
(r'(\t\t\t)('+hex_re+r'+:)( )([^\t]+)(\t)(.*?)$',
|
2013-09-22 20:39:16 +00:00
|
|
|
bygroups(Text, Name.Label, Text, Name.Property, Text,
|
|
|
|
Name.Constant)),
|
|
|
|
(r'[^\n]+\n', Other)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
class ObjdumpLexer(RegexLexer):
|
|
|
|
"""
|
|
|
|
For the output of 'objdump -dr'
|
|
|
|
"""
|
|
|
|
name = 'objdump'
|
|
|
|
aliases = ['objdump']
|
|
|
|
filenames = ['*.objdump']
|
|
|
|
mimetypes = ['text/x-objdump']
|
|
|
|
|
|
|
|
tokens = _objdump_lexer_tokens(GasLexer)
|
|
|
|
|
|
|
|
|
2013-09-22 20:39:16 +00:00
|
|
|
class DObjdumpLexer(DelegatingLexer):
|
|
|
|
"""
|
|
|
|
For the output of 'objdump -Sr on compiled D files'
|
|
|
|
"""
|
|
|
|
name = 'd-objdump'
|
|
|
|
aliases = ['d-objdump']
|
|
|
|
filenames = ['*.d-objdump']
|
|
|
|
mimetypes = ['text/x-d-objdump']
|
|
|
|
|
|
|
|
def __init__(self, **options):
|
|
|
|
super(DObjdumpLexer, self).__init__(DLexer, ObjdumpLexer, **options)
|
|
|
|
|
|
|
|
|
|
|
|
class CppObjdumpLexer(DelegatingLexer):
|
|
|
|
"""
|
|
|
|
For the output of 'objdump -Sr on compiled C++ files'
|
|
|
|
"""
|
|
|
|
name = 'cpp-objdump'
|
|
|
|
aliases = ['cpp-objdump', 'c++-objdumb', 'cxx-objdump']
|
|
|
|
filenames = ['*.cpp-objdump', '*.c++-objdump', '*.cxx-objdump']
|
|
|
|
mimetypes = ['text/x-cpp-objdump']
|
|
|
|
|
|
|
|
def __init__(self, **options):
|
|
|
|
super(CppObjdumpLexer, self).__init__(CppLexer, ObjdumpLexer, **options)
|
|
|
|
|
|
|
|
|
|
|
|
class CObjdumpLexer(DelegatingLexer):
|
|
|
|
"""
|
|
|
|
For the output of 'objdump -Sr on compiled C files'
|
|
|
|
"""
|
|
|
|
name = 'c-objdump'
|
|
|
|
aliases = ['c-objdump']
|
|
|
|
filenames = ['*.c-objdump']
|
|
|
|
mimetypes = ['text/x-c-objdump']
|
|
|
|
|
|
|
|
def __init__(self, **options):
|
|
|
|
super(CObjdumpLexer, self).__init__(CLexer, ObjdumpLexer, **options)
|
|
|
|
|
|
|
|
|
|
|
|
class LlvmLexer(RegexLexer):
|
|
|
|
"""
|
|
|
|
For LLVM assembly code.
|
|
|
|
"""
|
|
|
|
name = 'LLVM'
|
|
|
|
aliases = ['llvm']
|
|
|
|
filenames = ['*.ll']
|
|
|
|
mimetypes = ['text/x-llvm']
|
|
|
|
|
|
|
|
#: optional Comment or Whitespace
|
|
|
|
string = r'"[^"]*?"'
|
2014-12-01 06:10:30 +00:00
|
|
|
identifier = r'([-a-zA-Z$._][\w\-$.]*|' + string + ')'
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
tokens = {
|
|
|
|
'root': [
|
|
|
|
include('whitespace'),
|
|
|
|
|
|
|
|
# Before keywords, because keywords are valid label names :(...
|
|
|
|
(identifier + '\s*:', Name.Label),
|
|
|
|
|
|
|
|
include('keyword'),
|
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
(r'%' + identifier, Name.Variable),
|
|
|
|
(r'@' + identifier, Name.Variable.Global),
|
|
|
|
(r'%\d+', Name.Variable.Anonymous),
|
|
|
|
(r'@\d+', Name.Variable.Global),
|
|
|
|
(r'#\d+', Name.Variable.Global),
|
2013-09-22 20:39:16 +00:00
|
|
|
(r'!' + identifier, Name.Variable),
|
|
|
|
(r'!\d+', Name.Variable.Anonymous),
|
|
|
|
(r'c?' + string, String),
|
|
|
|
|
|
|
|
(r'0[xX][a-fA-F0-9]+', Number),
|
|
|
|
(r'-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?', Number),
|
|
|
|
|
|
|
|
(r'[=<>{}\[\]()*.,!]|x\b', Punctuation)
|
|
|
|
],
|
|
|
|
'whitespace': [
|
|
|
|
(r'(\n|\s)+', Text),
|
|
|
|
(r';.*?\n', Comment)
|
|
|
|
],
|
|
|
|
'keyword': [
|
|
|
|
# Regular keywords
|
|
|
|
(r'(begin|end'
|
|
|
|
r'|true|false'
|
|
|
|
r'|declare|define'
|
|
|
|
r'|global|constant'
|
|
|
|
|
|
|
|
r'|private|linker_private|internal|available_externally|linkonce'
|
|
|
|
r'|linkonce_odr|weak|weak_odr|appending|dllimport|dllexport'
|
|
|
|
r'|common|default|hidden|protected|extern_weak|external'
|
|
|
|
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'
|
2014-12-01 06:10:30 +00:00
|
|
|
r'|linker_private_weak'
|
|
|
|
r'|attributes|blockaddress|initialexec|localdynamic|localexec'
|
|
|
|
r'|prefix|unnamed_addr'
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
r'|ccc|fastcc|coldcc|x86_stdcallcc|x86_fastcallcc|arm_apcscc'
|
|
|
|
r'|arm_aapcscc|arm_aapcs_vfpcc|ptx_device|ptx_kernel'
|
2014-12-01 06:10:30 +00:00
|
|
|
r'|intel_ocl_bicc|msp430_intrcc|spir_func|spir_kernel'
|
|
|
|
r'|x86_64_sysvcc|x86_64_win64cc|x86_thiscallcc'
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
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'
|
2014-12-01 06:10:30 +00:00
|
|
|
r'|builtin|cold|nobuiltin|noduplicate|nonlazybind|optnone'
|
|
|
|
r'|returns_twice|sanitize_address|sanitize_memory|sanitize_thread'
|
|
|
|
r'|sspstrong|uwtable|returned'
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
r'|type|opaque'
|
|
|
|
|
|
|
|
r'|eq|ne|slt|sgt|sle'
|
|
|
|
r'|sge|ult|ugt|ule|uge'
|
|
|
|
r'|oeq|one|olt|ogt|ole'
|
|
|
|
r'|oge|ord|uno|ueq|une'
|
|
|
|
r'|x'
|
2014-12-01 06:10:30 +00:00
|
|
|
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'
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
# 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'
|
2016-06-13 14:41:17 +00:00
|
|
|
r'|fptosi|inttoptr|ptrtoint|bitcast|addrspacecast'
|
|
|
|
r'|select|va_arg|ret|br|switch'
|
2013-09-22 20:39:16 +00:00
|
|
|
r'|invoke|unwind|unreachable'
|
2014-12-01 06:10:30 +00:00
|
|
|
r'|indirectbr|landingpad|resume'
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
r'|malloc|alloca|free|load|store|getelementptr'
|
|
|
|
|
|
|
|
r'|extractelement|insertelement|shufflevector|getresult'
|
|
|
|
r'|extractvalue|insertvalue'
|
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
r'|atomicrmw|cmpxchg|fence'
|
|
|
|
|
2013-09-22 20:39:16 +00:00
|
|
|
r')\b', Keyword),
|
|
|
|
|
|
|
|
# Types
|
2014-12-01 06:10:30 +00:00
|
|
|
(r'void|half|float|double|x86_fp80|fp128|ppc_fp128|label|metadata',
|
2013-09-22 20:39:16 +00:00
|
|
|
Keyword.Type),
|
|
|
|
|
|
|
|
# Integer types
|
|
|
|
(r'i[1-9]\d*', Keyword)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class NasmLexer(RegexLexer):
|
|
|
|
"""
|
|
|
|
For Nasm (Intel) assembly code.
|
|
|
|
"""
|
|
|
|
name = 'NASM'
|
|
|
|
aliases = ['nasm']
|
|
|
|
filenames = ['*.asm', '*.ASM']
|
|
|
|
mimetypes = ['text/x-nasm']
|
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
identifier = r'[a-z$._?][\w$.?#@~]*'
|
|
|
|
hexn = r'(?:0x[0-9a-f]+|$0[0-9a-f]*|[0-9]+[0-9a-f]*h)'
|
2013-09-22 20:39:16 +00:00
|
|
|
octn = r'[0-7]+q'
|
|
|
|
binn = r'[01]+b'
|
|
|
|
decn = r'[0-9]+'
|
|
|
|
floatn = decn + r'\.e?' + decn
|
|
|
|
string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`"
|
|
|
|
declkw = r'(?:res|d)[bwdqt]|times'
|
|
|
|
register = (r'r[0-9][0-5]?[bwd]|'
|
|
|
|
r'[a-d][lh]|[er]?[a-d]x|[er]?[sb]p|[er]?[sd]i|[c-gs]s|st[0-7]|'
|
|
|
|
r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]')
|
|
|
|
wordop = r'seg|wrt|strict'
|
|
|
|
type = r'byte|[dq]?word'
|
|
|
|
directives = (r'BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|'
|
|
|
|
r'ORG|ALIGN|STRUC|ENDSTRUC|COMMON|CPU|GROUP|UPPERCASE|IMPORT|'
|
|
|
|
r'EXPORT|LIBRARY|MODULE')
|
|
|
|
|
|
|
|
flags = re.IGNORECASE | re.MULTILINE
|
|
|
|
tokens = {
|
|
|
|
'root': [
|
|
|
|
(r'^\s*%', Comment.Preproc, 'preproc'),
|
2014-12-01 06:10:30 +00:00
|
|
|
include('whitespace'),
|
2013-09-22 20:39:16 +00:00
|
|
|
(identifier + ':', Name.Label),
|
|
|
|
(r'(%s)(\s+)(equ)' % identifier,
|
|
|
|
bygroups(Name.Constant, Keyword.Declaration, Keyword.Declaration),
|
|
|
|
'instruction-args'),
|
|
|
|
(directives, Keyword, 'instruction-args'),
|
|
|
|
(declkw, Keyword.Declaration, 'instruction-args'),
|
|
|
|
(identifier, Name.Function, 'instruction-args'),
|
|
|
|
(r'[\r\n]+', Text)
|
|
|
|
],
|
|
|
|
'instruction-args': [
|
|
|
|
(string, String),
|
|
|
|
(hexn, Number.Hex),
|
|
|
|
(octn, Number.Oct),
|
2014-12-01 06:10:30 +00:00
|
|
|
(binn, Number.Bin),
|
2013-09-22 20:39:16 +00:00
|
|
|
(floatn, Number.Float),
|
|
|
|
(decn, Number.Integer),
|
|
|
|
include('punctuation'),
|
|
|
|
(register, Name.Builtin),
|
|
|
|
(identifier, Name.Variable),
|
|
|
|
(r'[\r\n]+', Text, '#pop'),
|
|
|
|
include('whitespace')
|
|
|
|
],
|
|
|
|
'preproc': [
|
|
|
|
(r'[^;\n]+', Comment.Preproc),
|
|
|
|
(r';.*?\n', Comment.Single, '#pop'),
|
|
|
|
(r'\n', Comment.Preproc, '#pop'),
|
|
|
|
],
|
|
|
|
'whitespace': [
|
|
|
|
(r'\n', Text),
|
|
|
|
(r'[ \t]+', Text),
|
|
|
|
(r';.*', Comment.Single)
|
|
|
|
],
|
|
|
|
'punctuation': [
|
|
|
|
(r'[,():\[\]]+', Punctuation),
|
|
|
|
(r'[&|^<>+*/%~-]+', Operator),
|
|
|
|
(r'[$]+', Keyword.Constant),
|
|
|
|
(wordop, Operator.Word),
|
|
|
|
(type, Keyword.Type)
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2013-09-22 20:39:16 +00:00
|
|
|
class Ca65Lexer(RegexLexer):
|
|
|
|
"""
|
|
|
|
For ca65 assembler sources.
|
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
.. versionadded:: 1.6
|
2013-09-22 20:39:16 +00:00
|
|
|
"""
|
2014-12-01 06:10:30 +00:00
|
|
|
name = 'ca65 assembler'
|
2013-09-22 20:39:16 +00:00
|
|
|
aliases = ['ca65']
|
|
|
|
filenames = ['*.s']
|
|
|
|
|
|
|
|
flags = re.IGNORECASE
|
|
|
|
|
|
|
|
tokens = {
|
|
|
|
'root': [
|
|
|
|
(r';.*', Comment.Single),
|
|
|
|
(r'\s+', Text),
|
|
|
|
(r'[a-z_.@$][\w.@$]*:', Name.Label),
|
|
|
|
(r'((ld|st)[axy]|(in|de)[cxy]|asl|lsr|ro[lr]|adc|sbc|cmp|cp[xy]'
|
|
|
|
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),
|
2014-12-01 06:10:30 +00:00
|
|
|
(r'\.\w+', Keyword.Pseudo),
|
2013-09-22 20:39:16 +00:00
|
|
|
(r'[-+~*/^&|!<>=]', Operator),
|
|
|
|
(r'"[^"\n]*.', String),
|
|
|
|
(r"'[^'\n]*.", String.Char),
|
|
|
|
(r'\$[0-9a-f]+|[0-9a-f]+h\b', Number.Hex),
|
2014-12-01 06:10:30 +00:00
|
|
|
(r'\d+', Number.Integer),
|
|
|
|
(r'%[01]+', Number.Bin),
|
|
|
|
(r'[#,.:()=\[\]]', Punctuation),
|
2013-09-22 20:39:16 +00:00
|
|
|
(r'[a-z_.@$][\w.@$]*', Name),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
def analyse_text(self, text):
|
|
|
|
# comments in GAS start with "#"
|
|
|
|
if re.match(r'^\s*;', text, re.MULTILINE):
|
|
|
|
return 0.9
|