From c40b3e08457c6dc27325b89fde17b9855054362c Mon Sep 17 00:00:00 2001 From: moculus Date: Tue, 30 Sep 2008 05:47:20 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- mode/perl.py | 27 ++++++++++++++------------- mode/python.py | 7 ++++--- tab.py | 4 ++-- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/mode/perl.py b/mode/perl.py index 3c60b39..53072c4 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -13,21 +13,20 @@ class PodGrammar(Grammar): RegionRule(r'entry', r'(?<=^=encoding) +.*$', Grammar, '^\n$'), ] -def _make_string_rules(forbidden=None): - if forbidden: - rule = PatternRule(r'scalar', r"\$[^\[\]\(\){}<>A-Za-z0-9 \\%s](?![A-Za-z0-9_])" % forbidden) - else: - rule = ContextPatternRule(r'scalar', r"\$[^\[\]\(\){}<>A-Za-z0-9 %(delim)s](?![A-Za-z0-9_])", r"\$[^A-Za-z0-9 ](?![A-Za-z0-9_])") +def _make_string_rules(forbidden): + rule1 = PatternRule(r'scalar', r"\$[^\[\]\(\){}<>A-Za-z0-9 \\%s](?![A-Za-z0-9_])" % forbidden) + #rule2 = PatternRule(r'data', r"[^%s\\\@\$%%\&]+" % forbidden) rules = [ PatternRule(r'octal', r'\\[0-7]{3}'), PatternRule(r'escaped', r'\\.'), PatternRule(r'deref', r"\$+[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*(?:(?:->)?{\$?(?:[a-zA-Z_][a-zA-Z_0-9]*|'(?:\\.|[^'\\])*'|\"(\\.|[^\\\"])*\")}|(?:->)?\[\$?[0-9a-zA-Z_]+\])+"), PatternRule(r'length', r"\$#[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*"), - rule, + rule1, PatternRule(r'scalar', r"\$\$*[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*"), PatternRule(r'cast', r"[\$\@\%\&]{.*?}"), PatternRule(r'array', r"@\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"), + #rule2, ] return rules @@ -36,7 +35,7 @@ class StrictStringGrammar(Grammar): PatternRule(r'escaped', r"\\'"), ] class StringGrammar(Grammar): - rules = _make_string_rules() + rules = _make_string_rules('"') class QuotedGrammar1(Grammar): rules = _make_string_rules(')') @@ -139,11 +138,12 @@ class PerlGrammar(Grammar): # some basic stuff PatternRule(r'delimiter', r"::|->|=>|(?>=|<<=|\*\*="), + PatternRule(r'operator', r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*=|\\"), PatternRule(r'operator', r"\+\+|\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|\*|&&|&|\|\||\||/|\^|==|//|~|=~|!~|!=|%|!|\.|x(?![a-zA-Z_])"), PatternRule(r'noperator', r"(?:xor|or|not|ne|lt|le|gt|ge|eq|cmp|and)(?![a-zA-Z_])"), PatternRule(r'bareword', r'(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*'), + PatternRule(r'spaces', r' +'), PatternRule(r"eol", r"\n$"), ] @@ -207,9 +207,10 @@ class PerlTabber(tab.StackTabber): not fqname.startswith('heredoc') and not fqname.startswith('perl_string') and not fqname.startswith('endblock') and - not fqname == 'eol' and - not fqname == 'comment' and - not fqname == 'null' and + fqname != 'eol' and + fqname != 'comment' and + fqname != 'spaces' and + fqname != 'null' and token.string not in ('}', ';', '(', '{', '[', ',')): self._opt_append('cont', currlvl + w) return currlvl @@ -418,14 +419,14 @@ class PerlWrapParagraph(method.WrapParagraph): def _is_newline(self, t): return t.name == 'eol' def _is_space(self, t): - return t.name == 'null' and regex.space.match(t.string) + return t.name == 'spaces' def _detect_line_type(self, w, y): h = w.buffer.highlights[w.mode.name()] ltype = None for t in h.tokens[y]: fqname = t.fqname() - if fqname == 'null' or fqname == 'eol': + if fqname == 'spaces' or fqname == 'eol': pass elif fqname.startswith('comment'): if ltype and ltype != 'comment': diff --git a/mode/python.py b/mode/python.py index 8caa1b2..0dd81fe 100644 --- a/mode/python.py +++ b/mode/python.py @@ -44,6 +44,7 @@ class PythonGrammar(Grammar): OverridePatternRule(r'comment', r'#@@:(?P[.a-zA-Z0-9_]+):(?P[.a-zA-Z0-9_]+) *$'), PatternRule(r'comment', r'#.*$'), PatternRule(r'continuation', r'\\\n$'), + PatternRule(r'spaces', r' +'), PatternRule(r'eol', r'\n$'), ] @@ -399,7 +400,7 @@ class PythonContext(context.Context): while i < y2: g = highlights.tokens[i] if (len(g) == 1 and g[0].name == 'eol' or - len(g) == 2 and g[0].name == 'null' and g[1].name == 'eol'): + len(g) == 2 and g[0].name == 'spaces' and g[1].name == 'eol'): if last is None: last = i i += 1 @@ -407,7 +408,7 @@ class PythonContext(context.Context): y2 += 1 continue - if g[0].name == 'null': + if g[0].name == 'spaces': j, lvl = 1, len(g[0].string) else: j, lvl = 0, 0 @@ -466,7 +467,7 @@ class Python(mode.Fundamental): 'functionname': ('blue', 'default', 'bold'), 'classname': ('green', 'default', 'bold'), 'rawstring.start': ('green', 'default', 'bold'), - 'rawstring.null': ('green', 'default', 'bold'), + 'rawstring.data': ('green', 'default', 'bold'), 'rawstring.escaped': ('magenta', 'default', 'bold'), 'rawstring.end': ('green', 'default', 'bold'), 'system_identifier': ('cyan', 'default', 'bold'), diff --git a/tab.py b/tab.py index f97e46f..8cd2b89 100644 --- a/tab.py +++ b/tab.py @@ -10,9 +10,9 @@ class Marker(object): class Tabber(object): wsre = regex.whitespace - wst = ('null', 'eol',) + wst = ('spaces', 'null', 'eol',) sre = regex.space - st = ('null',) + st = ('spaces', 'null',) def __init__(self, m): self.mode = m self.lines = {}