From 6639271c29204ebdc85d12e7ab7c789c3aa3fc47 Mon Sep 17 00:00:00 2001 From: moculus Date: Sun, 24 Jun 2007 14:29:05 +0000 Subject: [PATCH] nasm readded --HG-- branch : pmacs2 --- application.py | 15 ++++++-------- mode_nasm.py | 56 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/application.py b/application.py index 81f57c2..2b44c40 100755 --- a/application.py +++ b/application.py @@ -7,12 +7,12 @@ import util, window2 from point2 import Point # modes -# TODO: mode_c mode_nasm mode_sh mode_sql mode_javascript mode_diff mode_tt +# TODO: mode_c mode_nasm mode_sh mode_sql mode_javascript mode_tt import mode2 import mode_mini, mode_search, mode_replace, mode_which import mode_console, mode_consolemini import mode_blame, mode_diff -import mode_python, mode_perl, mode_xml +import mode_python, mode_perl, mode_xml, mode_nasm import mode_life, mode_text, mode_mutt def run(buffers, jump_to_line=None, init_mode=None): @@ -88,7 +88,7 @@ class Application(object): 'diff': mode_diff.Diff, 'fundamental': mode2.Fundamental, 'mini': mode_mini.Mini, -# 'nasm': mode_nasm.Nasm, + 'nasm': mode_nasm.Nasm, 'perl': mode_perl.Perl, 'python': mode_python.Python, 'replace': mode_replace.Replace, @@ -121,13 +121,13 @@ class Application(object): '.t': 'perl', # '.c': 'c', '.txt': 'text', -# '.s': 'nasm', + '.s': 'nasm', # '.sh': 'sh', # '.bash': 'sh', '.xml': 'xml', '.xml.in': 'xml', -# '.html': 'xml', -# '.htm': 'xml', + '.html': 'xml', + '.htm': 'xml', # '.sql': 'sql', # '.js': 'javascript', # '.tt': 'template' @@ -148,9 +148,6 @@ class Application(object): # create all the insert methods for the character ranges we like for c in string.letters + string.digits + string.punctuation: - ## closing tags are handled differently - #if c == ')' or c == ']' or c == '}': - # continue obj = method.InsertString(c) self.methods[obj.name] = obj diff --git a/mode_nasm.py b/mode_nasm.py index ddde262..daef510 100644 --- a/mode_nasm.py +++ b/mode_nasm.py @@ -1,29 +1,51 @@ -import sets, sys +import color, mode2 +from lex2 import Grammar, PatternRule, RegionRule -import color, mode, lex, lex_nasm +class StringGrammar(Grammar): + rules = [ + PatternRule( + name=r'octal', + pattern=r'\\[0-7]{3}', + ), + PatternRule( + name=r'escaped', + pattern=r'\\.', + ), + ] -class Nasm(mode.Fundamental): +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';.*$'), + ] + + +class Nasm(mode2.Fundamental): + grammar = NasmGrammar() def __init__(self, w): - mode.Fundamental.__init__(self, w) - - self.grammar = lex_nasm.NasmGrammar() - self.lexer = lex.Lexer(self.grammar) - - self.default_color = color.build('default', 'default') + mode2.Fundamental.__init__(self, w) self.colors = { 'keyword': color.build('cyan', 'default', 'bold'), - 'nasm macros': color.build('blue', 'default', 'bold'), - 'string3': color.build('green', 'default'), - 'string2': color.build('green', 'default'), - 'string1': color.build('green', 'default'), + 'macros': color.build('blue', 'default', 'bold'), + 'string.start': color.build('green', 'default'), + 'string.null': color.build('green', 'default'), + 'string.end': color.build('green', 'default'), 'comment': color.build('red', 'default'), 'registers': color.build('yellow', 'default'), 'instructions': color.build('magenta', 'default'), 'label': color.build('blue', 'default'), } - - #self.highlighter.lex_buffer() - #self.get_regions() - def name(self): return "Nasm"