pmacs3/mode/nasm.py

43 lines
2.1 KiB
Python
Raw Normal View History

2009-03-31 23:24:28 -04:00
from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
from mode.python import StringGrammar1, StringGrammar2, StringGrammar3, StringGrammar4
2007-07-21 11:40:53 -04:00
chr1 = '[a-zA-Z_.?]'
chr2 = '[a-zA-Z0-9_.?$#@~]'
word = chr1 + chr2 + '*'
2007-07-21 11:40:53 -04:00
class NasmGrammar(Grammar):
rules = [
PatternRule('continuation', r'\\\n$'),
PatternRule('nasm_keyword', "(?:section|global|extern)(?!" + chr2 + ")"),
PatternRule('macros', "%(?:define|undef|assign|strlen|macro|endmacro|if|elif|else|endif|ifdef|ifndef|include|push|pop|stacksize)(?!" + chr2 + ")"),
PatternRule('instructions', "(?: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)(?!" + chr2 + ")"),
PatternRule('registers', "(?:eax|ax|ah|al|ebx|bx|bh|bl|ecx|cx|ch|cl|esi|edi|esp|ebp)(?!" + chr2 + ")"),
PatternRule('prefix', "(?:dword|word|lock)(?!" + chr2 + ")"),
PatternMatchRule('x', '(' + word + ')(:)', 'nasm_label', 'delimiter'),
#PatternRule('nasm_label', word + ":"),
PatternRule("identifier", r'\$?' + word),
PatternRule("integer", "(0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
PatternRule("float", r"[0-9]+\.[0-9]*|\.[0-9]+|([0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
RegionRule('string', "'''", StringGrammar3, "'''"),
RegionRule('string', '"""', StringGrammar4, '"""'),
RegionRule('string', "'", StringGrammar1, "'"),
RegionRule('string', '"', StringGrammar2, '"'),
PatternRule('comment', ';.*$'),
2007-07-21 11:40:53 -04:00
]
2009-03-31 23:24:28 -04:00
class Nasm(Fundamental):
name = 'nasm'
2007-10-18 17:07:35 -04:00
extensions = ['.s']
grammar = NasmGrammar
2009-02-15 12:06:35 -05:00
commentc = ';'
2007-10-18 17:07:35 -04:00
colors = {
2008-04-06 23:22:16 -04:00
'nasm_keyword': ('cyan', 'default', 'bold'),
2007-07-21 11:40:53 -04:00
'macros': ('blue', 'default', 'bold'),
'registers': ('yellow', 'default', 'bold'),
'instructions': ('magenta', 'default', 'bold'),
'nasm_label': ('blue', 'default', 'bold'),
2007-07-21 11:40:53 -04:00
}
2007-10-19 02:41:33 -04:00
install = Nasm.install