本文整理汇总了Python中env.Env.shortString方法的典型用法代码示例。如果您正苦于以下问题:Python Env.shortString方法的具体用法?Python Env.shortString怎么用?Python Env.shortString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类env.Env
的用法示例。
在下文中一共展示了Env.shortString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from env import Env [as 别名]
# 或者: from env.Env import shortString [as 别名]
class Animate:
def __init__(self, world):
self.world = world
self.oldWorld = world
self.passes = 0
self.fails = 0
self.curEnv = Env()
def dispatch(self, input):
words = input.split(" ")
if len(words) == 0:
return ""
cmd = words[0]
args = []
if len(words) > 1:
input = input.replace("\;", "__colon")
args = map(lambda x: x.strip().replace("__colon", "\;"), input[len(cmd)+1:].split(";"))
if cmd == "exit":
tests = ""
if self.passes+self.fails > 0:
tests = "Assertions failed: " + str(self.fails) + ", passed: " + str(self.passes) + ", total: " + str(self.passes+self.fails)
return "_exit" + tests
if cmd in ("help", "symbols", "judges"):
return getattr(self, cmd)()
if cmd in ("ids", "names", "sup", "cases"):
if len(args) == 1:
return getattr(self, cmd)(args[0])
else:
return "Error, " + cmd + " takes one argument"
if cmd == "assert":
if len(args) >= 2:
return self.assertS(args[0], args[1:])
else:
return "Error, assert requires at least two arguments"
if cmd in ("eval", "assume", "type", "env", "subst", "fv"):
return getattr(self, cmd)(args)
if cmd in ("match", "subtype"):
if len(args) == 2:
return getattr(self, cmd)(args[0], args[1])
else:
return "Error, " + cmd + " takes two arguments"
if cmd:
return "Unknown command, for help, use 'help', to leave animation mode, use 'exit'"
return ""
def match(self, sym, exp):
try:
sym = self.parseSynExp(sym)
exp = self.parseSemExp(exp)
except AnimError as e:
return str(e)
m = exp.isSuperType(sym,set(self.world.symbols.values()))
if m:
return "Yes(" + sym.longString() + "; " + exp.longString() + "; " + m.shortString() + ")"
else:
return "No(" + sym.longString() + "; " + exp.longString() + ")"
def subtype(self, e1, e2):
try:
e1 = self.parseSynExp(e1)
e2 = self.parseSynExp(e2)
except AnimError as e:
return str(e)
if e1.isSuperType(e2, self.world.symList):
return "Yes"
else:
return "No"
def assertS(self, result, rest):
test = self.dispatch("; ".join(rest))
if test.startswith(result):
self.passes += 1
return ""
else:
self.fails += 1
return "Failed assertion: '" + "; ".join(rest) + "'\n expected: '" + result + "'\n found: '" + test + "'"
def assign(self, cmd):
pass
def help(self):
return """Animation mode commands:
help print this message
exit leave animation mode
eval p [with cs] evaluate the meta-expression p
using the given free variable bindings
c ::= x '=' e
cs ::= cs ';' c | []
assume p add p to the environment if not p cannot be proved
env [clear] display the current environment
clear = clear environment
type e the type of e
#.........这里部分代码省略.........