refactor syntline to represent the empty line, and replace itself
fix up matching for variable references
This commit is contained in:
parent
0bf142c64e
commit
1ca029e2b6
77
scripting.py
77
scripting.py
|
@ -29,18 +29,22 @@ class Rtype(TPrs):
|
||||||
for lit in self.RglitFromSt(st):
|
for lit in self.RglitFromSt(st):
|
||||||
yield SyntLit(None, lit, self)
|
yield SyntLit(None, lit, self)
|
||||||
|
|
||||||
|
for synt in self.RgsyntVarRefFromSt(syntBlock, st):
|
||||||
|
yield synt
|
||||||
|
|
||||||
|
def RgsyntVarRefFromSt(self, syntBlock, st):
|
||||||
while syntBlock != None:
|
while syntBlock != None:
|
||||||
if isinstance(syntBlock, SyntBlock):
|
if isinstance(syntBlock, SyntBlock):
|
||||||
for synt in self.RgsyntFromSyntBlock(syntBlock, st):
|
for synt in self.RgsyntFromSyntBlock(syntBlock, st):
|
||||||
yield synt
|
yield synt
|
||||||
syntBlock = syntBlock.syntParent
|
syntBlock = syntBlock.syntParent
|
||||||
|
|
||||||
# helper for RgsyntFromSt
|
# helper for RgsyntVarRefFromSt
|
||||||
def RgsyntFromSyntBlock(self, syntBlock, st):
|
def RgsyntFromSyntBlock(self, syntBlock, st):
|
||||||
# yield all vars in scope
|
# yield all vars in scope
|
||||||
for syntLine in syntBlock.rgsynt:
|
for syntVar in syntBlock.rgsynt:
|
||||||
if SyntVar.FVarOfType(syntLine.rgsynt[0], self):
|
if SyntVar.FVarOfType(syntVar, self) and syntVar.name.St().lower().startswith(st.lower()):
|
||||||
yield SyntVarRef(None, syntLine.rgsynt[0])
|
yield SyntVarRef(None, syntVar)
|
||||||
|
|
||||||
def StForSobj(self, sobj):
|
def StForSobj(self, sobj):
|
||||||
return str(sobj)
|
return str(sobj)
|
||||||
|
@ -243,29 +247,15 @@ class SyntExpr(Synt):
|
||||||
def Project(self, pcur):
|
def Project(self, pcur):
|
||||||
self.syntParent.ProjectTypeinForChild(pcur.PwHoriz(self), self, " ")
|
self.syntParent.ProjectTypeinForChild(pcur.PwHoriz(self), self, " ")
|
||||||
|
|
||||||
class SyntLine(Synt):
|
class SyntLine(SyntDesc):
|
||||||
rgclsStmt = []
|
rgclsStmt = []
|
||||||
def Populate(self):
|
desc = [[" "]]
|
||||||
self.rgsynt.append(SyntBlank(self))
|
@classmethod
|
||||||
def SetStmt(self, syntStmt):
|
def RgsyntReplace(cls, syntChild, st, rtype):
|
||||||
self.Replace(self.rgsynt[0], syntStmt)
|
for clsStmt in cls.rgclsStmt:
|
||||||
def Project(self, pcur):
|
|
||||||
pwKey = PwKeyHandler(pcur.pwVert, self.HandleKey)
|
|
||||||
with pcur.ProjectHoriz(pwKey, self):
|
|
||||||
self.rgsynt[0].Project(pcur)
|
|
||||||
|
|
||||||
def RgsyntForChild(self, syntChild, st):
|
|
||||||
for clsStmt in self.rgclsStmt:
|
|
||||||
if clsStmt.StForTypein().lower().startswith(st.lower()):
|
if clsStmt.StForTypein().lower().startswith(st.lower()):
|
||||||
yield clsStmt(None)
|
yield clsStmt(None)
|
||||||
|
|
||||||
def HandleKey(self, pwKey, pov, psel, key):
|
|
||||||
if ansi.FEnter(key):
|
|
||||||
self.syntParent.InsertLineAfter(self, None)
|
|
||||||
psel.Inc(pwKey.PwParent())
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
class SyntBlock(Synt):
|
class SyntBlock(Synt):
|
||||||
def Project(self, pcur):
|
def Project(self, pcur):
|
||||||
with pcur.Indent(2 if pcur.pwHoriz != None else 0):
|
with pcur.Indent(2 if pcur.pwHoriz != None else 0):
|
||||||
|
@ -277,18 +267,29 @@ class SyntBlock(Synt):
|
||||||
psel.Inc(pcur.pwVert)
|
psel.Inc(pcur.pwVert)
|
||||||
PwButtonHidden(pcur.pwVert, "[insert new line]", None, OnInsertNewLine, pcur.dxindent)
|
PwButtonHidden(pcur.pwVert, "[insert new line]", None, OnInsertNewLine, pcur.dxindent)
|
||||||
for syntLine in self.rgsynt:
|
for syntLine in self.rgsynt:
|
||||||
syntLine.Project(pcur)
|
pwKey = PwKeyHandler(pcur.pwVert, self.HandleKey)
|
||||||
|
with pcur.ProjectHoriz(pwKey, syntLine):
|
||||||
|
syntLine.Project(pcur)
|
||||||
|
|
||||||
|
def RgsyntForChild(self, syntChild, st):
|
||||||
|
return SyntLine.RgsyntReplace(syntChild, st, None)
|
||||||
|
|
||||||
def InsertLineAfter(self, syntAfter, syntStmt):
|
def InsertLineAfter(self, syntAfter, syntStmt):
|
||||||
syntLine = SyntLine(self)
|
if syntStmt == None:
|
||||||
if syntStmt != None:
|
syntStmt = SyntLine(self)
|
||||||
syntLine.SetStmt(syntStmt)
|
|
||||||
if syntAfter == None:
|
if syntAfter == None:
|
||||||
self.rgsynt.insert(0, syntLine)
|
self.rgsynt.insert(0, syntStmt)
|
||||||
else:
|
else:
|
||||||
self.rgsynt.insert(self.rgsynt.index(syntAfter) + 1, syntLine)
|
self.rgsynt.insert(self.rgsynt.index(syntAfter) + 1, syntStmt)
|
||||||
return syntLine
|
syntStmt.syntParent = self
|
||||||
|
return syntStmt
|
||||||
|
|
||||||
|
def HandleKey(self, pwKey, pov, psel, key):
|
||||||
|
if ansi.FEnter(key):
|
||||||
|
self.InsertLineAfter(pwKey.pwChild.Value(), None)
|
||||||
|
psel.Inc(pwKey.PwParent())
|
||||||
|
return True
|
||||||
|
return False
|
||||||
class SyntLit(Synt):
|
class SyntLit(Synt):
|
||||||
def InitPersistent(self, syntParent, value, rtype):
|
def InitPersistent(self, syntParent, value, rtype):
|
||||||
Synt.InitPersistent(self, syntParent)
|
Synt.InitPersistent(self, syntParent)
|
||||||
|
@ -301,10 +302,6 @@ class SyntLit(Synt):
|
||||||
def Project(self, pcur):
|
def Project(self, pcur):
|
||||||
self.syntParent.ProjectTypeinForChild(pcur.PwHoriz(self), self, self.StForTypein())
|
self.syntParent.ProjectTypeinForChild(pcur.PwHoriz(self), self, self.StForTypein())
|
||||||
|
|
||||||
@RegStmt
|
|
||||||
class SyntBlank(SyntDesc):
|
|
||||||
desc = [[" "]]
|
|
||||||
|
|
||||||
@RegStmt
|
@RegStmt
|
||||||
class SyntVar(SyntDesc):
|
class SyntVar(SyntDesc):
|
||||||
desc = [["Define"], " ", (SyntName, None), " to be ", (SyntExpr, 1)]
|
desc = [["Define"], " ", (SyntName, None), " to be ", (SyntExpr, 1)]
|
||||||
|
@ -318,6 +315,10 @@ class SyntVarRef(Synt):
|
||||||
def __init__(self, syntParent, syntVar = None):
|
def __init__(self, syntParent, syntVar = None):
|
||||||
Synt.__init__(self, syntParent)
|
Synt.__init__(self, syntParent)
|
||||||
self.syntVar = syntVar
|
self.syntVar = syntVar
|
||||||
|
@classmethod
|
||||||
|
def RgsyntReplace(cls, syntChild, st, rtype):
|
||||||
|
rtype = rtype and RtypeAny()
|
||||||
|
return rtype.RgsyntVarRefForChild(syntChild, st)
|
||||||
def Rtype(self):
|
def Rtype(self):
|
||||||
return self.syntVar.Rtype()
|
return self.syntVar.Rtype()
|
||||||
def StForTypein(self):
|
def StForTypein(self):
|
||||||
|
@ -566,14 +567,14 @@ class PwButtonHidden(PwButton):
|
||||||
if mpksel.Get(self) == Ksel.NAV:
|
if mpksel.Get(self) == Ksel.NAV:
|
||||||
PwButton.Draw(self, ascr, x + self.dxIndent, y, w - self.dxIndent, dxStart, mpksel, fOverlay)
|
PwButton.Draw(self, ascr, x + self.dxIndent, y, w - self.dxIndent, dxStart, mpksel, fOverlay)
|
||||||
|
|
||||||
class PwKeyHandler(PwContainer):
|
class PwKeyHandler(PwContainOne):
|
||||||
def __init__(self, pwParent, dgHandleKey):
|
def __init__(self, pwParent, dgHandleKey):
|
||||||
PwContainer.__init__(self, pwParent)
|
PwContainOne.__init__(self, pwParent)
|
||||||
self.dgHandleKey = dgHandleKey
|
self.dgHandleKey = dgHandleKey
|
||||||
def DxDyNew(self, w, dxStart, mpksel):
|
def DxDyNew(self, w, dxStart, mpksel):
|
||||||
return self.RgpwChild()[0].DxDyNew(w, dxStart, mpksel)
|
return self.pwChild.DxDyNew(w, dxStart, mpksel)
|
||||||
def Draw(self, ascr, x, y, w, dxStart, mpksel, fOverlay):
|
def Draw(self, ascr, x, y, w, dxStart, mpksel, fOverlay):
|
||||||
self.RgpwChild()[0].Draw(ascr, x, y, w, dxStart, mpksel, fOverlay)
|
self.pwChild.Draw(ascr, x, y, w, dxStart, mpksel, fOverlay)
|
||||||
def HandleKey(self, pov, psel, key):
|
def HandleKey(self, pov, psel, key):
|
||||||
self.dgHandleKey(self, pov, psel, key)
|
self.dgHandleKey(self, pov, psel, key)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue