diff --git a/buffer2.py b/buffer2.py index 8e52442..623fb78 100644 --- a/buffer2.py +++ b/buffer2.py @@ -103,6 +103,8 @@ class Buffer(object): if modename not in self.highlights and w.mode.lexer is not None: self.highlights[modename] = highlight2.Highlighter(w.mode.lexer) self.highlights[modename].highlight(self.lines) + #if modename not in self.tabbing and w.mode.tabber is not None: + # self.tabbing[modename] = def remove_window(self, w): if w in self.windows: self.windows.remove(w) diff --git a/method.py b/method.py index 6e4046c..c11db2a 100644 --- a/method.py +++ b/method.py @@ -14,10 +14,10 @@ DATATYPES = { } class Argument: - def __init__(self, name, typ=type(""), datatype=None, prompt=None, help="", + def __init__(self, name, type=type(""), datatype=None, prompt=None, help="", default=default.none, load_default=False): self.name = name - self.type = typ + self.type = type self.datatype = datatype if prompt is None: self.prompt = "%s: " % (name) diff --git a/mode_python.py b/mode_python.py index faf802a..e85a912 100644 --- a/mode_python.py +++ b/mode_python.py @@ -1,17 +1,133 @@ import commands, os.path, sets, string, sys -import color, default, mode2, lex2, lex2_python, method, regex, tab_python -import ctag_python, completer +import color, completer, default, mode2, lex2, method, regex +import ctag_python from point2 import Point +from lex2 import Grammar, ConstantRule, PatternRule, RegionRule, DualRegionRule + +class StringGrammar(Grammar): + rules = [ + PatternRule( + name=r'octal', + pattern=r'\\[0-7]{3}', + ), + PatternRule( + name=r'escaped', + pattern=r'\\.', + ), + #PatternRule( + # name=r'format', + # pattern=r'%(?:\([a-zA-Z_]+\))?[-# +]*(?:[0-9]+|\*)?\.?(?:[0-9]+|\*)?[hlL]?[a-zA-Z%]', + #), + ] + +class PythonGrammar(Grammar): + rules = [ + PatternRule( + name=r'functiondef', + pattern=r'(?<=def )[a-zA-Z_][a-zA-Z0-9_]*', + ), + PatternRule( + name=r'classdef', + pattern=r'(?<=class )[a-zA-Z_][a-zA-Z0-9_]*', + ), + PatternRule( + name=r'reserved', + pattern=r'(?:True|None|False|Exception|self)(?![a-zA-Z0-9_])', + ), + PatternRule( + name=r'keyword', + pattern=r'(?:yield|while|try|return|raise|print|pass|or|not|lambda|is|in|import|if|global|from|for|finally|exec|except|else|elif|del|def|continue|class|break|assert|as|and)(?![a-zA-Z0-9_])', + ), + PatternRule( + name=r"builtin", + pattern=r'(?>=|<<=|\*\*=', + ), + PatternRule( + name=r"operator", + pattern=r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%", + ), + + PatternRule( + name=r"integer", + pattern=r"(?"""|\'\'\')', + grammar=Grammar(), + end=r'%(tag)s', + ), + RegionRule( + name=r'tq_string', + start=r'(?P"""|\'\'\')', + grammar=Grammar(), + end=r'%(tag)s', + ), + RegionRule( + name=r'string', + start=r'(?P"|\')', + grammar=StringGrammar(), + end=r'%(tag)s', + ), + + PatternRule( + name=r'comment', + pattern=r'#.*$', + ), + PatternRule( + name=r'continuation', + pattern=r'\\$', + ), + ] class Python(mode2.Fundamental): + grammar = PythonGrammar + tabber = tab2.Tabber def __init__(self, w): mode2.Fundamental.__init__(self, w) self.tag_matching = True - #self.tag_matching = False - self.grammar = lex2_python.PythonGrammar() + self.grammar = PythonGrammar() self.lexer = lex2.Lexer(self.name(), self.grammar) self.add_action_and_bindings(PythonCheckSyntax(), ('C-c s',))