2007-06-24 10:29:05 -04:00
|
|
|
import color, mode2
|
2007-07-15 09:44:20 -04:00
|
|
|
from lex3 import Grammar, PatternRule, RegionRule
|
2007-03-06 10:05:38 -05:00
|
|
|
|
2007-06-24 10:29:05 -04:00
|
|
|
class StringGrammar(Grammar):
|
|
|
|
rules = [
|
2007-06-24 10:30:42 -04:00
|
|
|
PatternRule(name=r'octal', pattern=r'\\[0-7]{3}'),
|
|
|
|
PatternRule(name=r'escaped', pattern=r'\\.'),
|
2007-06-24 10:29:05 -04:00
|
|
|
]
|
2007-03-06 10:05:38 -05:00
|
|
|
|
2007-06-24 10:29:05 -04:00
|
|
|
class NasmGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(name=r'keyword', pattern=r"(?:section|global|extern)(?![a-zA-Z_])"),
|
|
|
|
PatternRule(name=r'macros', pattern=r"%(?:define|undef|assign|strlen|macro|endmacro|if|elif|else|endif|ifdef|ifndef|include|push|pop|stacksize)(?![a-zA-Z_])"),
|
|
|
|
PatternRule(name=r'instructions', pattern=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(name=r'registers', pattern=r"(?:eax|ax|ah|al|ebx|bx|bh|bl|ecx|cx|ch|cl|esi|edi|esp|ebp)(?![a-zA-Z_])"),
|
|
|
|
PatternRule(name=r'prefix', pattern=r"(?:dword|word|lock)(?![a-zA-Z_])"),
|
|
|
|
PatternRule(name=r'label', pattern=r"[a-zA-Z_.][a-zA-Z0-9_.]*:"),
|
|
|
|
PatternRule(name=r"identifier", pattern=r"[a-zA-Z_][a-zA-Z0-9_]*"),
|
|
|
|
PatternRule(name=r"integer", pattern=r"(0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
|
|
|
|
PatternRule(name=r"float", pattern=r"[0-9]+\.[0-9]*|\.[0-9]+|([0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
|
|
|
|
RegionRule(name=r'string', start=r'"""', grammar=StringGrammar(), end=r'"""'),
|
|
|
|
RegionRule(name=r'string', start=r"'''", grammar=StringGrammar(), end=r"'''"),
|
|
|
|
RegionRule(name=r'string', start=r'"', grammar=StringGrammar(), end=r'"'),
|
|
|
|
RegionRule(name=r'string', start=r"'", grammar=StringGrammar(), end=r"'"),
|
|
|
|
PatternRule(name=r'comment', pattern=r';.*$'),
|
|
|
|
]
|
2007-03-06 10:05:38 -05:00
|
|
|
|
|
|
|
|
2007-06-24 10:29:05 -04:00
|
|
|
class Nasm(mode2.Fundamental):
|
|
|
|
grammar = NasmGrammar()
|
|
|
|
def __init__(self, w):
|
|
|
|
mode2.Fundamental.__init__(self, w)
|
2007-03-06 10:05:38 -05:00
|
|
|
self.colors = {
|
|
|
|
'keyword': color.build('cyan', 'default', 'bold'),
|
2007-06-24 10:29:05 -04:00
|
|
|
'macros': color.build('blue', 'default', 'bold'),
|
|
|
|
'string.start': color.build('green', 'default'),
|
|
|
|
'string.null': color.build('green', 'default'),
|
|
|
|
'string.end': color.build('green', 'default'),
|
2007-03-06 10:05:38 -05:00
|
|
|
'comment': color.build('red', 'default'),
|
|
|
|
'registers': color.build('yellow', 'default'),
|
|
|
|
'instructions': color.build('magenta', 'default'),
|
|
|
|
'label': color.build('blue', 'default'),
|
|
|
|
}
|
|
|
|
def name(self):
|
|
|
|
return "Nasm"
|