branch : pmacs2
This commit is contained in:
moculus 2008-09-30 05:47:20 +00:00
parent 49ecf5acfd
commit c40b3e0845
3 changed files with 20 additions and 18 deletions

View File

@ -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"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*=|\\"),
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':

View File

@ -44,6 +44,7 @@ class PythonGrammar(Grammar):
OverridePatternRule(r'comment', r'#@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.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'),

4
tab.py
View File

@ -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 = {}