parent
619ca7538e
commit
f7936a4910
17
lex.py
17
lex.py
|
@ -201,6 +201,23 @@ class ContextPatternRule(PatternRule):
|
|||
class NocaseContextPatternRule(ContextPatternRule):
|
||||
reflags = re.IGNORECASE
|
||||
|
||||
class LazyPatternRule(Rule):
|
||||
def __init__(self, name, pattern):
|
||||
Rule.__init__(self, name)
|
||||
self.pattern = pattern
|
||||
self.d = {}
|
||||
def _compile(self, d):
|
||||
self.re = re.compile(self.pattern % d, self.reflags)
|
||||
self.d = d
|
||||
def match(self, lexer, parent):
|
||||
if self.d != parent.matchd:
|
||||
self._compile(parent.matchd)
|
||||
return self.re.match(self.get_line(lexer), lexer.x)
|
||||
def lex(self, lexer, parent, m):
|
||||
if m:
|
||||
yield self.make_token(lexer, m.group(0), self.name, parent, m.groupdict())
|
||||
raise StopIteration
|
||||
|
||||
class PatternGroupRule(PatternRule):
|
||||
def __init__(self, name, *args):
|
||||
assert args and len(args) % 2 == 0
|
||||
|
|
13
mode/perl.py
13
mode/perl.py
|
@ -8,7 +8,7 @@ from mode import Fundamental
|
|||
import regex
|
||||
from buffer import IperlBuffer
|
||||
from point import Point
|
||||
from lex import Grammar, PatternRule, ContextPatternRule, RegionRule
|
||||
from lex import Grammar, LazyPatternRule, PatternRule, ContextPatternRule, RegionRule
|
||||
from lex import OverridePatternRule, PatternMatchRule
|
||||
from method import Argument, Method, WrapParagraph, arg
|
||||
from method.introspect import TokenComplete
|
||||
|
@ -60,7 +60,7 @@ scalar_rules = [
|
|||
PatternRule('perl.hash', r"\%\$*" + word2),
|
||||
PatternRule('perl.hash', r'\$' + word2 + '(?= *\{)'),
|
||||
|
||||
PatternRule('perl.scalar', r'\$[_ab&`\'\+\*\.|,\\";#\%=\-~\^:\?!@\$<>()\[\]](?!' + wchr2 + ')'),
|
||||
PatternRule('perl.scalar', r'\$[_&`\'\+\*\.|,\\";#\%=\-~\^:\?!@\$<>()\[\]](?!' + wchr2 + ')'),
|
||||
PatternRule('perl.scalar', r'\$\d+(?!' + wchr2 +')'),
|
||||
PatternRule('perl.scalar', r'\$\^(?:' + word1 + '|' + wchr1 + ')'),
|
||||
PatternRule('perl.scalar', r'\$\^O'),
|
||||
|
@ -78,6 +78,13 @@ def _make_string_rules(forbidden):
|
|||
length,
|
||||
] + scalar_rules
|
||||
|
||||
if not forbidden:
|
||||
rules.insert(0, LazyPatternRule('data', "\$(?=%(delim)s)"))
|
||||
elif forbidden in '()[].+*|?^':
|
||||
rules.insert(0, PatternRule('data', "\\$(?=\\" + forbidden + ')'))
|
||||
else:
|
||||
rules.insert(0, PatternRule('data', "\\$(?=" + forbidden + ')'))
|
||||
|
||||
if forbidden == ')':
|
||||
return rules + [PatternRule('data', r"[^$\%@\(\)]+")]
|
||||
elif forbidden == '}':
|
||||
|
@ -160,7 +167,7 @@ PerlGrammar.rules = [
|
|||
PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"),
|
||||
|
||||
# special scalar; doesn't interpolate well
|
||||
PatternRule('perl.scalar', r'\$/'),
|
||||
#PatternRule('perl.scalar', r'\$/'),
|
||||
] + scalar_rules + [
|
||||
|
||||
# match regexes; paired delimiters
|
||||
|
|
Loading…
Reference in New Issue