parent
49ecf5acfd
commit
c40b3e0845
27
mode/perl.py
27
mode/perl.py
|
@ -13,21 +13,20 @@ class PodGrammar(Grammar):
|
||||||
RegionRule(r'entry', r'(?<=^=encoding) +.*$', Grammar, '^\n$'),
|
RegionRule(r'entry', r'(?<=^=encoding) +.*$', Grammar, '^\n$'),
|
||||||
]
|
]
|
||||||
|
|
||||||
def _make_string_rules(forbidden=None):
|
def _make_string_rules(forbidden):
|
||||||
if forbidden:
|
rule1 = PatternRule(r'scalar', r"\$[^\[\]\(\){}<>A-Za-z0-9 \\%s](?![A-Za-z0-9_])" % forbidden)
|
||||||
rule = PatternRule(r'scalar', r"\$[^\[\]\(\){}<>A-Za-z0-9 \\%s](?![A-Za-z0-9_])" % forbidden)
|
#rule2 = PatternRule(r'data', r"[^%s\\\@\$%%\&]+" % 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_])")
|
|
||||||
|
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'octal', r'\\[0-7]{3}'),
|
PatternRule(r'octal', r'\\[0-7]{3}'),
|
||||||
PatternRule(r'escaped', r'\\.'),
|
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'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_]|::)*"),
|
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'scalar', r"\$\$*[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*"),
|
||||||
PatternRule(r'cast', r"[\$\@\%\&]{.*?}"),
|
PatternRule(r'cast', r"[\$\@\%\&]{.*?}"),
|
||||||
PatternRule(r'array', r"@\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"),
|
PatternRule(r'array', r"@\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"),
|
||||||
|
#rule2,
|
||||||
]
|
]
|
||||||
return rules
|
return rules
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ class StrictStringGrammar(Grammar):
|
||||||
PatternRule(r'escaped', r"\\'"),
|
PatternRule(r'escaped', r"\\'"),
|
||||||
]
|
]
|
||||||
class StringGrammar(Grammar):
|
class StringGrammar(Grammar):
|
||||||
rules = _make_string_rules()
|
rules = _make_string_rules('"')
|
||||||
|
|
||||||
class QuotedGrammar1(Grammar):
|
class QuotedGrammar1(Grammar):
|
||||||
rules = _make_string_rules(')')
|
rules = _make_string_rules(')')
|
||||||
|
@ -139,11 +138,12 @@ class PerlGrammar(Grammar):
|
||||||
|
|
||||||
# some basic stuff
|
# some basic stuff
|
||||||
PatternRule(r'delimiter', r"::|->|=>|(?<!:):(?!=:)|[,;=\?(){}\[\]\(\)]"),
|
PatternRule(r'delimiter', r"::|->|=>|(?<!:):(?!=:)|[,;=\?(){}\[\]\(\)]"),
|
||||||
PatternRule(r'operator', r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
|
PatternRule(r'operator', r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*=|\\"),
|
||||||
PatternRule(r'operator', r"\+\+|\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|\*|&&|&|\|\||\||/|\^|==|//|~|=~|!~|!=|%|!|\.|x(?![a-zA-Z_])"),
|
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'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'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$"),
|
PatternRule(r"eol", r"\n$"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -207,9 +207,10 @@ class PerlTabber(tab.StackTabber):
|
||||||
not fqname.startswith('heredoc') and
|
not fqname.startswith('heredoc') and
|
||||||
not fqname.startswith('perl_string') and
|
not fqname.startswith('perl_string') and
|
||||||
not fqname.startswith('endblock') and
|
not fqname.startswith('endblock') and
|
||||||
not fqname == 'eol' and
|
fqname != 'eol' and
|
||||||
not fqname == 'comment' and
|
fqname != 'comment' and
|
||||||
not fqname == 'null' and
|
fqname != 'spaces' and
|
||||||
|
fqname != 'null' and
|
||||||
token.string not in ('}', ';', '(', '{', '[', ',')):
|
token.string not in ('}', ';', '(', '{', '[', ',')):
|
||||||
self._opt_append('cont', currlvl + w)
|
self._opt_append('cont', currlvl + w)
|
||||||
return currlvl
|
return currlvl
|
||||||
|
@ -418,14 +419,14 @@ class PerlWrapParagraph(method.WrapParagraph):
|
||||||
def _is_newline(self, t):
|
def _is_newline(self, t):
|
||||||
return t.name == 'eol'
|
return t.name == 'eol'
|
||||||
def _is_space(self, t):
|
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):
|
def _detect_line_type(self, w, y):
|
||||||
h = w.buffer.highlights[w.mode.name()]
|
h = w.buffer.highlights[w.mode.name()]
|
||||||
ltype = None
|
ltype = None
|
||||||
for t in h.tokens[y]:
|
for t in h.tokens[y]:
|
||||||
fqname = t.fqname()
|
fqname = t.fqname()
|
||||||
if fqname == 'null' or fqname == 'eol':
|
if fqname == 'spaces' or fqname == 'eol':
|
||||||
pass
|
pass
|
||||||
elif fqname.startswith('comment'):
|
elif fqname.startswith('comment'):
|
||||||
if ltype and ltype != 'comment':
|
if ltype and ltype != 'comment':
|
||||||
|
|
|
@ -44,6 +44,7 @@ class PythonGrammar(Grammar):
|
||||||
OverridePatternRule(r'comment', r'#@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *$'),
|
OverridePatternRule(r'comment', r'#@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *$'),
|
||||||
PatternRule(r'comment', r'#.*$'),
|
PatternRule(r'comment', r'#.*$'),
|
||||||
PatternRule(r'continuation', r'\\\n$'),
|
PatternRule(r'continuation', r'\\\n$'),
|
||||||
|
PatternRule(r'spaces', r' +'),
|
||||||
PatternRule(r'eol', r'\n$'),
|
PatternRule(r'eol', r'\n$'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -399,7 +400,7 @@ class PythonContext(context.Context):
|
||||||
while i < y2:
|
while i < y2:
|
||||||
g = highlights.tokens[i]
|
g = highlights.tokens[i]
|
||||||
if (len(g) == 1 and g[0].name == 'eol' or
|
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:
|
if last is None:
|
||||||
last = i
|
last = i
|
||||||
i += 1
|
i += 1
|
||||||
|
@ -407,7 +408,7 @@ class PythonContext(context.Context):
|
||||||
y2 += 1
|
y2 += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if g[0].name == 'null':
|
if g[0].name == 'spaces':
|
||||||
j, lvl = 1, len(g[0].string)
|
j, lvl = 1, len(g[0].string)
|
||||||
else:
|
else:
|
||||||
j, lvl = 0, 0
|
j, lvl = 0, 0
|
||||||
|
@ -466,7 +467,7 @@ class Python(mode.Fundamental):
|
||||||
'functionname': ('blue', 'default', 'bold'),
|
'functionname': ('blue', 'default', 'bold'),
|
||||||
'classname': ('green', 'default', 'bold'),
|
'classname': ('green', 'default', 'bold'),
|
||||||
'rawstring.start': ('green', 'default', 'bold'),
|
'rawstring.start': ('green', 'default', 'bold'),
|
||||||
'rawstring.null': ('green', 'default', 'bold'),
|
'rawstring.data': ('green', 'default', 'bold'),
|
||||||
'rawstring.escaped': ('magenta', 'default', 'bold'),
|
'rawstring.escaped': ('magenta', 'default', 'bold'),
|
||||||
'rawstring.end': ('green', 'default', 'bold'),
|
'rawstring.end': ('green', 'default', 'bold'),
|
||||||
'system_identifier': ('cyan', 'default', 'bold'),
|
'system_identifier': ('cyan', 'default', 'bold'),
|
||||||
|
|
4
tab.py
4
tab.py
|
@ -10,9 +10,9 @@ class Marker(object):
|
||||||
|
|
||||||
class Tabber(object):
|
class Tabber(object):
|
||||||
wsre = regex.whitespace
|
wsre = regex.whitespace
|
||||||
wst = ('null', 'eol',)
|
wst = ('spaces', 'null', 'eol',)
|
||||||
sre = regex.space
|
sre = regex.space
|
||||||
st = ('null',)
|
st = ('spaces', 'null',)
|
||||||
def __init__(self, m):
|
def __init__(self, m):
|
||||||
self.mode = m
|
self.mode = m
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
|
|
Loading…
Reference in New Issue