variable references work!
This commit is contained in:
parent
6213a0f917
commit
0bf142c64e
61
scripting.py
61
scripting.py
|
@ -108,6 +108,10 @@ class Synt(Typeable):
|
|||
def SyntDefault(cls, syntParent):
|
||||
return cls(syntParent)
|
||||
|
||||
@classmethod
|
||||
def RgsyntReplace(cls, syntChild, st, rtype):
|
||||
return []
|
||||
|
||||
def ProjectTypeinForChild(self, pwParent, syntChild, st):
|
||||
def OnSelect(synt, psel):
|
||||
self.Replace(syntChild, synt)
|
||||
|
@ -168,9 +172,7 @@ class SyntDesc(Synt):
|
|||
return self.rgsynt[isynt]
|
||||
def set(self, syntNew):
|
||||
self.Replace(isynt, syntNew)
|
||||
def delete(self):
|
||||
self.Replace(isynt, None)
|
||||
return property(get, set, delete)
|
||||
return property(get, set)
|
||||
|
||||
def Populate(self):
|
||||
for desce in self.desc:
|
||||
|
@ -188,19 +190,32 @@ class SyntDesc(Synt):
|
|||
def delete():
|
||||
self.Replace(isynt, None)
|
||||
return property(get, set, delete)
|
||||
|
||||
def RtypeTopForChild(self, syntChild):
|
||||
isyntChild = self.Isynt(syntChild)
|
||||
isyntDesce = 0
|
||||
|
||||
def DesceChild(self, isyntChild):
|
||||
isyntDesce = 0;
|
||||
for desce in self.desc:
|
||||
if isinstance(desce, tuple):
|
||||
if isyntDesce == isyntChild:
|
||||
if isinstance(desce[1], tuple):
|
||||
return desce[1][0]
|
||||
return None
|
||||
return desce
|
||||
isyntDesce += 1
|
||||
return None
|
||||
|
||||
def RtypeTopForChild(self, syntChild):
|
||||
isyntChild = self.Isynt(syntChild)
|
||||
desce = self.DesceChild(isyntChild)
|
||||
if desce != None and isinstance(desce[1], tuple):
|
||||
return desce[1][0]
|
||||
return None
|
||||
|
||||
def RgsyntForChild(self, syntChild, st):
|
||||
isyntChild = self.Isynt(syntChild)
|
||||
desce = self.DesceChild(isyntChild)
|
||||
if desce != None:
|
||||
rtype = None
|
||||
if isinstance(desce[1], tuple):
|
||||
rtype = desce[1][1]
|
||||
return desce[0].RgsyntReplace(syntChild, st, rtype)
|
||||
return []
|
||||
def Project(self, pcur):
|
||||
"adds more horizontal pws to a horizontal pw"
|
||||
isynt = 0
|
||||
|
@ -217,9 +232,14 @@ class SyntDesc(Synt):
|
|||
|
||||
class SyntName(Synt):
|
||||
def Project(self, pcur):
|
||||
PwTypein(pcur.PwHoriz(self), self.GetStTypein(), self)
|
||||
|
||||
PwTypein(pcur.PwHoriz(self), self.St(), self)
|
||||
def St(self):
|
||||
return self.GetStTypein()
|
||||
|
||||
class SyntExpr(Synt):
|
||||
@classmethod
|
||||
def RgsyntReplace(cls, syntChild, st, rtype):
|
||||
return RtypeAny().RgsyntFromSt(syntChild.syntParent, st)
|
||||
def Project(self, pcur):
|
||||
self.syntParent.ProjectTypeinForChild(pcur.PwHoriz(self), self, " ")
|
||||
|
||||
|
@ -274,10 +294,13 @@ class SyntLit(Synt):
|
|||
Synt.InitPersistent(self, syntParent)
|
||||
self.value = value
|
||||
self.rtype = rtype
|
||||
|
||||
def StForTypein(self):
|
||||
return self.rtype.StForSobj(self.value)
|
||||
def Rtype(self):
|
||||
return rtype
|
||||
|
||||
return self.rtype
|
||||
def Project(self, pcur):
|
||||
self.syntParent.ProjectTypeinForChild(pcur.PwHoriz(self), self, self.StForTypein())
|
||||
|
||||
@RegStmt
|
||||
class SyntBlank(SyntDesc):
|
||||
desc = [[" "]]
|
||||
|
@ -289,7 +312,7 @@ class SyntVar(SyntDesc):
|
|||
expr = SyntDesc.DefProp(1)
|
||||
@classmethod
|
||||
def FVarOfType(cls, synt, rtype):
|
||||
return isinstance(synt, cls) and synt.expr != None and rtype.FOverlap(expr.Rtype())
|
||||
return isinstance(synt, cls) and synt.expr != None and rtype.FOverlap(synt.expr.Rtype())
|
||||
|
||||
class SyntVarRef(Synt):
|
||||
def __init__(self, syntParent, syntVar = None):
|
||||
|
@ -297,7 +320,11 @@ class SyntVarRef(Synt):
|
|||
self.syntVar = syntVar
|
||||
def Rtype(self):
|
||||
return self.syntVar.Rtype()
|
||||
|
||||
def StForTypein(self):
|
||||
return self.syntVar.name.St()
|
||||
def Project(self, pcur):
|
||||
self.syntParent.ProjectTypeinForChild(pcur.PwHoriz(self), self, self.StForTypein())
|
||||
|
||||
@RegStmt
|
||||
class SyntIf(SyntDesc):
|
||||
desc = [["If"], " ", (SyntExpr, (1, RtypeBool)), ", then:", (SyntBlock, None), "or else:", (SyntBlock, None)]
|
||||
|
|
Loading…
Reference in a new issue