实现转换方法(API未实现)
This commit is contained in:
parent
69c6c32b62
commit
cd240517b5
|
@ -44,9 +44,12 @@ class PyTreesAPI():
|
||||||
with open(filepath, 'w') as file:
|
with open(filepath, 'w') as file:
|
||||||
file.write(self.pystr)
|
file.write(self.pystr)
|
||||||
|
|
||||||
def run() -> None:
|
def run(self) -> None:
|
||||||
"""_summary_
|
"""_summary_
|
||||||
"""
|
"""
|
||||||
|
self.write_to_file()
|
||||||
|
out = os.popen('python ./auto_generate.py')
|
||||||
|
print(out.read())
|
||||||
|
|
||||||
|
|
||||||
def newTree(self) -> None:
|
def newTree(self) -> None:
|
||||||
|
|
|
@ -43,19 +43,23 @@ class ptmlTranslator(ptmlListener):
|
||||||
|
|
||||||
# Enter a parse tree produced by ptmlParser#internal_node.
|
# Enter a parse tree produced by ptmlParser#internal_node.
|
||||||
def enterInternal_node(self, ctx:ptmlParser.Internal_nodeContext):
|
def enterInternal_node(self, ctx:ptmlParser.Internal_nodeContext):
|
||||||
|
type = str(ctx.children[0])
|
||||||
|
|
||||||
tag = str(uuid.uuid4())
|
match type:
|
||||||
|
case 'sequence':
|
||||||
|
tag = self.api.newSequenceNode()
|
||||||
|
case 'selector':
|
||||||
|
tag = self.api.newSelectorNode()
|
||||||
|
case 'parallel':
|
||||||
|
tag = self.api.newParallelNode(threshold=int(ctx.children[1]))
|
||||||
|
case 'decorator':
|
||||||
|
tag = self.api.newDecoratorNode()
|
||||||
|
case _:
|
||||||
|
raise TypeError(
|
||||||
|
''
|
||||||
|
)
|
||||||
self.stack.append(tag)
|
self.stack.append(tag)
|
||||||
|
|
||||||
type = str(ctx.children[0])
|
|
||||||
if type == 'sequence':
|
|
||||||
self.api.newSequenceNode(tag)
|
|
||||||
elif type == 'selector':
|
|
||||||
self.api.newSelectorNode(tag)
|
|
||||||
elif type == 'parallel':
|
|
||||||
self.api.newParallelNode(tag, threshold=int(ctx.children[1]))
|
|
||||||
elif type == 'decorator':
|
|
||||||
self.api.newDecoratorNode(tag)
|
|
||||||
|
|
||||||
# Exit a parse tree produced by ptmlParser#internal_node.
|
# Exit a parse tree produced by ptmlParser#internal_node.
|
||||||
def exitInternal_node(self, ctx:ptmlParser.Internal_nodeContext):
|
def exitInternal_node(self, ctx:ptmlParser.Internal_nodeContext):
|
||||||
|
@ -68,16 +72,21 @@ class ptmlTranslator(ptmlListener):
|
||||||
type = str(ctx.children[0])
|
type = str(ctx.children[0])
|
||||||
name = str(ctx.Names())
|
name = str(ctx.Names())
|
||||||
|
|
||||||
|
# if have params
|
||||||
if len(ctx.children) > 4:
|
if len(ctx.children) > 4:
|
||||||
# have params
|
|
||||||
args = ctx.action_parm()
|
args = ctx.action_parm()
|
||||||
print(args.Float())
|
print(args.Float())
|
||||||
|
|
||||||
if type == 'cond':
|
|
||||||
self.api.newBehaviourNode(name, isCond=True)
|
|
||||||
else:
|
else:
|
||||||
self.api.newBehaviourNode(name, isCond=False)
|
args = []
|
||||||
|
|
||||||
|
#
|
||||||
|
if type == 'cond':
|
||||||
|
behav_tag = self.api.newBehaviourNode(name, args, isCond=True)
|
||||||
|
else:
|
||||||
|
behav_tag = self.api.newBehaviourNode(name, args, isCond=False)
|
||||||
|
# connect
|
||||||
|
parent_tag = self.stack[-1]
|
||||||
|
self.api.connect_to_parent(behav_tag, parent_tag)
|
||||||
|
|
||||||
|
|
||||||
# Exit a parse tree produced by ptmlParser#action_sign.
|
# Exit a parse tree produced by ptmlParser#action_sign.
|
||||||
|
|
Loading…
Reference in New Issue