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):
|
def SyntDefault(cls, syntParent):
|
||||||
return cls(syntParent)
|
return cls(syntParent)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def RgsyntReplace(cls, syntChild, st, rtype):
|
||||||
|
return []
|
||||||
|
|
||||||
def ProjectTypeinForChild(self, pwParent, syntChild, st):
|
def ProjectTypeinForChild(self, pwParent, syntChild, st):
|
||||||
def OnSelect(synt, psel):
|
def OnSelect(synt, psel):
|
||||||
self.Replace(syntChild, synt)
|
self.Replace(syntChild, synt)
|
||||||
|
@ -168,9 +172,7 @@ class SyntDesc(Synt):
|
||||||
return self.rgsynt[isynt]
|
return self.rgsynt[isynt]
|
||||||
def set(self, syntNew):
|
def set(self, syntNew):
|
||||||
self.Replace(isynt, syntNew)
|
self.Replace(isynt, syntNew)
|
||||||
def delete(self):
|
return property(get, set)
|
||||||
self.Replace(isynt, None)
|
|
||||||
return property(get, set, delete)
|
|
||||||
|
|
||||||
def Populate(self):
|
def Populate(self):
|
||||||
for desce in self.desc:
|
for desce in self.desc:
|
||||||
|
@ -188,19 +190,32 @@ class SyntDesc(Synt):
|
||||||
def delete():
|
def delete():
|
||||||
self.Replace(isynt, None)
|
self.Replace(isynt, None)
|
||||||
return property(get, set, delete)
|
return property(get, set, delete)
|
||||||
|
|
||||||
def RtypeTopForChild(self, syntChild):
|
def DesceChild(self, isyntChild):
|
||||||
isyntChild = self.Isynt(syntChild)
|
isyntDesce = 0;
|
||||||
isyntDesce = 0
|
|
||||||
for desce in self.desc:
|
for desce in self.desc:
|
||||||
if isinstance(desce, tuple):
|
if isinstance(desce, tuple):
|
||||||
if isyntDesce == isyntChild:
|
if isyntDesce == isyntChild:
|
||||||
if isinstance(desce[1], tuple):
|
return desce
|
||||||
return desce[1][0]
|
|
||||||
return None
|
|
||||||
isyntDesce += 1
|
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
|
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):
|
def Project(self, pcur):
|
||||||
"adds more horizontal pws to a horizontal pw"
|
"adds more horizontal pws to a horizontal pw"
|
||||||
isynt = 0
|
isynt = 0
|
||||||
|
@ -217,9 +232,14 @@ class SyntDesc(Synt):
|
||||||
|
|
||||||
class SyntName(Synt):
|
class SyntName(Synt):
|
||||||
def Project(self, pcur):
|
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):
|
class SyntExpr(Synt):
|
||||||
|
@classmethod
|
||||||
|
def RgsyntReplace(cls, syntChild, st, rtype):
|
||||||
|
return RtypeAny().RgsyntFromSt(syntChild.syntParent, st)
|
||||||
def Project(self, pcur):
|
def Project(self, pcur):
|
||||||
self.syntParent.ProjectTypeinForChild(pcur.PwHoriz(self), self, " ")
|
self.syntParent.ProjectTypeinForChild(pcur.PwHoriz(self), self, " ")
|
||||||
|
|
||||||
|
@ -274,10 +294,13 @@ class SyntLit(Synt):
|
||||||
Synt.InitPersistent(self, syntParent)
|
Synt.InitPersistent(self, syntParent)
|
||||||
self.value = value
|
self.value = value
|
||||||
self.rtype = rtype
|
self.rtype = rtype
|
||||||
|
def StForTypein(self):
|
||||||
|
return self.rtype.StForSobj(self.value)
|
||||||
def Rtype(self):
|
def Rtype(self):
|
||||||
return rtype
|
return self.rtype
|
||||||
|
def Project(self, pcur):
|
||||||
|
self.syntParent.ProjectTypeinForChild(pcur.PwHoriz(self), self, self.StForTypein())
|
||||||
|
|
||||||
@RegStmt
|
@RegStmt
|
||||||
class SyntBlank(SyntDesc):
|
class SyntBlank(SyntDesc):
|
||||||
desc = [[" "]]
|
desc = [[" "]]
|
||||||
|
@ -289,7 +312,7 @@ class SyntVar(SyntDesc):
|
||||||
expr = SyntDesc.DefProp(1)
|
expr = SyntDesc.DefProp(1)
|
||||||
@classmethod
|
@classmethod
|
||||||
def FVarOfType(cls, synt, rtype):
|
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):
|
class SyntVarRef(Synt):
|
||||||
def __init__(self, syntParent, syntVar = None):
|
def __init__(self, syntParent, syntVar = None):
|
||||||
|
@ -297,7 +320,11 @@ class SyntVarRef(Synt):
|
||||||
self.syntVar = syntVar
|
self.syntVar = syntVar
|
||||||
def Rtype(self):
|
def Rtype(self):
|
||||||
return self.syntVar.Rtype()
|
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
|
@RegStmt
|
||||||
class SyntIf(SyntDesc):
|
class SyntIf(SyntDesc):
|
||||||
desc = [["If"], " ", (SyntExpr, (1, RtypeBool)), ", then:", (SyntBlock, None), "or else:", (SyntBlock, None)]
|
desc = [["If"], " ", (SyntExpr, (1, RtypeBool)), ", then:", (SyntBlock, None), "or else:", (SyntBlock, None)]
|
||||||
|
|
Loading…
Reference in a new issue