nasm readded

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-06-24 14:29:05 +00:00
parent 7f95a5cb7d
commit 6639271c29
2 changed files with 45 additions and 26 deletions

View File

@ -7,12 +7,12 @@ import util, window2
from point2 import Point from point2 import Point
# modes # 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 mode2
import mode_mini, mode_search, mode_replace, mode_which import mode_mini, mode_search, mode_replace, mode_which
import mode_console, mode_consolemini import mode_console, mode_consolemini
import mode_blame, mode_diff 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 import mode_life, mode_text, mode_mutt
def run(buffers, jump_to_line=None, init_mode=None): def run(buffers, jump_to_line=None, init_mode=None):
@ -88,7 +88,7 @@ class Application(object):
'diff': mode_diff.Diff, 'diff': mode_diff.Diff,
'fundamental': mode2.Fundamental, 'fundamental': mode2.Fundamental,
'mini': mode_mini.Mini, 'mini': mode_mini.Mini,
# 'nasm': mode_nasm.Nasm, 'nasm': mode_nasm.Nasm,
'perl': mode_perl.Perl, 'perl': mode_perl.Perl,
'python': mode_python.Python, 'python': mode_python.Python,
'replace': mode_replace.Replace, 'replace': mode_replace.Replace,
@ -121,13 +121,13 @@ class Application(object):
'.t': 'perl', '.t': 'perl',
# '.c': 'c', # '.c': 'c',
'.txt': 'text', '.txt': 'text',
# '.s': 'nasm', '.s': 'nasm',
# '.sh': 'sh', # '.sh': 'sh',
# '.bash': 'sh', # '.bash': 'sh',
'.xml': 'xml', '.xml': 'xml',
'.xml.in': 'xml', '.xml.in': 'xml',
# '.html': 'xml', '.html': 'xml',
# '.htm': 'xml', '.htm': 'xml',
# '.sql': 'sql', # '.sql': 'sql',
# '.js': 'javascript', # '.js': 'javascript',
# '.tt': 'template' # '.tt': 'template'
@ -148,9 +148,6 @@ class Application(object):
# create all the insert methods for the character ranges we like # create all the insert methods for the character ranges we like
for c in string.letters + string.digits + string.punctuation: 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) obj = method.InsertString(c)
self.methods[obj.name] = obj self.methods[obj.name] = obj

View File

@ -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): def __init__(self, w):
mode.Fundamental.__init__(self, w) mode2.Fundamental.__init__(self, w)
self.grammar = lex_nasm.NasmGrammar()
self.lexer = lex.Lexer(self.grammar)
self.default_color = color.build('default', 'default')
self.colors = { self.colors = {
'keyword': color.build('cyan', 'default', 'bold'), 'keyword': color.build('cyan', 'default', 'bold'),
'nasm macros': color.build('blue', 'default', 'bold'), 'macros': color.build('blue', 'default', 'bold'),
'string3': color.build('green', 'default'), 'string.start': color.build('green', 'default'),
'string2': color.build('green', 'default'), 'string.null': color.build('green', 'default'),
'string1': color.build('green', 'default'), 'string.end': color.build('green', 'default'),
'comment': color.build('red', 'default'), 'comment': color.build('red', 'default'),
'registers': color.build('yellow', 'default'), 'registers': color.build('yellow', 'default'),
'instructions': color.build('magenta', 'default'), 'instructions': color.build('magenta', 'default'),
'label': color.build('blue', 'default'), 'label': color.build('blue', 'default'),
} }
#self.highlighter.lex_buffer()
#self.get_regions()
def name(self): def name(self):
return "Nasm" return "Nasm"