improvements to nasm mode

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2010-10-16 11:03:34 -04:00
parent 111bd2546c
commit 7f02011b88
2 changed files with 8 additions and 5 deletions

4
lex.py
View File

@ -351,8 +351,8 @@ class RegionRule(Rule):
if self.pairs[i][1]: if self.pairs[i][1]:
try: try:
stopre = re.compile(self.pairs[i][1] % matchd, self.reflags) stopre = re.compile(self.pairs[i][1] % matchd, self.reflags)
except: except Exception, e:
raise Exception, "%r\n%r\n%r" % (self.pairs[i][1], matchd, self.reflags) raise Exception, "%r\n%r\n%r\n%r" % (e, self.pairs[i][1], matchd, self.reflags)
else: else:
stopre = None stopre = None
if i == len(self.pairs) - 1: if i == len(self.pairs) - 1:

View File

@ -11,15 +11,19 @@ word = chr1 + chr2 + '*'
class NasmGrammar(Grammar): class NasmGrammar(Grammar):
rules = [ rules = [
PatternRule('comment', ';.*$'),
RegionRule('comment', '%if +0', Grammar, r'%%endif'),
# for use with ndisasm files # for use with ndisasm files
PatternRule('nasm.address', '^[0-9a-fA-F]+ +[0-9a-fA-F]+'), PatternMatchRule('x', '^([0-9a-fA-F]{8})( )([0-9a-fA-F]+)', 'nasm.integer', 'spaces', 'nasm.address'),
PatternRule('nasm.address', '^[0-9a-fA-F]{8} [0-9a-fA-F]+'),
PatternRule('spaces', ' +'), PatternRule('spaces', ' +'),
PatternRule("nasm.integer", "(0[xX][0-9a-fA-F]+|0|[1-9][0-9]*|0[0-7]+)[lL]?"), PatternRule("nasm.integer", "(0[xX][0-9a-fA-F]+|0|[1-9][0-9]*|0[0-7]+)[lL]?"),
PatternRule('nasm.register', "(?:eax|ebx|ecx|edx|ax|ah|al|bx|bh|bl|bp|cx|ch|cl|cmpsb|dh|di|dl|ds|dx|esi|es|edi|esp|ebp|si|sp|stosd)(?!" + chr2 + ")"), PatternRule('nasm.register', "(?:eax|ebx|ecx|edx|ax|ah|al|bx|bh|bl|bp|cx|ch|cl|cmpsb|dh|di|dl|ds|dx|esi|es|edi|esp|ebp|si|sp|stosd)(?!" + chr2 + ")"),
PatternRule('nasm.pseudo', "(?:a16|a32|byte|db|dd|do|dq|dt|dword|qword|tword|fs|gs|near|o16|o32|short)(?!" + chr2 + ")"), PatternRule('nasm.pseudo', "(?:a16|a32|byte|db|dd|do|dq|dt|dword|qword|tword|fs|gs|near|o16|o32|short)(?!" + chr2 + ")"),
PatternRule('nasm.instruction', "(?:jg|jeq|jecxz|jne|ja|jmp|push|pushad|pushfd|call|ret|sub|adc|add|popad|popaw|popa|popfd|pop|call|and|arpl|bound|cwd|cdq|clc|cld|cli|cmp|cmpxchg|cpuid|das|dec|divpd|div|enter|leave|fadd|fld|fmul|fsqrt|fsub|fs|hlt|imul|inc|insb|insd|insw|ins|int|int3|in|jcxz|jc|jna|jnc|jnz|jo|js|jz|lea|lldt|loadsb|lock|loopne|movzx|movd|mov|mul|neg|not|nop|or|outsb|outsd|outsw|repe|retf|rol|sal|sar|sbb|scasw|shl|shr|shld|shrd|sldt|syscall|sysenter|sysexit|test|xchg|xadd|xor)(?!" + chr2 + ")"), PatternRule('nasm.instruction', "(?:jg|jeq|jecxz|jne|ja|jmp|push|pushad|pushfd|call|ret|sub|adc|add|popad|popaw|popa|popfd|pop|call|and|arpl|bound|cwd|cdq|clc|cld|cli|cmp|cmpxchg|cpuid|das|dec|divpd|div|enter|leave|fadd|fld|fmul|fsqrt|fsub|fs|hlt|imul|inc|insb|insd|insw|ins|int|int3|in|jcxz|jc|jna|jnc|jnz|jo|js|jz|lea|lldt|loadsb|lock|loopne|movzx|movd|mov|mul|neg|not|nop|or|outsb|outsd|outsw|repe|retf|rol|sal|sar|sbb|scasw|shl|shr|shld|shrd|sldt|syscall|sysenter|sysexit|test|xchg|xadd|xor)(?!" + chr2 + ")"),
PatternRule('nasm.macro', "%(?:define|undef|assign|strlen|macro|endmacro|if|elif|else|endif|ifdef|ifndef|include|push|pop|stacksize)(?!" + chr2 + ")"), PatternRule('nasm.macro', "\%(?:define|undef|assign|strlen|macro|endmacro|if|elif|else|endif|ifdef|ifndef|include|push|pop|stacksize)(?!" + chr2 + ")"),
PatternRule('nasm.keyword', "(?:section|global|extern)(?!" + chr2 + ")"), PatternRule('nasm.keyword', "(?:section|global|extern)(?!" + chr2 + ")"),
PatternRule('nasm.prefix', "(?:dword|word|lock)(?!" + chr2 + ")"), PatternRule('nasm.prefix', "(?:dword|word|lock)(?!" + chr2 + ")"),
PatternMatchRule('x', '(' + word + ')(:)', 'nasm.label', 'delimiter'), PatternMatchRule('x', '(' + word + ')(:)', 'nasm.label', 'delimiter'),
@ -30,7 +34,6 @@ class NasmGrammar(Grammar):
RegionRule('string', "'''", StringGrammar3, "'''"), RegionRule('string', "'''", StringGrammar3, "'''"),
RegionRule('string', '"', StringGrammar2, '"'), RegionRule('string', '"', StringGrammar2, '"'),
RegionRule('string', "'", StringGrammar1, "'"), RegionRule('string', "'", StringGrammar1, "'"),
PatternRule('comment', ';.*$'),
PatternRule('eol', '\n'), PatternRule('eol', '\n'),
PatternRule('continuation', r'\\\n$'), PatternRule('continuation', r'\\\n$'),
] ]