From cd240517b548fa9121fa46e30dc4e26937446148 Mon Sep 17 00:00:00 2001 From: "2193177243@qq.com" <2193177243@qq.com> Date: Mon, 9 Oct 2023 10:38:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=BD=AC=E6=8D=A2=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=88API=E6=9C=AA=E5=AE=9E=E7=8E=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ptml/ptmlTranslateAPI.py | 5 ++++- ptml/ptmlTranslator.py | 43 ++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/ptml/ptmlTranslateAPI.py b/ptml/ptmlTranslateAPI.py index 47c011d..41e3543 100644 --- a/ptml/ptmlTranslateAPI.py +++ b/ptml/ptmlTranslateAPI.py @@ -44,9 +44,12 @@ class PyTreesAPI(): with open(filepath, 'w') as file: file.write(self.pystr) - def run() -> None: + def run(self) -> None: """_summary_ """ + self.write_to_file() + out = os.popen('python ./auto_generate.py') + print(out.read()) def newTree(self) -> None: diff --git a/ptml/ptmlTranslator.py b/ptml/ptmlTranslator.py index 848e9fe..a004cdf 100644 --- a/ptml/ptmlTranslator.py +++ b/ptml/ptmlTranslator.py @@ -43,19 +43,23 @@ class ptmlTranslator(ptmlListener): # Enter a parse tree produced by ptmlParser#internal_node. def enterInternal_node(self, ctx:ptmlParser.Internal_nodeContext): - - tag = str(uuid.uuid4()) - 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) + + 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) + # Exit a parse tree produced by ptmlParser#internal_node. def exitInternal_node(self, ctx:ptmlParser.Internal_nodeContext): @@ -68,16 +72,21 @@ class ptmlTranslator(ptmlListener): type = str(ctx.children[0]) name = str(ctx.Names()) + # if have params if len(ctx.children) > 4: - # have params args = ctx.action_parm() print(args.Float()) - - if type == 'cond': - self.api.newBehaviourNode(name, isCond=True) 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.