2007-10-21 20:55:29 -04:00
|
|
|
import color, mode
|
2007-10-21 20:52:48 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule
|
2007-07-21 11:40:53 -04:00
|
|
|
|
|
|
|
class StringGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'octal', r'\\[0-7]{3}'),
|
|
|
|
PatternRule(r'escaped', r'\\.'),
|
|
|
|
]
|
|
|
|
|
|
|
|
class NasmGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'keyword', r"(?:section|global|extern)(?![a-zA-Z_])"),
|
|
|
|
PatternRule(r'macros', r"%(?:define|undef|assign|strlen|macro|endmacro|if|elif|else|endif|ifdef|ifndef|include|push|pop|stacksize)(?![a-zA-Z_])"),
|
|
|
|
PatternRule(r'instructions', r"(?:jeq|jne|ja|jmp|push|pushad|pushfd|call|ret|sub|add|pop|popa|popad|popfd|call|and|cwd|cdq|cmp|cmpxchg|cpuid|div|divpd|enter|leave|fadd|fld|fmul|fsqrt|fsub|hlt|imul|inc|int|int3|lea|mov|movd|mul|neg|not|nop|or|sal|sar|shl|shr|shld|shrd|syscall|sysenter|sysexit|test|xchg|xadd|xor)(?![a-zA-Z_])"),
|
|
|
|
PatternRule(r'registers', r"(?:eax|ax|ah|al|ebx|bx|bh|bl|ecx|cx|ch|cl|esi|edi|esp|ebp)(?![a-zA-Z_])"),
|
|
|
|
PatternRule(r'prefix', r"(?:dword|word|lock)(?![a-zA-Z_])"),
|
|
|
|
PatternRule(r'label', r"[a-zA-Z_.][a-zA-Z0-9_.]*:"),
|
|
|
|
PatternRule(r"identifier", r"[a-zA-Z_][a-zA-Z0-9_]*"),
|
|
|
|
PatternRule(r"integer", r"(0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
|
|
|
|
PatternRule(r"float", r"[0-9]+\.[0-9]*|\.[0-9]+|([0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
|
|
|
|
RegionRule(r'string', r'"""', StringGrammar, r'"""'),
|
|
|
|
RegionRule(r'string', r"'''", StringGrammar, r"'''"),
|
|
|
|
RegionRule(r'string', r'"', StringGrammar, r'"'),
|
|
|
|
RegionRule(r'string', r"'", StringGrammar, r"'"),
|
|
|
|
PatternRule(r'comment', r';.*$'),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2007-10-21 20:55:29 -04:00
|
|
|
class Nasm(mode.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'nasm'
|
|
|
|
extensions = ['.s']
|
|
|
|
grammar = NasmGrammar
|
|
|
|
colors = {
|
2007-07-21 11:40:53 -04:00
|
|
|
'keyword': ('cyan', 'default', 'bold'),
|
|
|
|
'macros': ('blue', 'default', 'bold'),
|
|
|
|
'string.start': ('green', 'default'),
|
|
|
|
'string.null': ('green', 'default'),
|
|
|
|
'string.end': ('green', 'default'),
|
|
|
|
'comment': ('red', 'default'),
|
|
|
|
'registers': ('yellow', 'default'),
|
|
|
|
'instructions': ('magenta', 'default'),
|
|
|
|
'label': ('blue', 'default'),
|
|
|
|
}
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = Nasm.install
|