parent
a8ecc35701
commit
68d68b51b9
|
@ -7,7 +7,11 @@ sub foo {
|
|||
unless 9 && 3;
|
||||
}
|
||||
|
||||
#@@:string:mode_sql.SqlGrammar
|
||||
#@@:heredoc:mode_sql.SqlGrammar
|
||||
my $s = <<EOT;
|
||||
drop table foog;
|
||||
EOT
|
||||
|
||||
my $foo = {
|
||||
'drop table ',
|
||||
'bar',
|
||||
|
|
36
lex3.py
36
lex3.py
|
@ -1,5 +1,6 @@
|
|||
import re
|
||||
import regex, util
|
||||
from point2 import Point
|
||||
|
||||
class Token(object):
|
||||
def __init__(self, name, rule, y, x, s, parent=None, matchd={}, link=None):
|
||||
|
@ -11,8 +12,7 @@ class Token(object):
|
|||
self.parent = parent
|
||||
self.matchd = matchd
|
||||
self.link = link
|
||||
self.loverride = None
|
||||
self.goverride = None
|
||||
#self.loverride = None
|
||||
assert parent is None or hasattr(parent, 'name'), 'oh no %r' % parent
|
||||
def parents(self):
|
||||
if self.parent is not None:
|
||||
|
@ -95,14 +95,15 @@ class NocasePatternRule(PatternRule):
|
|||
class OverridePatternRule(PatternRule):
|
||||
def lex(self, lexer, parent, m):
|
||||
if m:
|
||||
a = lexer.mode.window.application
|
||||
d = m.groupdict()
|
||||
if lexer.action == 'lex':
|
||||
a = lexer.mode.window.application
|
||||
try:
|
||||
names = d['grammar'].split('.')
|
||||
grammar = a.globals()[names.pop(0)]
|
||||
for name in names:
|
||||
grammar = getattr(grammar, name)
|
||||
lexer.loverride['%s.start' % d['token']] = grammar
|
||||
lexer.mode.gstack['%s.start' % d['token']] = grammar
|
||||
except Exception:
|
||||
#raise
|
||||
pass
|
||||
|
@ -208,17 +209,14 @@ class RegionRule(Rule):
|
|||
# for each one, we will compile our stop-regex, and figure out the
|
||||
# name of the stop token to be created if this stop-regex matches.
|
||||
fqname = toresume[0].fqname()
|
||||
if fqname in lexer.loverride:
|
||||
grammar = lexer.loverride[fqname]
|
||||
del lexer.loverride[fqname]
|
||||
#toresume[0].loverride = grammar
|
||||
elif fqname in lexer.goverride:
|
||||
grammar = lexer.goverride[fqname]
|
||||
#toresume[0].goverride = grammar
|
||||
#elif toresume[0].loverride:
|
||||
# grammar = toresume[0].loverride
|
||||
#elif toresume[0].goverride:
|
||||
# grammar = toresume[0].goverride
|
||||
p = Point(toresume[0].x, toresume[0].y)
|
||||
if fqname in lexer.mode.ghist and p in lexer.mode.ghist[fqname]:
|
||||
grammar = lexer.mode.ghist[fqname][p]
|
||||
elif fqname in lexer.mode.gstack:
|
||||
grammar = lexer.mode.gstack[fqname]
|
||||
lexer.mode.ghist.setdefault(fqname, {})
|
||||
lexer.mode.ghist[fqname][p] = grammar
|
||||
del lexer.mode.gstack[fqname]
|
||||
else:
|
||||
grammar = self.pairs[i][0]
|
||||
|
||||
|
@ -340,8 +338,6 @@ class Lexer:
|
|||
self.y = 0
|
||||
self.x = 0
|
||||
self.lines = None
|
||||
self.loverride = {}
|
||||
self.goverride = {}
|
||||
assert self.grammar.rules
|
||||
def get_line(self):
|
||||
return self.lines[self.y] + '\n'
|
||||
|
@ -350,9 +346,11 @@ class Lexer:
|
|||
self.y = y
|
||||
self.x = x
|
||||
self.lines = lines
|
||||
self.loverride = {}
|
||||
self.mode.ghist = {}
|
||||
self.mode.gstack = {}
|
||||
for t in self._lex():
|
||||
yield t
|
||||
del self.action
|
||||
raise StopIteration
|
||||
def resume(self, lines, y, x, token):
|
||||
self.action = 'resume'
|
||||
|
@ -360,7 +358,6 @@ class Lexer:
|
|||
self.x = x
|
||||
self.lines = lines
|
||||
self.tokens = []
|
||||
self.loverride = {}
|
||||
toresume = token.parents()
|
||||
|
||||
i = 1
|
||||
|
@ -375,6 +372,7 @@ class Lexer:
|
|||
yield t
|
||||
for t in self._lex():
|
||||
yield t
|
||||
del self.action
|
||||
raise StopIteration
|
||||
|
||||
def _lex(self):
|
||||
|
|
41
mode2.py
41
mode2.py
|
@ -1,6 +1,7 @@
|
|||
import os, sets, string
|
||||
import color, method
|
||||
from lex3 import Lexer
|
||||
from point2 import Point
|
||||
|
||||
DEBUG = False
|
||||
|
||||
|
@ -158,6 +159,8 @@ class Fundamental(Handler):
|
|||
# lexing for highlighting, etc.
|
||||
if self.grammar:
|
||||
self.lexer = Lexer(self, self.grammar)
|
||||
self.gstack = {}
|
||||
self.ghist = {}
|
||||
|
||||
# tab handling
|
||||
if self.tabbercls:
|
||||
|
@ -196,6 +199,44 @@ class Fundamental(Handler):
|
|||
def region_added(self, p, newlines):
|
||||
if self.tabber is not None:
|
||||
self.tabber.region_added(p, newlines)
|
||||
if self.lexer:
|
||||
ydelta = len(newlines) - 1
|
||||
xdelta = len(newlines[-1])
|
||||
ghist = {}
|
||||
for name in self.ghist:
|
||||
for p2 in self.ghist[name]:
|
||||
if p2.y > p.y:
|
||||
newp = Point(p2.x, p2.y + ydelta)
|
||||
elif ydelta == 0:
|
||||
newp = Point(p2.x + xdelta, p2.y)
|
||||
else:
|
||||
newp = Point(p2.x, p2.y + ydelta)
|
||||
ghist.setdefault(name, {})
|
||||
ghist[name][newp] = self.ghist[name][p2]
|
||||
self.ghist = ghist
|
||||
def region_removed(self, p1, p2):
|
||||
if self.tabber is not None:
|
||||
self.tabber.region_removed(p1, p2)
|
||||
if self.lexer and False:
|
||||
ydelta = p2.y - p1.y
|
||||
xdelta = p2.x - p1.x
|
||||
ghist = {}
|
||||
for name in self.ghist:
|
||||
for p in self.ghist[name]:
|
||||
if p < p1:
|
||||
newp = p
|
||||
elif p1 <= p and p < p2:
|
||||
continue
|
||||
elif ydelta == 0:
|
||||
if p.y == p2.y:
|
||||
newp = Point(p.x - xdelta, p.y)
|
||||
else:
|
||||
newp = p
|
||||
else:
|
||||
if p.y == p2.y:
|
||||
newp = Point(p.x - xdelta, p.y - ydelta)
|
||||
else:
|
||||
newp = Point(p.x, p.y - ydelta)
|
||||
ghist.setdefault(name, {})
|
||||
ghist[name][newp] = self.ghist[name][p]
|
||||
self.ghist = ghist
|
||||
|
|
14
point2.py
14
point2.py
|
@ -21,12 +21,22 @@ class Point(tuple):
|
|||
'''Returns a tuple (x,y)'''
|
||||
return tuple(self)
|
||||
def add(self, xdelta, ydelta):
|
||||
'''Returns a new point, applying xdelta and ydelta'''
|
||||
'''Returns a new point, adding xdelta and ydelta'''
|
||||
return Point(self[1] + xdelta, self[0] + ydelta)
|
||||
def vadd(self, xdelta, ydelta):
|
||||
'''Returns a new point. If ydelta > 0, xdelta is absolute; otherwise, xdelta is relative'''
|
||||
'''Returns a new point. If ydelta != 0, xdelta is absolute; otherwise, xdelta is relative'''
|
||||
assert xdelta >= 0 and ydelta >= 0, str((xdelta, ydelta))
|
||||
if ydelta != 0:
|
||||
return Point(xdelta, self[0] + ydelta)
|
||||
else:
|
||||
return Point(self[1] + xdelta, self[0])
|
||||
#def sub(self, xdelta, ydelta):
|
||||
# '''Returns a new point, subtracing xdelta and ydelta'''
|
||||
# return Point(self[1] - xdelta, self[0] - ydelta)
|
||||
#def vsub(self, xdelta, ydelta):
|
||||
# '''Returns a new point. If ydelta != 0, xdelta is absolute; otherwise, xdelta is relative'''
|
||||
# assert xdelta >= 0 and ydelta >= 0, str((xdelta, ydelta))
|
||||
# if ydelta != 0:
|
||||
# return Point(self[1], self[0] - ydelta)
|
||||
# else:
|
||||
# return Point(self[1] - xdelta, self[0])
|
||||
|
|
Loading…
Reference in New Issue