diff --git a/mode/nasm.py b/mode/nasm.py index ba1e064..07570a9 100644 --- a/mode/nasm.py +++ b/mode/nasm.py @@ -8,22 +8,24 @@ word = chr1 + chr2 + '*' 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', ';.*$'), + PatternRule('nasm.keyword', "(?:section|global|extern)(?!" + chr2 + ")"), + PatternRule('nasm.macro', "%(?:define|undef|assign|strlen|macro|endmacro|if|elif|else|endif|ifdef|ifndef|include|push|pop|stacksize)(?!" + chr2 + ")"), + PatternRule('nasm.instruction', "(?: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('nasm.register', "(?:eax|ax|ah|al|ebx|bx|bh|bl|ecx|cx|ch|cl|esi|edi|esp|ebp)(?!" + chr2 + ")"), + PatternRule('nasm.prefix', "(?:dword|word|lock)(?!" + chr2 + ")"), + PatternMatchRule('x', '(' + word + ')(:)', 'nasm.label', 'delimiter'), + PatternRule("nasm.identifier", r'\$?' + word), + PatternRule("nasm.integer", "(0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"), + PatternRule("nasm.float", r"[0-9]+\.[0-9]*|\.[0-9]+|([0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"), + PatternRule('delimiter', r'(?://|%%|<<|>>|[~!\.\*/%\-\+\(\)\[\],\|\^\&])'), + RegionRule('string', '"""', StringGrammar4, '"""'), + RegionRule('string', "'''", StringGrammar3, "'''"), + RegionRule('string', '"', StringGrammar2, '"'), + RegionRule('string', "'", StringGrammar1, "'"), + PatternRule('spaces', ' +'), + PatternRule('eol', '\n'), + PatternRule('continuation', r'\\\n$'), ] class Nasm(Fundamental): @@ -32,11 +34,16 @@ class Nasm(Fundamental): grammar = NasmGrammar commentc = ';' colors = { - 'nasm_keyword': ('cyan', 'default', 'bold'), - 'macros': ('blue', 'default', 'bold'), - 'registers': ('yellow', 'default', 'bold'), - 'instructions': ('magenta', 'default', 'bold'), - 'nasm_label': ('blue', 'default', 'bold'), + 'nasm.keyword': ('cyan', 'default', 'bold'), + 'nasm.macro': ('blue', 'default', 'bold'), + 'nasm.register': ('yellow', 'default', 'bold'), + 'nasm.instruction': ('magenta', 'default', 'bold'), + 'nasm.label': ('blue', 'default', 'bold'), + } + _bindings = { + 'close-paren': (')',), + 'close-brace': ('}',), + 'close-bracket': (']',), } install = Nasm.install diff --git a/mode/perl.py b/mode/perl.py index 27b713e..39ace11 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -1,10 +1,17 @@ -import os, re, string, sys +import os +import re +import string from subprocess import Popen, PIPE, STDOUT -import buffer, color, commands, completer, context, method, mode, regex, tab +import completer +import context +from mode import Fundamental +import regex +from buffer import IperlBuffer from point import Point from lex import Grammar, PatternRule, ContextPatternRule, RegionRule from lex import OverridePatternRule, PatternMatchRule -from method import Argument, Method, WrapParagraph +from method import Argument, Method, WrapParagraph, arg +from method.introspect import TokenComplete from tab import StackTabber, StackTabber2 from parse import Any, And, Or, Optional, Name, Match, Matchs import term @@ -111,18 +118,12 @@ class PerlGrammar(Grammar): PatternRule('perl.keyword', "(?)(?:STDIN|STDERR|STDOUT|continue|do|else|elsif|eval|foreach|for|if|last|my|next|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])"), PatternRule('perl.hash_key', '(?<={)' + wchr2 + '+(?=})'), PatternRule('perl.method', '(?<=->)' + word1), - #PatternMatchRule('x', '(' + wchr2 + '+)( *)(=>)' - # 'perl.hash_key', 'spaces', 'delimiter'), PatternRule('perl.hash_key', wchr2 + '+(?= *=>)'), PatternRule('perl.length', r"\$#" + word2), - #PatternMatchRule('x', r'([\$\@\%\&\*])( *)({)', - # 'perl.cast', 'spaces', 'delimiter'), PatternRule('perl.cast', r'[\$\@\%\&\*](?= *{)'), PatternRule('perl.scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" + wchr2 + ")"), PatternRule('perl.array', "@_"), - #PatternMatchRule('x', r"(\$\$*" + word2 + ")(->)( *)(\()", - # 'perl.function', 'delimiter', 'spaces', 'delimiter'), PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"), PatternRule('perl.scalar', r"\$\$*" + word2), PatternRule('perl.array', r"@\$*" + word2), @@ -224,8 +225,8 @@ class PerlTabber2(StackTabber2): end_at_eof = False end_at_tokens = {'perl.delimiter': {';': 1}} nocontinue_tokens = {'perl.delimiter': {';': 1, ',': 1, '}': 1}, - 'perl.heredoc.end': 1, - 'perl.evaldoc.end': 1, 'perl.pod.end': 1} + 'perl.heredoc.end': 1, + 'perl.evaldoc.end': 1, 'perl.pod.end': 1} start_free_tokens = {'perl.string.start': 1, 'perl.pod.start': 1, 'perl.heredoc.start': 1, 'perl.evaldoc.start': 1} end_free_tokens = {'perl.string.end': 1, 'perl.pod.end': 1, @@ -233,7 +234,7 @@ class PerlTabber2(StackTabber2): class PerlSetLib(Method): '''Set the path(s) to find perl modules''' - args = [method.arg("lib", dt='path', p="Lib: ", dv=lambda w: '.')] + args = [arg("lib", dt='path', p="Lib: ", dv=lambda w: '.')] def _execute(self, w, **vargs): w.application.config['perl.libs'] = vargs['lib'].split(':') class PerlAddLib(PerlSetLib): @@ -275,7 +276,7 @@ class PerldocModule(PerlBase): class Perldoc(Method): name_re = re.compile('(?:[a-zA-Z_][a-zA-Z0-9_]*::)*[a-zA-Z_][a-zA-Z0-9_]*') - args = [method.arg("name", p="Perldoc: ")] + args = [arg("name", p="Perldoc: ")] def _execute(self, w, **vargs): name = vargs['name'] if not self.name_re.match(name): @@ -459,7 +460,7 @@ class PerlHashCleanup(Method): w.delete(start_p, end_p) w.insert_string(start_p, data) -class PerlWrapParagraph(method.WrapParagraph): +class PerlWrapParagraph(WrapParagraph): '''Wrap Comments and POD''' # enumerations for line types LT_COMMENT = 1 @@ -557,13 +558,13 @@ class PerlWrapParagraph(method.WrapParagraph): else: w.set_error("did not detect comment or pod lines") -class PerlSemanticComplete(method.introspect.TokenComplete): +class PerlSemanticComplete(TokenComplete): _mini_prompt = 'Semantic Complete' def _min_completion(self, w, x1, x2, y): a = w.application a.methods['iperl-path-start'].execute(w, switch=False) - name = buffer.IperlBuffer.create_name(w.buffer) + name = IperlBuffer.create_name(w.buffer) b = a.get_buffer_by_name(name) line = w.buffer.lines[y] @@ -606,7 +607,7 @@ class PerlSemanticComplete(method.introspect.TokenComplete): else: w.set_error("Partial completion: %r" % candidates) -class PerlOpenModule(method.Method): +class PerlOpenModule(Method): args = [Argument("module", type=type(""), prompt="Open Perl Module: ")] def _execute(self, w, **vargs): path = w.mode.find_module(vargs['module']) @@ -614,7 +615,7 @@ class PerlOpenModule(method.Method): w.application.methods['open-file'].execute(w, filename=path) else: w.set_error("Could not find module %r" % vargs['module']) -class PerlOpenModuleWord(method.Method): +class PerlOpenModuleWord(Method): namechars = string.letters + string.digits + '_' def _execute(self, w, **vargs): word = pkg = w.get_token().string @@ -674,7 +675,7 @@ class PerlContext(context.Context): if curr: self.namelines[i] = (curr, tuple(stack)) i += 1 -class Perl(mode.Fundamental): +class Perl(Fundamental): name = 'Perl' extensions = ['.pl', '.pm', '.pod'] detection = ['perl'] @@ -788,28 +789,23 @@ class Perl(mode.Fundamental): 'perlfunction': PerlFunctionCompleter(None), } format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s %(perc)s [%(func)s]" - def get_status_names(self): - names = mode.Fundamental.get_status_names(self) - c = self.window.logical_cursor() - names['func'] = self.get_line_function(c.y) - return names + _bindings = { + 'perl-set-lib': ('C-c l',), + 'perl-check-syntax': ('C-c s',), + 'perl-hash-cleanup': ('C-c h',), + 'perldoc-module': ('C-c v',), + 'perldoc-word': ('C-c p',), + 'perl-wrap-paragraph': ('M-q',), + 'perl-goto-function': ('C-c M-g',), + 'perl-open-module': ('C-c C-f',), + 'perl-open-module-word': ('C-c M-f',), + 'perl-semantic-complete': ('C-c TAB',), + 'close-paren': (')'), + 'close-bracket': (']'), + 'close-brace': ('}'), + } def __init__(self, w): - mode.Fundamental.__init__(self, w) - self.add_bindings('perl-set-lib', ('C-c l',)) - self.add_bindings('perl-check-syntax', ('C-c s',)) - self.add_bindings('perl-hash-cleanup', ('C-c h',)) - #self.add_bindings('perl-view-module-perldoc', ('C-c v',)) - #self.add_bindings('perl-view-word-perldoc', ('C-c p',)) - self.add_bindings('perldoc-module', ('C-c v',)) - self.add_bindings('perldoc-word', ('C-c p',)) - self.add_bindings('perl-wrap-paragraph', ('M-q',)) - self.add_bindings('perl-goto-function', ('C-c M-g',)) - self.add_bindings('perl-open-module', ('C-c C-f',)) - self.add_bindings('perl-open-module-word', ('C-c M-f',)) - self.add_bindings('perl-semantic-complete', ('C-c TAB',)) - self.add_bindings('close-paren', (')')) - self.add_bindings('close-bracket', (']')) - self.add_bindings('close-brace', ('}')) + Fundamental.__init__(self, w) self.context = PerlContext(self) self.functions = None self.funclines = None @@ -834,18 +830,23 @@ class Perl(mode.Fundamental): if a.config.get('perl.libs', None): s = ':'.join(['%s' % x for x in a.config.get('perl.libs')]) cmd = 'PERL5LIB=%r %s' % (s, cmd) - (status, data) = commands.getstatusoutput(cmd) - if status != 0: - raise Exception, "%r failed" % cmd + p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) + data = p.stdout.read() + status = p.wait() + + if status != 0: raise Exception, "%r failed" % cmd self.perlinc = data.split('\n') return self.perlinc - def get_functions(self): - return self.context.get_names() - def get_function_names(self): - return self.context.get_name_list() - def get_line_function(self, y): - return self.context.get_line_name(y) + def get_functions(self): return self.context.get_names() + def get_function_names(self): return self.context.get_name_list() + def get_line_function(self, y): return self.context.get_line_name(y) + + def get_status_names(self): + names = Fundamental.get_status_names(self) + c = self.window.logical_cursor() + names['func'] = self.get_line_function(c.y) + return names install = Perl.install