From c323fa1da9e1474cc384df7d61b12d117086f9ee Mon Sep 17 00:00:00 2001 From: "2193177243@qq.com" <2193177243@qq.com> Date: Tue, 10 Oct 2023 20:47:32 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20=E5=AE=9E=E7=8E=B0load?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8C=E5=AE=8C=E6=88=90ptml=E5=88=B0?= =?UTF-8?q?=E8=A1=8C=E4=B8=BA=E6=A0=91=E5=AF=B9=E8=B1=A1=E7=9A=84=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=20=F0=9F=91=8C=20IMPROVE:=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86ptml=E7=9A=84=E8=AF=AD=E6=B3=95=EF=BC=8C=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BC=A0=E9=80=92=E7=9B=AE=E5=89=8D=E4=BB=85=E6=94=AF?= =?UTF-8?q?=E6=8C=81int=E3=80=81float=E3=80=81boolean=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E9=87=87=E7=94=A8=E6=8B=AC=E5=8F=B7=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ptml/CoffeeDelivery.ptml | 35 ++++-- ptml/behaviour_lib/CoffeeCupFound.py | 21 ++++ ptml/behaviour_lib/CoffeeCupGrasped.py | 21 ++++ ptml/behaviour_lib/CoffeeCupPlaced.py | 21 ++++ ptml/behaviour_lib/DestinationAReached.py | 21 ++++ ptml/behaviour_lib/FindCoffeeCup.py | 21 ++++ ptml/behaviour_lib/Grasp.py | 21 ++++ ptml/behaviour_lib/GraspCoffeeCup.py | 21 ++++ ptml/behaviour_lib/Istask.py | 21 ++++ ptml/behaviour_lib/Move.py | 21 ++++ ptml/behaviour_lib/PlaceCoffeeCup.py | 21 ++++ ptml/behaviour_lib/ReachDestinationA.py | 21 ++++ ptml/behaviour_lib/SeqTest.py | 21 ++++ ptml/behaviour_lib/TestTask.py | 21 ++++ ptml/ptml.g4 | 4 +- ptml/ptml.interp | 6 +- ptml/ptml.tokens | 10 +- ptml/ptmlCompiler.py | 40 +++++++ ptml/ptmlLexer.interp | 6 +- ptml/ptmlLexer.py | 117 +++++++++--------- ptml/ptmlLexer.tokens | 10 +- ptml/ptmlParser.py | 140 +++++++++++----------- ptml/ptmlTranslateAPI.py | 123 ------------------- ptml/ptmlTranslator.py | 98 ++++++++------- ptml/ptml_test.py | 31 ++--- ptml/sequence_oufbg8fg.dot | 45 +++++++ 26 files changed, 597 insertions(+), 341 deletions(-) create mode 100644 ptml/behaviour_lib/CoffeeCupFound.py create mode 100644 ptml/behaviour_lib/CoffeeCupGrasped.py create mode 100644 ptml/behaviour_lib/CoffeeCupPlaced.py create mode 100644 ptml/behaviour_lib/DestinationAReached.py create mode 100644 ptml/behaviour_lib/FindCoffeeCup.py create mode 100644 ptml/behaviour_lib/Grasp.py create mode 100644 ptml/behaviour_lib/GraspCoffeeCup.py create mode 100644 ptml/behaviour_lib/Istask.py create mode 100644 ptml/behaviour_lib/Move.py create mode 100644 ptml/behaviour_lib/PlaceCoffeeCup.py create mode 100644 ptml/behaviour_lib/ReachDestinationA.py create mode 100644 ptml/behaviour_lib/SeqTest.py create mode 100644 ptml/behaviour_lib/TestTask.py create mode 100644 ptml/ptmlCompiler.py delete mode 100644 ptml/ptmlTranslateAPI.py create mode 100644 ptml/sequence_oufbg8fg.dot diff --git a/ptml/CoffeeDelivery.ptml b/ptml/CoffeeDelivery.ptml index ea8bbdc..50cd0ed 100644 --- a/ptml/CoffeeDelivery.ptml +++ b/ptml/CoffeeDelivery.ptml @@ -1,16 +1,35 @@ -sequence: - selector: +//sequence: +// act action1() +// act action2(2, 2.3, True) +// +// parallel 2: +// act action3(int a, float b) +// act action4() + +sequence{ + selector{ cond CoffeeCupFound() task FindCoffeeCup() - sequence: + sequence{ cond SeqTest() - task Move() - selector: + task Move(1.2, 2, 2.3, True) + task Grasp() + parallel 3 { + cond Istask() + task TestTask() + } + } + } + selector{ cond CoffeeCupGrasped() task GraspCoffeeCup() - selector: + } + selector{ cond DestinationAReached() task ReachDestinationA() - selector: + } + selector{ cond CoffeeCupPlaced() - task PlaceCoffeeCup(1.2) \ No newline at end of file + task PlaceCoffeeCup() + } +} diff --git a/ptml/behaviour_lib/CoffeeCupFound.py b/ptml/behaviour_lib/CoffeeCupFound.py new file mode 100644 index 0000000..b3e6db3 --- /dev/null +++ b/ptml/behaviour_lib/CoffeeCupFound.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class CoffeeCupFound(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/CoffeeCupGrasped.py b/ptml/behaviour_lib/CoffeeCupGrasped.py new file mode 100644 index 0000000..f12d12b --- /dev/null +++ b/ptml/behaviour_lib/CoffeeCupGrasped.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class CoffeeCupGrasped(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/CoffeeCupPlaced.py b/ptml/behaviour_lib/CoffeeCupPlaced.py new file mode 100644 index 0000000..2b6f2e3 --- /dev/null +++ b/ptml/behaviour_lib/CoffeeCupPlaced.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class CoffeeCupPlaced(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/DestinationAReached.py b/ptml/behaviour_lib/DestinationAReached.py new file mode 100644 index 0000000..48c75df --- /dev/null +++ b/ptml/behaviour_lib/DestinationAReached.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class DestinationAReached(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/FindCoffeeCup.py b/ptml/behaviour_lib/FindCoffeeCup.py new file mode 100644 index 0000000..3504e7f --- /dev/null +++ b/ptml/behaviour_lib/FindCoffeeCup.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class FindCoffeeCup(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/Grasp.py b/ptml/behaviour_lib/Grasp.py new file mode 100644 index 0000000..964aed1 --- /dev/null +++ b/ptml/behaviour_lib/Grasp.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class Grasp(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/GraspCoffeeCup.py b/ptml/behaviour_lib/GraspCoffeeCup.py new file mode 100644 index 0000000..ca97d68 --- /dev/null +++ b/ptml/behaviour_lib/GraspCoffeeCup.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class GraspCoffeeCup(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/Istask.py b/ptml/behaviour_lib/Istask.py new file mode 100644 index 0000000..293022b --- /dev/null +++ b/ptml/behaviour_lib/Istask.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class Istask(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/Move.py b/ptml/behaviour_lib/Move.py new file mode 100644 index 0000000..0e76abd --- /dev/null +++ b/ptml/behaviour_lib/Move.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class Move(ptree.behaviour.Behaviour): + + def __init__(self, name: str, a, b, c, d): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/PlaceCoffeeCup.py b/ptml/behaviour_lib/PlaceCoffeeCup.py new file mode 100644 index 0000000..592837f --- /dev/null +++ b/ptml/behaviour_lib/PlaceCoffeeCup.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class PlaceCoffeeCup(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/ReachDestinationA.py b/ptml/behaviour_lib/ReachDestinationA.py new file mode 100644 index 0000000..08134de --- /dev/null +++ b/ptml/behaviour_lib/ReachDestinationA.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class ReachDestinationA(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/SeqTest.py b/ptml/behaviour_lib/SeqTest.py new file mode 100644 index 0000000..4ebca75 --- /dev/null +++ b/ptml/behaviour_lib/SeqTest.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class SeqTest(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/behaviour_lib/TestTask.py b/ptml/behaviour_lib/TestTask.py new file mode 100644 index 0000000..0ee6fbb --- /dev/null +++ b/ptml/behaviour_lib/TestTask.py @@ -0,0 +1,21 @@ +import py_trees as ptree +from typing import Any + +class TestTask(ptree.behaviour.Behaviour): + + def __init__(self, name: str): + super().__init__(name) + + def setup(self, **kwargs: Any) -> None: + return super().setup(**kwargs) + + def initialise(self) -> None: + return super().initialise() + + def update(self) -> ptree.common.Status: + print('Start checking IsChatting...') + return ptree.common.Status.SUCCESS + + def terminate(self, new_status: ptree.common.Status) -> None: + return super().terminate(new_status) + \ No newline at end of file diff --git a/ptml/ptml.g4 b/ptml/ptml.g4 index adab6ae..0a545a9 100644 --- a/ptml/ptml.g4 +++ b/ptml/ptml.g4 @@ -2,8 +2,8 @@ grammar ptml; root : tree+ EOF; -tree : internal_node ':' (action_sign|tree)+ ; -internal_node : 'sequence' | 'selector' | 'parallel' Integer | 'decorator' ; +tree : internal_node '{' (action_sign|tree)+ '}' ; +internal_node : 'sequence' | 'selector' | 'parallel' Integer ; action_sign : ('task'|'cond') Names '(' action_parm? ')'; action_parm : (Integer|Float|boolean) (',' (Integer|Float|boolean))* ; // var_decls : var_type Names ; diff --git a/ptml/ptml.interp b/ptml/ptml.interp index 3ded37b..a96ef7d 100644 --- a/ptml/ptml.interp +++ b/ptml/ptml.interp @@ -1,10 +1,10 @@ token literal names: null -':' +'{' +'}' 'sequence' 'selector' 'parallel' -'decorator' 'task' 'cond' '(' @@ -48,4 +48,4 @@ boolean atn: -[4, 1, 17, 61, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 4, 0, 14, 8, 0, 11, 0, 12, 0, 15, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 24, 8, 1, 11, 1, 12, 1, 25, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 33, 8, 2, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 39, 8, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 3, 4, 46, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 52, 8, 4, 5, 4, 54, 8, 4, 10, 4, 12, 4, 57, 9, 4, 1, 5, 1, 5, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 2, 1, 0, 6, 7, 1, 0, 11, 12, 66, 0, 13, 1, 0, 0, 0, 2, 19, 1, 0, 0, 0, 4, 32, 1, 0, 0, 0, 6, 34, 1, 0, 0, 0, 8, 45, 1, 0, 0, 0, 10, 58, 1, 0, 0, 0, 12, 14, 3, 2, 1, 0, 13, 12, 1, 0, 0, 0, 14, 15, 1, 0, 0, 0, 15, 13, 1, 0, 0, 0, 15, 16, 1, 0, 0, 0, 16, 17, 1, 0, 0, 0, 17, 18, 5, 0, 0, 1, 18, 1, 1, 0, 0, 0, 19, 20, 3, 4, 2, 0, 20, 23, 5, 1, 0, 0, 21, 24, 3, 6, 3, 0, 22, 24, 3, 2, 1, 0, 23, 21, 1, 0, 0, 0, 23, 22, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 23, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 3, 1, 0, 0, 0, 27, 33, 5, 2, 0, 0, 28, 33, 5, 3, 0, 0, 29, 30, 5, 4, 0, 0, 30, 33, 5, 14, 0, 0, 31, 33, 5, 5, 0, 0, 32, 27, 1, 0, 0, 0, 32, 28, 1, 0, 0, 0, 32, 29, 1, 0, 0, 0, 32, 31, 1, 0, 0, 0, 33, 5, 1, 0, 0, 0, 34, 35, 7, 0, 0, 0, 35, 36, 5, 13, 0, 0, 36, 38, 5, 8, 0, 0, 37, 39, 3, 8, 4, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 40, 1, 0, 0, 0, 40, 41, 5, 9, 0, 0, 41, 7, 1, 0, 0, 0, 42, 46, 5, 14, 0, 0, 43, 46, 5, 15, 0, 0, 44, 46, 3, 10, 5, 0, 45, 42, 1, 0, 0, 0, 45, 43, 1, 0, 0, 0, 45, 44, 1, 0, 0, 0, 46, 55, 1, 0, 0, 0, 47, 51, 5, 10, 0, 0, 48, 52, 5, 14, 0, 0, 49, 52, 5, 15, 0, 0, 50, 52, 3, 10, 5, 0, 51, 48, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 51, 50, 1, 0, 0, 0, 52, 54, 1, 0, 0, 0, 53, 47, 1, 0, 0, 0, 54, 57, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 55, 56, 1, 0, 0, 0, 56, 9, 1, 0, 0, 0, 57, 55, 1, 0, 0, 0, 58, 59, 7, 1, 0, 0, 59, 11, 1, 0, 0, 0, 8, 15, 23, 25, 32, 38, 45, 51, 55] \ No newline at end of file +[4, 1, 17, 62, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 4, 0, 14, 8, 0, 11, 0, 12, 0, 15, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 24, 8, 1, 11, 1, 12, 1, 25, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 34, 8, 2, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 40, 8, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 3, 4, 47, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 53, 8, 4, 5, 4, 55, 8, 4, 10, 4, 12, 4, 58, 9, 4, 1, 5, 1, 5, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 2, 1, 0, 6, 7, 1, 0, 11, 12, 66, 0, 13, 1, 0, 0, 0, 2, 19, 1, 0, 0, 0, 4, 33, 1, 0, 0, 0, 6, 35, 1, 0, 0, 0, 8, 46, 1, 0, 0, 0, 10, 59, 1, 0, 0, 0, 12, 14, 3, 2, 1, 0, 13, 12, 1, 0, 0, 0, 14, 15, 1, 0, 0, 0, 15, 13, 1, 0, 0, 0, 15, 16, 1, 0, 0, 0, 16, 17, 1, 0, 0, 0, 17, 18, 5, 0, 0, 1, 18, 1, 1, 0, 0, 0, 19, 20, 3, 4, 2, 0, 20, 23, 5, 1, 0, 0, 21, 24, 3, 6, 3, 0, 22, 24, 3, 2, 1, 0, 23, 21, 1, 0, 0, 0, 23, 22, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 23, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 27, 1, 0, 0, 0, 27, 28, 5, 2, 0, 0, 28, 3, 1, 0, 0, 0, 29, 34, 5, 3, 0, 0, 30, 34, 5, 4, 0, 0, 31, 32, 5, 5, 0, 0, 32, 34, 5, 14, 0, 0, 33, 29, 1, 0, 0, 0, 33, 30, 1, 0, 0, 0, 33, 31, 1, 0, 0, 0, 34, 5, 1, 0, 0, 0, 35, 36, 7, 0, 0, 0, 36, 37, 5, 13, 0, 0, 37, 39, 5, 8, 0, 0, 38, 40, 3, 8, 4, 0, 39, 38, 1, 0, 0, 0, 39, 40, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 42, 5, 9, 0, 0, 42, 7, 1, 0, 0, 0, 43, 47, 5, 14, 0, 0, 44, 47, 5, 15, 0, 0, 45, 47, 3, 10, 5, 0, 46, 43, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 46, 45, 1, 0, 0, 0, 47, 56, 1, 0, 0, 0, 48, 52, 5, 10, 0, 0, 49, 53, 5, 14, 0, 0, 50, 53, 5, 15, 0, 0, 51, 53, 3, 10, 5, 0, 52, 49, 1, 0, 0, 0, 52, 50, 1, 0, 0, 0, 52, 51, 1, 0, 0, 0, 53, 55, 1, 0, 0, 0, 54, 48, 1, 0, 0, 0, 55, 58, 1, 0, 0, 0, 56, 54, 1, 0, 0, 0, 56, 57, 1, 0, 0, 0, 57, 9, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 59, 60, 7, 1, 0, 0, 60, 11, 1, 0, 0, 0, 8, 15, 23, 25, 33, 39, 46, 52, 56] \ No newline at end of file diff --git a/ptml/ptml.tokens b/ptml/ptml.tokens index 7e8628f..1f7a813 100644 --- a/ptml/ptml.tokens +++ b/ptml/ptml.tokens @@ -15,11 +15,11 @@ Integer=14 Float=15 LINE_COMMENT=16 WS=17 -':'=1 -'sequence'=2 -'selector'=3 -'parallel'=4 -'decorator'=5 +'{'=1 +'}'=2 +'sequence'=3 +'selector'=4 +'parallel'=5 'task'=6 'cond'=7 '('=8 diff --git a/ptml/ptmlCompiler.py b/ptml/ptmlCompiler.py new file mode 100644 index 0000000..58ddf67 --- /dev/null +++ b/ptml/ptmlCompiler.py @@ -0,0 +1,40 @@ +import os +from antlr4 import * +from ptmlTranslator import ptmlTranslator +from ptmlParser import ptmlParser as Parser +from ptmlLexer import ptmlLexer as Lexer + +def load(ptml_path: str, behaviour_lib_path: str): + """_summary_ + + Args: + ptml_path (str): _description_ + behaviour_lib_path (str): _description_ + + Raises: + FileNotFoundError: _description_ + FileNotFoundError: _description_ + """ + # error handle + if not os.path.exists(ptml_path): + raise FileNotFoundError( + 'Given a fault ptml path: {}'.format(ptml_path) + ) + if not os.path.exists(behaviour_lib_path): + raise FileNotFoundError( + 'Given a fault behaviour library path: {}'.format(behaviour_lib_path) + ) + + # noting fault, go next + input_stream = FileStream(ptml_path, encoding='utf-8') + + lexer = Lexer(input_stream) + stream = CommonTokenStream(lexer) + parser = Parser(stream) + tree = parser.root() + + walker = ParseTreeWalker() + ptml = ptmlTranslator() # listener mode + walker.walk(ptml, tree) + + return ptml.bt_root \ No newline at end of file diff --git a/ptml/ptmlLexer.interp b/ptml/ptmlLexer.interp index 17ef107..823b753 100644 --- a/ptml/ptmlLexer.interp +++ b/ptml/ptmlLexer.interp @@ -1,10 +1,10 @@ token literal names: null -':' +'{' +'}' 'sequence' 'selector' 'parallel' -'decorator' 'task' 'cond' '(' @@ -65,4 +65,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 17, 164, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 5, 12, 104, 8, 12, 10, 12, 12, 12, 107, 9, 12, 1, 13, 3, 13, 110, 8, 13, 1, 13, 1, 13, 5, 13, 114, 8, 13, 10, 13, 12, 13, 117, 9, 13, 1, 13, 3, 13, 120, 8, 13, 1, 14, 4, 14, 123, 8, 14, 11, 14, 12, 14, 124, 1, 14, 1, 14, 5, 14, 129, 8, 14, 10, 14, 12, 14, 132, 9, 14, 1, 14, 1, 14, 4, 14, 136, 8, 14, 11, 14, 12, 14, 137, 3, 14, 140, 8, 14, 1, 15, 1, 15, 1, 15, 1, 15, 5, 15, 146, 8, 15, 10, 15, 12, 15, 149, 9, 15, 1, 15, 3, 15, 152, 8, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 4, 16, 159, 8, 16, 11, 16, 12, 16, 160, 1, 16, 1, 16, 1, 147, 0, 17, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 1, 0, 5, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 1, 0, 49, 57, 1, 0, 48, 57, 3, 0, 9, 10, 12, 13, 32, 32, 174, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 1, 35, 1, 0, 0, 0, 3, 37, 1, 0, 0, 0, 5, 46, 1, 0, 0, 0, 7, 55, 1, 0, 0, 0, 9, 64, 1, 0, 0, 0, 11, 74, 1, 0, 0, 0, 13, 79, 1, 0, 0, 0, 15, 84, 1, 0, 0, 0, 17, 86, 1, 0, 0, 0, 19, 88, 1, 0, 0, 0, 21, 90, 1, 0, 0, 0, 23, 95, 1, 0, 0, 0, 25, 101, 1, 0, 0, 0, 27, 119, 1, 0, 0, 0, 29, 139, 1, 0, 0, 0, 31, 141, 1, 0, 0, 0, 33, 158, 1, 0, 0, 0, 35, 36, 5, 58, 0, 0, 36, 2, 1, 0, 0, 0, 37, 38, 5, 115, 0, 0, 38, 39, 5, 101, 0, 0, 39, 40, 5, 113, 0, 0, 40, 41, 5, 117, 0, 0, 41, 42, 5, 101, 0, 0, 42, 43, 5, 110, 0, 0, 43, 44, 5, 99, 0, 0, 44, 45, 5, 101, 0, 0, 45, 4, 1, 0, 0, 0, 46, 47, 5, 115, 0, 0, 47, 48, 5, 101, 0, 0, 48, 49, 5, 108, 0, 0, 49, 50, 5, 101, 0, 0, 50, 51, 5, 99, 0, 0, 51, 52, 5, 116, 0, 0, 52, 53, 5, 111, 0, 0, 53, 54, 5, 114, 0, 0, 54, 6, 1, 0, 0, 0, 55, 56, 5, 112, 0, 0, 56, 57, 5, 97, 0, 0, 57, 58, 5, 114, 0, 0, 58, 59, 5, 97, 0, 0, 59, 60, 5, 108, 0, 0, 60, 61, 5, 108, 0, 0, 61, 62, 5, 101, 0, 0, 62, 63, 5, 108, 0, 0, 63, 8, 1, 0, 0, 0, 64, 65, 5, 100, 0, 0, 65, 66, 5, 101, 0, 0, 66, 67, 5, 99, 0, 0, 67, 68, 5, 111, 0, 0, 68, 69, 5, 114, 0, 0, 69, 70, 5, 97, 0, 0, 70, 71, 5, 116, 0, 0, 71, 72, 5, 111, 0, 0, 72, 73, 5, 114, 0, 0, 73, 10, 1, 0, 0, 0, 74, 75, 5, 116, 0, 0, 75, 76, 5, 97, 0, 0, 76, 77, 5, 115, 0, 0, 77, 78, 5, 107, 0, 0, 78, 12, 1, 0, 0, 0, 79, 80, 5, 99, 0, 0, 80, 81, 5, 111, 0, 0, 81, 82, 5, 110, 0, 0, 82, 83, 5, 100, 0, 0, 83, 14, 1, 0, 0, 0, 84, 85, 5, 40, 0, 0, 85, 16, 1, 0, 0, 0, 86, 87, 5, 41, 0, 0, 87, 18, 1, 0, 0, 0, 88, 89, 5, 44, 0, 0, 89, 20, 1, 0, 0, 0, 90, 91, 5, 84, 0, 0, 91, 92, 5, 114, 0, 0, 92, 93, 5, 117, 0, 0, 93, 94, 5, 101, 0, 0, 94, 22, 1, 0, 0, 0, 95, 96, 5, 70, 0, 0, 96, 97, 5, 97, 0, 0, 97, 98, 5, 108, 0, 0, 98, 99, 5, 115, 0, 0, 99, 100, 5, 101, 0, 0, 100, 24, 1, 0, 0, 0, 101, 105, 7, 0, 0, 0, 102, 104, 7, 1, 0, 0, 103, 102, 1, 0, 0, 0, 104, 107, 1, 0, 0, 0, 105, 103, 1, 0, 0, 0, 105, 106, 1, 0, 0, 0, 106, 26, 1, 0, 0, 0, 107, 105, 1, 0, 0, 0, 108, 110, 5, 45, 0, 0, 109, 108, 1, 0, 0, 0, 109, 110, 1, 0, 0, 0, 110, 111, 1, 0, 0, 0, 111, 115, 7, 2, 0, 0, 112, 114, 7, 3, 0, 0, 113, 112, 1, 0, 0, 0, 114, 117, 1, 0, 0, 0, 115, 113, 1, 0, 0, 0, 115, 116, 1, 0, 0, 0, 116, 120, 1, 0, 0, 0, 117, 115, 1, 0, 0, 0, 118, 120, 5, 48, 0, 0, 119, 109, 1, 0, 0, 0, 119, 118, 1, 0, 0, 0, 120, 28, 1, 0, 0, 0, 121, 123, 7, 3, 0, 0, 122, 121, 1, 0, 0, 0, 123, 124, 1, 0, 0, 0, 124, 122, 1, 0, 0, 0, 124, 125, 1, 0, 0, 0, 125, 126, 1, 0, 0, 0, 126, 130, 5, 46, 0, 0, 127, 129, 7, 3, 0, 0, 128, 127, 1, 0, 0, 0, 129, 132, 1, 0, 0, 0, 130, 128, 1, 0, 0, 0, 130, 131, 1, 0, 0, 0, 131, 140, 1, 0, 0, 0, 132, 130, 1, 0, 0, 0, 133, 135, 5, 46, 0, 0, 134, 136, 7, 3, 0, 0, 135, 134, 1, 0, 0, 0, 136, 137, 1, 0, 0, 0, 137, 135, 1, 0, 0, 0, 137, 138, 1, 0, 0, 0, 138, 140, 1, 0, 0, 0, 139, 122, 1, 0, 0, 0, 139, 133, 1, 0, 0, 0, 140, 30, 1, 0, 0, 0, 141, 142, 5, 47, 0, 0, 142, 143, 5, 47, 0, 0, 143, 147, 1, 0, 0, 0, 144, 146, 9, 0, 0, 0, 145, 144, 1, 0, 0, 0, 146, 149, 1, 0, 0, 0, 147, 148, 1, 0, 0, 0, 147, 145, 1, 0, 0, 0, 148, 151, 1, 0, 0, 0, 149, 147, 1, 0, 0, 0, 150, 152, 5, 13, 0, 0, 151, 150, 1, 0, 0, 0, 151, 152, 1, 0, 0, 0, 152, 153, 1, 0, 0, 0, 153, 154, 5, 10, 0, 0, 154, 155, 1, 0, 0, 0, 155, 156, 6, 15, 0, 0, 156, 32, 1, 0, 0, 0, 157, 159, 7, 4, 0, 0, 158, 157, 1, 0, 0, 0, 159, 160, 1, 0, 0, 0, 160, 158, 1, 0, 0, 0, 160, 161, 1, 0, 0, 0, 161, 162, 1, 0, 0, 0, 162, 163, 6, 16, 0, 0, 163, 34, 1, 0, 0, 0, 12, 0, 105, 109, 115, 119, 124, 130, 137, 139, 147, 151, 160, 1, 6, 0, 0] \ No newline at end of file +[4, 0, 17, 156, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 5, 12, 96, 8, 12, 10, 12, 12, 12, 99, 9, 12, 1, 13, 3, 13, 102, 8, 13, 1, 13, 1, 13, 5, 13, 106, 8, 13, 10, 13, 12, 13, 109, 9, 13, 1, 13, 3, 13, 112, 8, 13, 1, 14, 4, 14, 115, 8, 14, 11, 14, 12, 14, 116, 1, 14, 1, 14, 5, 14, 121, 8, 14, 10, 14, 12, 14, 124, 9, 14, 1, 14, 1, 14, 4, 14, 128, 8, 14, 11, 14, 12, 14, 129, 3, 14, 132, 8, 14, 1, 15, 1, 15, 1, 15, 1, 15, 5, 15, 138, 8, 15, 10, 15, 12, 15, 141, 9, 15, 1, 15, 3, 15, 144, 8, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 4, 16, 151, 8, 16, 11, 16, 12, 16, 152, 1, 16, 1, 16, 1, 139, 0, 17, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 1, 0, 5, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 1, 0, 49, 57, 1, 0, 48, 57, 3, 0, 9, 10, 12, 13, 32, 32, 166, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 1, 35, 1, 0, 0, 0, 3, 37, 1, 0, 0, 0, 5, 39, 1, 0, 0, 0, 7, 48, 1, 0, 0, 0, 9, 57, 1, 0, 0, 0, 11, 66, 1, 0, 0, 0, 13, 71, 1, 0, 0, 0, 15, 76, 1, 0, 0, 0, 17, 78, 1, 0, 0, 0, 19, 80, 1, 0, 0, 0, 21, 82, 1, 0, 0, 0, 23, 87, 1, 0, 0, 0, 25, 93, 1, 0, 0, 0, 27, 111, 1, 0, 0, 0, 29, 131, 1, 0, 0, 0, 31, 133, 1, 0, 0, 0, 33, 150, 1, 0, 0, 0, 35, 36, 5, 123, 0, 0, 36, 2, 1, 0, 0, 0, 37, 38, 5, 125, 0, 0, 38, 4, 1, 0, 0, 0, 39, 40, 5, 115, 0, 0, 40, 41, 5, 101, 0, 0, 41, 42, 5, 113, 0, 0, 42, 43, 5, 117, 0, 0, 43, 44, 5, 101, 0, 0, 44, 45, 5, 110, 0, 0, 45, 46, 5, 99, 0, 0, 46, 47, 5, 101, 0, 0, 47, 6, 1, 0, 0, 0, 48, 49, 5, 115, 0, 0, 49, 50, 5, 101, 0, 0, 50, 51, 5, 108, 0, 0, 51, 52, 5, 101, 0, 0, 52, 53, 5, 99, 0, 0, 53, 54, 5, 116, 0, 0, 54, 55, 5, 111, 0, 0, 55, 56, 5, 114, 0, 0, 56, 8, 1, 0, 0, 0, 57, 58, 5, 112, 0, 0, 58, 59, 5, 97, 0, 0, 59, 60, 5, 114, 0, 0, 60, 61, 5, 97, 0, 0, 61, 62, 5, 108, 0, 0, 62, 63, 5, 108, 0, 0, 63, 64, 5, 101, 0, 0, 64, 65, 5, 108, 0, 0, 65, 10, 1, 0, 0, 0, 66, 67, 5, 116, 0, 0, 67, 68, 5, 97, 0, 0, 68, 69, 5, 115, 0, 0, 69, 70, 5, 107, 0, 0, 70, 12, 1, 0, 0, 0, 71, 72, 5, 99, 0, 0, 72, 73, 5, 111, 0, 0, 73, 74, 5, 110, 0, 0, 74, 75, 5, 100, 0, 0, 75, 14, 1, 0, 0, 0, 76, 77, 5, 40, 0, 0, 77, 16, 1, 0, 0, 0, 78, 79, 5, 41, 0, 0, 79, 18, 1, 0, 0, 0, 80, 81, 5, 44, 0, 0, 81, 20, 1, 0, 0, 0, 82, 83, 5, 84, 0, 0, 83, 84, 5, 114, 0, 0, 84, 85, 5, 117, 0, 0, 85, 86, 5, 101, 0, 0, 86, 22, 1, 0, 0, 0, 87, 88, 5, 70, 0, 0, 88, 89, 5, 97, 0, 0, 89, 90, 5, 108, 0, 0, 90, 91, 5, 115, 0, 0, 91, 92, 5, 101, 0, 0, 92, 24, 1, 0, 0, 0, 93, 97, 7, 0, 0, 0, 94, 96, 7, 1, 0, 0, 95, 94, 1, 0, 0, 0, 96, 99, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 97, 98, 1, 0, 0, 0, 98, 26, 1, 0, 0, 0, 99, 97, 1, 0, 0, 0, 100, 102, 5, 45, 0, 0, 101, 100, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 107, 7, 2, 0, 0, 104, 106, 7, 3, 0, 0, 105, 104, 1, 0, 0, 0, 106, 109, 1, 0, 0, 0, 107, 105, 1, 0, 0, 0, 107, 108, 1, 0, 0, 0, 108, 112, 1, 0, 0, 0, 109, 107, 1, 0, 0, 0, 110, 112, 5, 48, 0, 0, 111, 101, 1, 0, 0, 0, 111, 110, 1, 0, 0, 0, 112, 28, 1, 0, 0, 0, 113, 115, 7, 3, 0, 0, 114, 113, 1, 0, 0, 0, 115, 116, 1, 0, 0, 0, 116, 114, 1, 0, 0, 0, 116, 117, 1, 0, 0, 0, 117, 118, 1, 0, 0, 0, 118, 122, 5, 46, 0, 0, 119, 121, 7, 3, 0, 0, 120, 119, 1, 0, 0, 0, 121, 124, 1, 0, 0, 0, 122, 120, 1, 0, 0, 0, 122, 123, 1, 0, 0, 0, 123, 132, 1, 0, 0, 0, 124, 122, 1, 0, 0, 0, 125, 127, 5, 46, 0, 0, 126, 128, 7, 3, 0, 0, 127, 126, 1, 0, 0, 0, 128, 129, 1, 0, 0, 0, 129, 127, 1, 0, 0, 0, 129, 130, 1, 0, 0, 0, 130, 132, 1, 0, 0, 0, 131, 114, 1, 0, 0, 0, 131, 125, 1, 0, 0, 0, 132, 30, 1, 0, 0, 0, 133, 134, 5, 47, 0, 0, 134, 135, 5, 47, 0, 0, 135, 139, 1, 0, 0, 0, 136, 138, 9, 0, 0, 0, 137, 136, 1, 0, 0, 0, 138, 141, 1, 0, 0, 0, 139, 140, 1, 0, 0, 0, 139, 137, 1, 0, 0, 0, 140, 143, 1, 0, 0, 0, 141, 139, 1, 0, 0, 0, 142, 144, 5, 13, 0, 0, 143, 142, 1, 0, 0, 0, 143, 144, 1, 0, 0, 0, 144, 145, 1, 0, 0, 0, 145, 146, 5, 10, 0, 0, 146, 147, 1, 0, 0, 0, 147, 148, 6, 15, 0, 0, 148, 32, 1, 0, 0, 0, 149, 151, 7, 4, 0, 0, 150, 149, 1, 0, 0, 0, 151, 152, 1, 0, 0, 0, 152, 150, 1, 0, 0, 0, 152, 153, 1, 0, 0, 0, 153, 154, 1, 0, 0, 0, 154, 155, 6, 16, 0, 0, 155, 34, 1, 0, 0, 0, 12, 0, 97, 101, 107, 111, 116, 122, 129, 131, 139, 143, 152, 1, 6, 0, 0] \ No newline at end of file diff --git a/ptml/ptmlLexer.py b/ptml/ptmlLexer.py index 470be04..813fde6 100644 --- a/ptml/ptmlLexer.py +++ b/ptml/ptmlLexer.py @@ -10,65 +10,62 @@ else: def serializedATN(): return [ - 4,0,17,164,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5, + 4,0,17,156,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5, 2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2, - 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,1,0,1,0,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,3,1,3,1, - 3,1,3,1,3,1,3,1,3,1,3,1,3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1, - 4,1,5,1,5,1,5,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,8,1,8,1,9,1, - 9,1,10,1,10,1,10,1,10,1,10,1,11,1,11,1,11,1,11,1,11,1,11,1,12,1, - 12,5,12,104,8,12,10,12,12,12,107,9,12,1,13,3,13,110,8,13,1,13,1, - 13,5,13,114,8,13,10,13,12,13,117,9,13,1,13,3,13,120,8,13,1,14,4, - 14,123,8,14,11,14,12,14,124,1,14,1,14,5,14,129,8,14,10,14,12,14, - 132,9,14,1,14,1,14,4,14,136,8,14,11,14,12,14,137,3,14,140,8,14,1, - 15,1,15,1,15,1,15,5,15,146,8,15,10,15,12,15,149,9,15,1,15,3,15,152, - 8,15,1,15,1,15,1,15,1,15,1,16,4,16,159,8,16,11,16,12,16,160,1,16, - 1,16,1,147,0,17,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21, - 11,23,12,25,13,27,14,29,15,31,16,33,17,1,0,5,3,0,65,90,95,95,97, - 122,4,0,48,57,65,90,95,95,97,122,1,0,49,57,1,0,48,57,3,0,9,10,12, - 13,32,32,174,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9, - 1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19, - 1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29, - 1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,1,35,1,0,0,0,3,37,1,0,0,0,5,46, - 1,0,0,0,7,55,1,0,0,0,9,64,1,0,0,0,11,74,1,0,0,0,13,79,1,0,0,0,15, - 84,1,0,0,0,17,86,1,0,0,0,19,88,1,0,0,0,21,90,1,0,0,0,23,95,1,0,0, - 0,25,101,1,0,0,0,27,119,1,0,0,0,29,139,1,0,0,0,31,141,1,0,0,0,33, - 158,1,0,0,0,35,36,5,58,0,0,36,2,1,0,0,0,37,38,5,115,0,0,38,39,5, - 101,0,0,39,40,5,113,0,0,40,41,5,117,0,0,41,42,5,101,0,0,42,43,5, - 110,0,0,43,44,5,99,0,0,44,45,5,101,0,0,45,4,1,0,0,0,46,47,5,115, - 0,0,47,48,5,101,0,0,48,49,5,108,0,0,49,50,5,101,0,0,50,51,5,99,0, - 0,51,52,5,116,0,0,52,53,5,111,0,0,53,54,5,114,0,0,54,6,1,0,0,0,55, - 56,5,112,0,0,56,57,5,97,0,0,57,58,5,114,0,0,58,59,5,97,0,0,59,60, - 5,108,0,0,60,61,5,108,0,0,61,62,5,101,0,0,62,63,5,108,0,0,63,8,1, - 0,0,0,64,65,5,100,0,0,65,66,5,101,0,0,66,67,5,99,0,0,67,68,5,111, - 0,0,68,69,5,114,0,0,69,70,5,97,0,0,70,71,5,116,0,0,71,72,5,111,0, - 0,72,73,5,114,0,0,73,10,1,0,0,0,74,75,5,116,0,0,75,76,5,97,0,0,76, - 77,5,115,0,0,77,78,5,107,0,0,78,12,1,0,0,0,79,80,5,99,0,0,80,81, - 5,111,0,0,81,82,5,110,0,0,82,83,5,100,0,0,83,14,1,0,0,0,84,85,5, - 40,0,0,85,16,1,0,0,0,86,87,5,41,0,0,87,18,1,0,0,0,88,89,5,44,0,0, - 89,20,1,0,0,0,90,91,5,84,0,0,91,92,5,114,0,0,92,93,5,117,0,0,93, - 94,5,101,0,0,94,22,1,0,0,0,95,96,5,70,0,0,96,97,5,97,0,0,97,98,5, - 108,0,0,98,99,5,115,0,0,99,100,5,101,0,0,100,24,1,0,0,0,101,105, - 7,0,0,0,102,104,7,1,0,0,103,102,1,0,0,0,104,107,1,0,0,0,105,103, - 1,0,0,0,105,106,1,0,0,0,106,26,1,0,0,0,107,105,1,0,0,0,108,110,5, - 45,0,0,109,108,1,0,0,0,109,110,1,0,0,0,110,111,1,0,0,0,111,115,7, - 2,0,0,112,114,7,3,0,0,113,112,1,0,0,0,114,117,1,0,0,0,115,113,1, - 0,0,0,115,116,1,0,0,0,116,120,1,0,0,0,117,115,1,0,0,0,118,120,5, - 48,0,0,119,109,1,0,0,0,119,118,1,0,0,0,120,28,1,0,0,0,121,123,7, - 3,0,0,122,121,1,0,0,0,123,124,1,0,0,0,124,122,1,0,0,0,124,125,1, - 0,0,0,125,126,1,0,0,0,126,130,5,46,0,0,127,129,7,3,0,0,128,127,1, - 0,0,0,129,132,1,0,0,0,130,128,1,0,0,0,130,131,1,0,0,0,131,140,1, - 0,0,0,132,130,1,0,0,0,133,135,5,46,0,0,134,136,7,3,0,0,135,134,1, - 0,0,0,136,137,1,0,0,0,137,135,1,0,0,0,137,138,1,0,0,0,138,140,1, - 0,0,0,139,122,1,0,0,0,139,133,1,0,0,0,140,30,1,0,0,0,141,142,5,47, - 0,0,142,143,5,47,0,0,143,147,1,0,0,0,144,146,9,0,0,0,145,144,1,0, - 0,0,146,149,1,0,0,0,147,148,1,0,0,0,147,145,1,0,0,0,148,151,1,0, - 0,0,149,147,1,0,0,0,150,152,5,13,0,0,151,150,1,0,0,0,151,152,1,0, - 0,0,152,153,1,0,0,0,153,154,5,10,0,0,154,155,1,0,0,0,155,156,6,15, - 0,0,156,32,1,0,0,0,157,159,7,4,0,0,158,157,1,0,0,0,159,160,1,0,0, - 0,160,158,1,0,0,0,160,161,1,0,0,0,161,162,1,0,0,0,162,163,6,16,0, - 0,163,34,1,0,0,0,12,0,105,109,115,119,124,130,137,139,147,151,160, - 1,6,0,0 + 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,1,0,1,0,1,1,1,1,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,1,2,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1, + 4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,6,1,6,1, + 6,1,6,1,6,1,7,1,7,1,8,1,8,1,9,1,9,1,10,1,10,1,10,1,10,1,10,1,11, + 1,11,1,11,1,11,1,11,1,11,1,12,1,12,5,12,96,8,12,10,12,12,12,99,9, + 12,1,13,3,13,102,8,13,1,13,1,13,5,13,106,8,13,10,13,12,13,109,9, + 13,1,13,3,13,112,8,13,1,14,4,14,115,8,14,11,14,12,14,116,1,14,1, + 14,5,14,121,8,14,10,14,12,14,124,9,14,1,14,1,14,4,14,128,8,14,11, + 14,12,14,129,3,14,132,8,14,1,15,1,15,1,15,1,15,5,15,138,8,15,10, + 15,12,15,141,9,15,1,15,3,15,144,8,15,1,15,1,15,1,15,1,15,1,16,4, + 16,151,8,16,11,16,12,16,152,1,16,1,16,1,139,0,17,1,1,3,2,5,3,7,4, + 9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16, + 33,17,1,0,5,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122, + 1,0,49,57,1,0,48,57,3,0,9,10,12,13,32,32,166,0,1,1,0,0,0,0,3,1,0, + 0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0, + 0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0, + 0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0, + 0,1,35,1,0,0,0,3,37,1,0,0,0,5,39,1,0,0,0,7,48,1,0,0,0,9,57,1,0,0, + 0,11,66,1,0,0,0,13,71,1,0,0,0,15,76,1,0,0,0,17,78,1,0,0,0,19,80, + 1,0,0,0,21,82,1,0,0,0,23,87,1,0,0,0,25,93,1,0,0,0,27,111,1,0,0,0, + 29,131,1,0,0,0,31,133,1,0,0,0,33,150,1,0,0,0,35,36,5,123,0,0,36, + 2,1,0,0,0,37,38,5,125,0,0,38,4,1,0,0,0,39,40,5,115,0,0,40,41,5,101, + 0,0,41,42,5,113,0,0,42,43,5,117,0,0,43,44,5,101,0,0,44,45,5,110, + 0,0,45,46,5,99,0,0,46,47,5,101,0,0,47,6,1,0,0,0,48,49,5,115,0,0, + 49,50,5,101,0,0,50,51,5,108,0,0,51,52,5,101,0,0,52,53,5,99,0,0,53, + 54,5,116,0,0,54,55,5,111,0,0,55,56,5,114,0,0,56,8,1,0,0,0,57,58, + 5,112,0,0,58,59,5,97,0,0,59,60,5,114,0,0,60,61,5,97,0,0,61,62,5, + 108,0,0,62,63,5,108,0,0,63,64,5,101,0,0,64,65,5,108,0,0,65,10,1, + 0,0,0,66,67,5,116,0,0,67,68,5,97,0,0,68,69,5,115,0,0,69,70,5,107, + 0,0,70,12,1,0,0,0,71,72,5,99,0,0,72,73,5,111,0,0,73,74,5,110,0,0, + 74,75,5,100,0,0,75,14,1,0,0,0,76,77,5,40,0,0,77,16,1,0,0,0,78,79, + 5,41,0,0,79,18,1,0,0,0,80,81,5,44,0,0,81,20,1,0,0,0,82,83,5,84,0, + 0,83,84,5,114,0,0,84,85,5,117,0,0,85,86,5,101,0,0,86,22,1,0,0,0, + 87,88,5,70,0,0,88,89,5,97,0,0,89,90,5,108,0,0,90,91,5,115,0,0,91, + 92,5,101,0,0,92,24,1,0,0,0,93,97,7,0,0,0,94,96,7,1,0,0,95,94,1,0, + 0,0,96,99,1,0,0,0,97,95,1,0,0,0,97,98,1,0,0,0,98,26,1,0,0,0,99,97, + 1,0,0,0,100,102,5,45,0,0,101,100,1,0,0,0,101,102,1,0,0,0,102,103, + 1,0,0,0,103,107,7,2,0,0,104,106,7,3,0,0,105,104,1,0,0,0,106,109, + 1,0,0,0,107,105,1,0,0,0,107,108,1,0,0,0,108,112,1,0,0,0,109,107, + 1,0,0,0,110,112,5,48,0,0,111,101,1,0,0,0,111,110,1,0,0,0,112,28, + 1,0,0,0,113,115,7,3,0,0,114,113,1,0,0,0,115,116,1,0,0,0,116,114, + 1,0,0,0,116,117,1,0,0,0,117,118,1,0,0,0,118,122,5,46,0,0,119,121, + 7,3,0,0,120,119,1,0,0,0,121,124,1,0,0,0,122,120,1,0,0,0,122,123, + 1,0,0,0,123,132,1,0,0,0,124,122,1,0,0,0,125,127,5,46,0,0,126,128, + 7,3,0,0,127,126,1,0,0,0,128,129,1,0,0,0,129,127,1,0,0,0,129,130, + 1,0,0,0,130,132,1,0,0,0,131,114,1,0,0,0,131,125,1,0,0,0,132,30,1, + 0,0,0,133,134,5,47,0,0,134,135,5,47,0,0,135,139,1,0,0,0,136,138, + 9,0,0,0,137,136,1,0,0,0,138,141,1,0,0,0,139,140,1,0,0,0,139,137, + 1,0,0,0,140,143,1,0,0,0,141,139,1,0,0,0,142,144,5,13,0,0,143,142, + 1,0,0,0,143,144,1,0,0,0,144,145,1,0,0,0,145,146,5,10,0,0,146,147, + 1,0,0,0,147,148,6,15,0,0,148,32,1,0,0,0,149,151,7,4,0,0,150,149, + 1,0,0,0,151,152,1,0,0,0,152,150,1,0,0,0,152,153,1,0,0,0,153,154, + 1,0,0,0,154,155,6,16,0,0,155,34,1,0,0,0,12,0,97,101,107,111,116, + 122,129,131,139,143,152,1,6,0,0 ] class ptmlLexer(Lexer): @@ -100,8 +97,8 @@ class ptmlLexer(Lexer): modeNames = [ "DEFAULT_MODE" ] literalNames = [ "", - "':'", "'sequence'", "'selector'", "'parallel'", "'decorator'", - "'task'", "'cond'", "'('", "')'", "','", "'True'", "'False'" ] + "'{'", "'}'", "'sequence'", "'selector'", "'parallel'", "'task'", + "'cond'", "'('", "')'", "','", "'True'", "'False'" ] symbolicNames = [ "", "Names", "Integer", "Float", "LINE_COMMENT", "WS" ] diff --git a/ptml/ptmlLexer.tokens b/ptml/ptmlLexer.tokens index 7e8628f..1f7a813 100644 --- a/ptml/ptmlLexer.tokens +++ b/ptml/ptmlLexer.tokens @@ -15,11 +15,11 @@ Integer=14 Float=15 LINE_COMMENT=16 WS=17 -':'=1 -'sequence'=2 -'selector'=3 -'parallel'=4 -'decorator'=5 +'{'=1 +'}'=2 +'sequence'=3 +'selector'=4 +'parallel'=5 'task'=6 'cond'=7 '('=8 diff --git a/ptml/ptmlParser.py b/ptml/ptmlParser.py index 7f81a07..f194969 100644 --- a/ptml/ptmlParser.py +++ b/ptml/ptmlParser.py @@ -10,26 +10,26 @@ else: def serializedATN(): return [ - 4,1,17,61,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,1,0,4, + 4,1,17,62,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,1,0,4, 0,14,8,0,11,0,12,0,15,1,0,1,0,1,1,1,1,1,1,1,1,4,1,24,8,1,11,1,12, - 1,25,1,2,1,2,1,2,1,2,1,2,3,2,33,8,2,1,3,1,3,1,3,1,3,3,3,39,8,3,1, - 3,1,3,1,4,1,4,1,4,3,4,46,8,4,1,4,1,4,1,4,1,4,3,4,52,8,4,5,4,54,8, - 4,10,4,12,4,57,9,4,1,5,1,5,1,5,0,0,6,0,2,4,6,8,10,0,2,1,0,6,7,1, - 0,11,12,66,0,13,1,0,0,0,2,19,1,0,0,0,4,32,1,0,0,0,6,34,1,0,0,0,8, - 45,1,0,0,0,10,58,1,0,0,0,12,14,3,2,1,0,13,12,1,0,0,0,14,15,1,0,0, - 0,15,13,1,0,0,0,15,16,1,0,0,0,16,17,1,0,0,0,17,18,5,0,0,1,18,1,1, - 0,0,0,19,20,3,4,2,0,20,23,5,1,0,0,21,24,3,6,3,0,22,24,3,2,1,0,23, - 21,1,0,0,0,23,22,1,0,0,0,24,25,1,0,0,0,25,23,1,0,0,0,25,26,1,0,0, - 0,26,3,1,0,0,0,27,33,5,2,0,0,28,33,5,3,0,0,29,30,5,4,0,0,30,33,5, - 14,0,0,31,33,5,5,0,0,32,27,1,0,0,0,32,28,1,0,0,0,32,29,1,0,0,0,32, - 31,1,0,0,0,33,5,1,0,0,0,34,35,7,0,0,0,35,36,5,13,0,0,36,38,5,8,0, - 0,37,39,3,8,4,0,38,37,1,0,0,0,38,39,1,0,0,0,39,40,1,0,0,0,40,41, - 5,9,0,0,41,7,1,0,0,0,42,46,5,14,0,0,43,46,5,15,0,0,44,46,3,10,5, - 0,45,42,1,0,0,0,45,43,1,0,0,0,45,44,1,0,0,0,46,55,1,0,0,0,47,51, - 5,10,0,0,48,52,5,14,0,0,49,52,5,15,0,0,50,52,3,10,5,0,51,48,1,0, - 0,0,51,49,1,0,0,0,51,50,1,0,0,0,52,54,1,0,0,0,53,47,1,0,0,0,54,57, - 1,0,0,0,55,53,1,0,0,0,55,56,1,0,0,0,56,9,1,0,0,0,57,55,1,0,0,0,58, - 59,7,1,0,0,59,11,1,0,0,0,8,15,23,25,32,38,45,51,55 + 1,25,1,1,1,1,1,2,1,2,1,2,1,2,3,2,34,8,2,1,3,1,3,1,3,1,3,3,3,40,8, + 3,1,3,1,3,1,4,1,4,1,4,3,4,47,8,4,1,4,1,4,1,4,1,4,3,4,53,8,4,5,4, + 55,8,4,10,4,12,4,58,9,4,1,5,1,5,1,5,0,0,6,0,2,4,6,8,10,0,2,1,0,6, + 7,1,0,11,12,66,0,13,1,0,0,0,2,19,1,0,0,0,4,33,1,0,0,0,6,35,1,0,0, + 0,8,46,1,0,0,0,10,59,1,0,0,0,12,14,3,2,1,0,13,12,1,0,0,0,14,15,1, + 0,0,0,15,13,1,0,0,0,15,16,1,0,0,0,16,17,1,0,0,0,17,18,5,0,0,1,18, + 1,1,0,0,0,19,20,3,4,2,0,20,23,5,1,0,0,21,24,3,6,3,0,22,24,3,2,1, + 0,23,21,1,0,0,0,23,22,1,0,0,0,24,25,1,0,0,0,25,23,1,0,0,0,25,26, + 1,0,0,0,26,27,1,0,0,0,27,28,5,2,0,0,28,3,1,0,0,0,29,34,5,3,0,0,30, + 34,5,4,0,0,31,32,5,5,0,0,32,34,5,14,0,0,33,29,1,0,0,0,33,30,1,0, + 0,0,33,31,1,0,0,0,34,5,1,0,0,0,35,36,7,0,0,0,36,37,5,13,0,0,37,39, + 5,8,0,0,38,40,3,8,4,0,39,38,1,0,0,0,39,40,1,0,0,0,40,41,1,0,0,0, + 41,42,5,9,0,0,42,7,1,0,0,0,43,47,5,14,0,0,44,47,5,15,0,0,45,47,3, + 10,5,0,46,43,1,0,0,0,46,44,1,0,0,0,46,45,1,0,0,0,47,56,1,0,0,0,48, + 52,5,10,0,0,49,53,5,14,0,0,50,53,5,15,0,0,51,53,3,10,5,0,52,49,1, + 0,0,0,52,50,1,0,0,0,52,51,1,0,0,0,53,55,1,0,0,0,54,48,1,0,0,0,55, + 58,1,0,0,0,56,54,1,0,0,0,56,57,1,0,0,0,57,9,1,0,0,0,58,56,1,0,0, + 0,59,60,7,1,0,0,60,11,1,0,0,0,8,15,23,25,33,39,46,52,56 ] class ptmlParser ( Parser ): @@ -42,8 +42,8 @@ class ptmlParser ( Parser ): sharedContextCache = PredictionContextCache() - literalNames = [ "", "':'", "'sequence'", "'selector'", "'parallel'", - "'decorator'", "'task'", "'cond'", "'('", "')'", "','", + literalNames = [ "", "'{'", "'}'", "'sequence'", "'selector'", + "'parallel'", "'task'", "'cond'", "'('", "')'", "','", "'True'", "'False'" ] symbolicNames = [ "", "", "", "", @@ -137,7 +137,7 @@ class ptmlParser ( Parser ): self.state = 15 self._errHandler.sync(self) _la = self._input.LA(1) - if not ((((_la) & ~0x3f) == 0 and ((1 << _la) & 60) != 0)): + if not ((((_la) & ~0x3f) == 0 and ((1 << _la) & 56) != 0)): break self.state = 17 @@ -194,6 +194,7 @@ class ptmlParser ( Parser ): localctx = ptmlParser.TreeContext(self, self._ctx, self.state) self.enterRule(localctx, 2, self.RULE_tree) + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 19 @@ -202,30 +203,30 @@ class ptmlParser ( Parser ): self.match(ptmlParser.T__0) self.state = 23 self._errHandler.sync(self) - _alt = 1 - while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: - if _alt == 1: - self.state = 23 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [6, 7]: - self.state = 21 - self.action_sign() - pass - elif token in [2, 3, 4, 5]: - self.state = 22 - self.tree() - pass - else: - raise NoViableAltException(self) - - + _la = self._input.LA(1) + while True: + self.state = 23 + self._errHandler.sync(self) + token = self._input.LA(1) + if token in [6, 7]: + self.state = 21 + self.action_sign() + pass + elif token in [3, 4, 5]: + self.state = 22 + self.tree() + pass else: raise NoViableAltException(self) + self.state = 25 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,2,self._ctx) + _la = self._input.LA(1) + if not ((((_la) & ~0x3f) == 0 and ((1 << _la) & 248) != 0)): + break + self.state = 27 + self.match(ptmlParser.T__1) except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -264,30 +265,25 @@ class ptmlParser ( Parser ): localctx = ptmlParser.Internal_nodeContext(self, self._ctx, self.state) self.enterRule(localctx, 4, self.RULE_internal_node) try: - self.state = 32 + self.state = 33 self._errHandler.sync(self) token = self._input.LA(1) - if token in [2]: + if token in [3]: self.enterOuterAlt(localctx, 1) - self.state = 27 - self.match(ptmlParser.T__1) - pass - elif token in [3]: - self.enterOuterAlt(localctx, 2) - self.state = 28 + self.state = 29 self.match(ptmlParser.T__2) pass elif token in [4]: - self.enterOuterAlt(localctx, 3) - self.state = 29 - self.match(ptmlParser.T__3) + self.enterOuterAlt(localctx, 2) self.state = 30 - self.match(ptmlParser.Integer) + self.match(ptmlParser.T__3) pass elif token in [5]: - self.enterOuterAlt(localctx, 4) + self.enterOuterAlt(localctx, 3) self.state = 31 self.match(ptmlParser.T__4) + self.state = 32 + self.match(ptmlParser.Integer) pass else: raise NoViableAltException(self) @@ -336,26 +332,26 @@ class ptmlParser ( Parser ): self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 34 + self.state = 35 _la = self._input.LA(1) if not(_la==6 or _la==7): self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 35 - self.match(ptmlParser.Names) self.state = 36 + self.match(ptmlParser.Names) + self.state = 37 self.match(ptmlParser.T__7) - self.state = 38 + self.state = 39 self._errHandler.sync(self) _la = self._input.LA(1) if (((_la) & ~0x3f) == 0 and ((1 << _la) & 55296) != 0): - self.state = 37 + self.state = 38 self.action_parm() - self.state = 40 + self.state = 41 self.match(ptmlParser.T__8) except RecognitionException as re: localctx.exception = re @@ -413,49 +409,49 @@ class ptmlParser ( Parser ): self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 45 + self.state = 46 self._errHandler.sync(self) token = self._input.LA(1) if token in [14]: - self.state = 42 + self.state = 43 self.match(ptmlParser.Integer) pass elif token in [15]: - self.state = 43 + self.state = 44 self.match(ptmlParser.Float) pass elif token in [11, 12]: - self.state = 44 + self.state = 45 self.boolean() pass else: raise NoViableAltException(self) - self.state = 55 + self.state = 56 self._errHandler.sync(self) _la = self._input.LA(1) while _la==10: - self.state = 47 + self.state = 48 self.match(ptmlParser.T__9) - self.state = 51 + self.state = 52 self._errHandler.sync(self) token = self._input.LA(1) if token in [14]: - self.state = 48 + self.state = 49 self.match(ptmlParser.Integer) pass elif token in [15]: - self.state = 49 + self.state = 50 self.match(ptmlParser.Float) pass elif token in [11, 12]: - self.state = 50 + self.state = 51 self.boolean() pass else: raise NoViableAltException(self) - self.state = 57 + self.state = 58 self._errHandler.sync(self) _la = self._input.LA(1) @@ -497,7 +493,7 @@ class ptmlParser ( Parser ): self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 58 + self.state = 59 _la = self._input.LA(1) if not(_la==11 or _la==12): self._errHandler.recoverInline(self) diff --git a/ptml/ptmlTranslateAPI.py b/ptml/ptmlTranslateAPI.py deleted file mode 100644 index 41e3543..0000000 --- a/ptml/ptmlTranslateAPI.py +++ /dev/null @@ -1,123 +0,0 @@ -import os -import typing -import shortuuid - -short_uuid = lambda : shortuuid.ShortUUID().random(length=8) - -class PyTreesAPI(): - """ - - """ - - def __init__(self) -> None: - self.pystr = '' - self.prepare() - - - def prepare(self) -> None: - # import libraries - self.pystr += 'import py_trees as tree\n' - - self.pystr += '\n' * 2 - - def write_to_file(self, dir: str = './', filename: str = 'auto_generate.py') -> None: - """_summary_ - - Args: - dir (str, optional): _description_. Defaults to './'. - filename (str, optional): _description_. Defaults to 'auto_generate.py'. - - Raises: - FileNotFoundError: _description_ - """ - # exceptions handling - filepath = os.path.join(dir, filename) - if not os.path.exists(dir): - raise FileNotFoundError( - '' - ) - # if os.path.exists(filepath): - # raise FileExistsError( - # '' - # ) - - with open(filepath, 'w') as file: - file.write(self.pystr) - - def run(self) -> None: - """_summary_ - """ - self.write_to_file() - out = os.popen('python ./auto_generate.py') - print(out.read()) - - - def newTree(self) -> None: - """_summary_ - """ - - def newSequenceNode(self) -> str: - """_summary_ - - Returns: - str: _description_ - """ - tag = 'sequence_' + short_uuid() - return tag - - def newSelectorNode(self) -> str: - """_summary_ - - Returns: - str: _description_ - """ - tag = 'selector_' + short_uuid() - return tag - - def newParallelNode(self, threshold:int) -> str: - """_summary_ - - Args: - threshold (int): _description_ - - Returns: - str: _description_ - """ - tag = 'parallel_' + short_uuid() - return tag - - def newDecoratorNode(self) -> str: - """_summary_ - - Returns: - str: _description_ - """ - tag = 'decorator_' + short_uuid() - return tag - - def newBehaviourNode(self, - name: str, - args: typing.Optional[typing.List[str]] = [], - isCond: bool = False - ) -> str: - """_summary_ - - Args: - name (str): _description_ - args (typing.Optional[typing.List[str]], optional): _description_. Defaults to []. - isCond (bool, optional): _description_. Defaults to False. - - Returns: - str: _description_ - """ - tag = 'behavior_' + short_uuid() - return tag - - def connect_to_parent(self, uuid_child:str, uuid_parent:str) -> None: - """_summary_ - - Args: - uuid_child (str): _description_ - uuid_parent (str): _description_ - """ - return \ No newline at end of file diff --git a/ptml/ptmlTranslator.py b/ptml/ptmlTranslator.py index a004cdf..d2702c2 100644 --- a/ptml/ptmlTranslator.py +++ b/ptml/ptmlTranslator.py @@ -1,14 +1,11 @@ -import os -import sys -import uuid - -project_path = "/home/wu/RoboWaiter/ptml" -sys.path.append(project_path) +import shortuuid +import py_trees as ptree from antlr4 import * from ptmlListener import ptmlListener from ptmlParser import ptmlParser -from ptml.ptmlTranslateAPI import PyTreesAPI + +short_uuid = lambda : shortuuid.ShortUUID().random(length=8) class ptmlTranslator(ptmlListener): """Translate the ptml language to BT. @@ -19,9 +16,8 @@ class ptmlTranslator(ptmlListener): def __init__(self) -> None: super().__init__() - self.stack = [] - self.api = PyTreesAPI() - + self.bt_root = None + self.stack = [] # Enter a parse tree produced by ptmlParser#root. def enterRoot(self, ctx:ptmlParser.RootContext): @@ -34,32 +30,42 @@ class ptmlTranslator(ptmlListener): # Enter a parse tree produced by ptmlParser#tree. def enterTree(self, ctx:ptmlParser.TreeContext): - pass + type = str(ctx.internal_node().children[0]) + + match type: + case 'sequence': + tag = 'sequence_' + short_uuid() + node = ptree.composites.Sequence(name=tag, memory=False) + case 'selector': + tag = 'selector_' + short_uuid() + node = ptree.composites.Selector(name=tag, memory=False) + case 'parallel': + tag = 'parallel_' + short_uuid() + # threshold = int(ctx.children[1]) + # default policy, success on all + node = ptree.composites.Parallel( + name=tag, + policy=ptree.common.ParallelPolicy.SuccessOnAll + ) + case _: + raise TypeError( + 'Unknown Composite Type: {}'.format(type) + ) + + self.stack.append(node) # Exit a parse tree produced by ptmlParser#tree. def exitTree(self, ctx:ptmlParser.TreeContext): - pass + if len(self.stack) >= 2: + child = self.stack.pop() + self.stack[-1].add_child(child) + else: + self.bt_root = self.stack[0] # Enter a parse tree produced by ptmlParser#internal_node. def enterInternal_node(self, ctx:ptmlParser.Internal_nodeContext): - type = str(ctx.children[0]) - - 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) - + pass # Exit a parse tree produced by ptmlParser#internal_node. def exitInternal_node(self, ctx:ptmlParser.Internal_nodeContext): @@ -69,25 +75,35 @@ class ptmlTranslator(ptmlListener): # Enter a parse tree produced by ptmlParser#action_sign. def enterAction_sign(self, ctx:ptmlParser.Action_signContext): # cond / task - type = str(ctx.children[0]) + node_type = str(ctx.children[0]) name = str(ctx.Names()) # if have params + args = [] if len(ctx.children) > 4: - args = ctx.action_parm() - print(args.Float()) - else: - args = [] + params = ctx.action_parm() + + for i in params.children: + if isinstance(i, ptmlParser.BooleanContext): + args.append(str(i.children[0])) + else: + args.append(str(i)) + + args = ''.join(args) + # dynamic import + behaviour_lib_config = './behaviour_lib' + import sys + sys.path.append(behaviour_lib_config) + exec('from {} import {}'.format(name, name)) # - if type == 'cond': - behav_tag = self.api.newBehaviourNode(name, args, isCond=True) - else: - behav_tag = self.api.newBehaviourNode(name, args, isCond=False) + tag = 'cond_' + short_uuid() if node_type == 'cond' else 'task_' + short_uuid() + node = None + node = eval('{}(\'{}\', {})'.format(name, tag, args)) + # connect - parent_tag = self.stack[-1] - self.api.connect_to_parent(behav_tag, parent_tag) - + self.stack[-1].add_child(node) + # print(self.stack) # Exit a parse tree produced by ptmlParser#action_sign. def exitAction_sign(self, ctx:ptmlParser.Action_signContext): diff --git a/ptml/ptml_test.py b/ptml/ptml_test.py index a5c1ee3..6bfb457 100644 --- a/ptml/ptml_test.py +++ b/ptml/ptml_test.py @@ -1,25 +1,18 @@ import os -import sys -project_path = "/home/wu/RoboWaiter/ptml" -sys.path.append(project_path) +import py_trees as ptree -from antlr4 import * -from ptmlTranslator import ptmlTranslator -from ptmlParser import ptmlParser as Parser -from ptmlLexer import ptmlLexer as Lexer +from ptmlCompiler import load if __name__ == '__main__': + + project_path = "/home/wu/RoboWaiter/ptml" - text_path = os.path.join(project_path, 'CoffeeDelivery.ptml') - input_stream = FileStream(text_path, encoding='utf-8') - - # testing lexer & parser - lexer = Lexer(input_stream) - stream = CommonTokenStream(lexer) - parser = Parser(stream) - tree = parser.root() - - walker = ParseTreeWalker() - ptml = ptmlTranslator() # listener mode - walker.walk(ptml, tree) \ No newline at end of file + ptml_path = os.path.join(project_path, 'CoffeeDelivery.ptml') + behavior_lib_path = os.path.join(project_path, 'behaviour_lib') + # load + bt = load(ptml_path, behavior_lib_path) + # ptree.display.render_dot_tree(bt) + # build and tick + bt = ptree.trees.BehaviourTree(bt) + # todo: tick this bt diff --git a/ptml/sequence_oufbg8fg.dot b/ptml/sequence_oufbg8fg.dot new file mode 100644 index 0000000..79e4ba9 --- /dev/null +++ b/ptml/sequence_oufbg8fg.dot @@ -0,0 +1,45 @@ +digraph pastafarianism { +ordering=out; +graph [fontname="times-roman"]; +node [fontname="times-roman"]; +edge [fontname="times-roman"]; +sequence_oUFBg8fG [fillcolor=orange, fontcolor=black, fontsize=9, label=sequence_oUFBg8fG, shape=box, style=filled]; +selector_mPAUGPy3 [fillcolor=cyan, fontcolor=black, fontsize=9, label=selector_mPAUGPy3, shape=octagon, style=filled]; +sequence_oUFBg8fG -> selector_mPAUGPy3; +cond_G7w6nx8B [fillcolor=gray, fontcolor=black, fontsize=9, label=cond_G7w6nx8B, shape=ellipse, style=filled]; +selector_mPAUGPy3 -> cond_G7w6nx8B; +task_XjF4V8bW [fillcolor=gray, fontcolor=black, fontsize=9, label=task_XjF4V8bW, shape=ellipse, style=filled]; +selector_mPAUGPy3 -> task_XjF4V8bW; +sequence_n3nzZvgz [fillcolor=orange, fontcolor=black, fontsize=9, label=sequence_n3nzZvgz, shape=box, style=filled]; +selector_mPAUGPy3 -> sequence_n3nzZvgz; +cond_KCt2aubU [fillcolor=gray, fontcolor=black, fontsize=9, label=cond_KCt2aubU, shape=ellipse, style=filled]; +sequence_n3nzZvgz -> cond_KCt2aubU; +task_a8inFHcZ [fillcolor=gray, fontcolor=black, fontsize=9, label=task_a8inFHcZ, shape=ellipse, style=filled]; +sequence_n3nzZvgz -> task_a8inFHcZ; +task_YF2aiEPZ [fillcolor=gray, fontcolor=black, fontsize=9, label=task_YF2aiEPZ, shape=ellipse, style=filled]; +sequence_n3nzZvgz -> task_YF2aiEPZ; +parallel_WEe6n4ym [fillcolor=gold, fontcolor=black, fontsize=9, label="parallel_WEe6n4ym\ntype", shape=parallelogram, style=filled]; +sequence_n3nzZvgz -> parallel_WEe6n4ym; +cond_mRQoZb2w [fillcolor=gray, fontcolor=black, fontsize=9, label=cond_mRQoZb2w, shape=ellipse, style=filled]; +parallel_WEe6n4ym -> cond_mRQoZb2w; +task_MW4BQ2XF [fillcolor=gray, fontcolor=black, fontsize=9, label=task_MW4BQ2XF, shape=ellipse, style=filled]; +parallel_WEe6n4ym -> task_MW4BQ2XF; +selector_tU6G7YK6 [fillcolor=cyan, fontcolor=black, fontsize=9, label=selector_tU6G7YK6, shape=octagon, style=filled]; +sequence_oUFBg8fG -> selector_tU6G7YK6; +cond_UMTzm9kK [fillcolor=gray, fontcolor=black, fontsize=9, label=cond_UMTzm9kK, shape=ellipse, style=filled]; +selector_tU6G7YK6 -> cond_UMTzm9kK; +task_fnpwP2Lu [fillcolor=gray, fontcolor=black, fontsize=9, label=task_fnpwP2Lu, shape=ellipse, style=filled]; +selector_tU6G7YK6 -> task_fnpwP2Lu; +selector_qm8Zexyr [fillcolor=cyan, fontcolor=black, fontsize=9, label=selector_qm8Zexyr, shape=octagon, style=filled]; +sequence_oUFBg8fG -> selector_qm8Zexyr; +cond_g2umcjH4 [fillcolor=gray, fontcolor=black, fontsize=9, label=cond_g2umcjH4, shape=ellipse, style=filled]; +selector_qm8Zexyr -> cond_g2umcjH4; +task_H5nwyj3V [fillcolor=gray, fontcolor=black, fontsize=9, label=task_H5nwyj3V, shape=ellipse, style=filled]; +selector_qm8Zexyr -> task_H5nwyj3V; +selector_9SJMhckE [fillcolor=cyan, fontcolor=black, fontsize=9, label=selector_9SJMhckE, shape=octagon, style=filled]; +sequence_oUFBg8fG -> selector_9SJMhckE; +cond_D8fqA35b [fillcolor=gray, fontcolor=black, fontsize=9, label=cond_D8fqA35b, shape=ellipse, style=filled]; +selector_9SJMhckE -> cond_D8fqA35b; +task_EikNgjy4 [fillcolor=gray, fontcolor=black, fontsize=9, label=task_EikNgjy4, shape=ellipse, style=filled]; +selector_9SJMhckE -> task_EikNgjy4; +}