From dc0c94c0f6ed5f9580511f7cb461f4b00f768dc2 Mon Sep 17 00:00:00 2001 From: Marketa Opichalova <514349@mail.muni.cz> Date: Wed, 20 Mar 2024 13:02:56 +0100 Subject: [PATCH 1/3] implement only unique name atomics in struct --- eBCSgen/Parsing/ParseBCSL.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/eBCSgen/Parsing/ParseBCSL.py b/eBCSgen/Parsing/ParseBCSL.py index 1fc448f..84a4602 100644 --- a/eBCSgen/Parsing/ParseBCSL.py +++ b/eBCSgen/Parsing/ParseBCSL.py @@ -544,11 +544,19 @@ def atomic(self, matches): def structure(self, matches): name = str(matches[0].children[0]) - if len(matches) > 1: - composition = set(matches[1].children) - return StructureAgent(name, composition) - else: + if len(matches) <= 1: return StructureAgent(name, set()) + atomic_names = set() + composition = set() + for atomic in matches[1].children: + if atomic.name in atomic_names: + raise ComplexParsingError( + f"Duplicate atomic agent in structure: {atomic.name}", matches + ) + atomic_names.add(atomic.name) + composition.add(atomic) + + return StructureAgent(name, composition) def rate_complex(self, matches): sequence = [] From be9148235648ffb2d5e42aaa796734880cd02175 Mon Sep 17 00:00:00 2001 From: Marketa Opichalova <514349@mail.muni.cz> Date: Thu, 21 Mar 2024 13:10:08 +0100 Subject: [PATCH 2/3] test correction - non-unique atomics --- Testing/objects_testing.py | 2 +- Testing/parsing/test_complex.py | 4 ++-- Testing/parsing/test_side.py | 10 ++++++++-- Testing/parsing/test_structure.py | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Testing/objects_testing.py b/Testing/objects_testing.py index 71742b5..a324d26 100644 --- a/Testing/objects_testing.py +++ b/Testing/objects_testing.py @@ -58,7 +58,7 @@ # structure s1 = StructureAgent("B", {a1}) s2 = StructureAgent("D", set()) -s3 = StructureAgent("K", {a1, a3, a5}) +s3 = StructureAgent("K", {a1, a3, a11}) s4 = StructureAgent("B", {a4}) s5 = StructureAgent("D", {a5, a6}) s6 = StructureAgent("K", set()) diff --git a/Testing/parsing/test_complex.py b/Testing/parsing/test_complex.py index 77d5d35..c3c5326 100644 --- a/Testing/parsing/test_complex.py +++ b/Testing/parsing/test_complex.py @@ -6,12 +6,12 @@ def test_parser(): assert ret.success assert ret.data.children[0] == objects.c1 - ret = objects.rate_complex_parser.parse("B(T{s}).D().K(T{s},S{s},S{_})::cell") + ret = objects.rate_complex_parser.parse("B(T{s}).D().K(T{s},S{s},U{a})::cell") assert ret.success assert ret.data.children[0] == objects.c2 ret = objects.rate_complex_parser.parse( - "B(T{s}).K(T{s}, S{s}, S{_}).D(S{_},T{p})::cyt" + "B(T{s}).K(T{s}, S{s}, U{a}).D(S{_},T{p})::cyt" ) assert ret.success assert ret.data.children[0] == objects.c3 diff --git a/Testing/parsing/test_side.py b/Testing/parsing/test_side.py index 6034958..908aa9b 100644 --- a/Testing/parsing/test_side.py +++ b/Testing/parsing/test_side.py @@ -13,13 +13,13 @@ def test_parser(): assert ret.data.to_side() == objects.side2 ret = objects.side_parser.parse( - "B(T{s})::cell + B(T{s}).D().K(T{s},S{s},S{_})::cell + B(T{s}).D().K(T{s},S{s},S{_})::cell" + "B(T{s})::cell + B(T{s}).D().K(T{s},S{s},U{a})::cell + B(T{s}).D().K(T{s},S{s},U{a})::cell" ) assert ret.success assert ret.data.to_side() == objects.side3 ret = objects.side_parser.parse( - "B(T{s})::cell + 2 B(T{s}).D().K(T{s},S{s},S{_})::cell" + "B(T{s})::cell + 2 B(T{s}).D().K(T{s},S{s},U{a})::cell" ) assert ret.success assert ret.data.to_side() == objects.side3 @@ -48,3 +48,9 @@ def test_parser(): ret = objects.side_parser.parse("B(T{s}") assert not ret.success + + # not unique atomics in structure + ret = objects.side_parser.parse( + "B(T{s})::cell + B(T{s}).D().K(T{s},S{s},S{_})::cell + B(T{s}).D().K(T{s},S{s},S{_})::cell" + ) + assert not ret.success diff --git a/Testing/parsing/test_structure.py b/Testing/parsing/test_structure.py index bed18af..4494f56 100644 --- a/Testing/parsing/test_structure.py +++ b/Testing/parsing/test_structure.py @@ -4,7 +4,7 @@ def test_parser(): assert objects.structure_parser.parse("B(T{s})").data == objects.s1 assert objects.structure_parser.parse("D()").data == objects.s2 - assert objects.structure_parser.parse("K(T{s}, S{s}, S{_})").data == objects.s3 + assert objects.structure_parser.parse("K(T{s}, S{s}, U{a})").data == objects.s3 assert objects.structure_parser.parse("B(T{_})").data == objects.s4 assert objects.structure_parser.parse("D(S{_},T{p})").data == objects.s5 assert objects.structure_parser.parse("K()").data == objects.s6 From 49b36b0c3d605c4fb00fe2ae70b8f55ed4289aa7 Mon Sep 17 00:00:00 2001 From: Marketa Opichalova <514349@mail.muni.cz> Date: Thu, 21 Mar 2024 15:25:05 +0100 Subject: [PATCH 3/3] test extended - (non)unique atomics in struct --- Testing/parsing/test_complex.py | 9 +++++++++ Testing/parsing/test_structure.py | 3 +++ 2 files changed, 12 insertions(+) diff --git a/Testing/parsing/test_complex.py b/Testing/parsing/test_complex.py index c3c5326..e16dfb3 100644 --- a/Testing/parsing/test_complex.py +++ b/Testing/parsing/test_complex.py @@ -58,3 +58,12 @@ def test_parser(): ret = objects.rate_complex_parser.parse("B(T{s})::") assert not ret.success + + ret = objects.rate_complex_parser.parse("B(T{s}, T{_})::cell") + assert not ret.success + + ret = objects.rate_complex_parser.parse("B(T{s}, T{s})::cell") + assert not ret.success + + ret = objects.rate_complex_parser.parse("B(T{s}, T{a})::cell") + assert not ret.success diff --git a/Testing/parsing/test_structure.py b/Testing/parsing/test_structure.py index 4494f56..a7fbfd4 100644 --- a/Testing/parsing/test_structure.py +++ b/Testing/parsing/test_structure.py @@ -18,3 +18,6 @@ def test_parser(): assert not objects.structure_parser.parse("[B(T{s})]").success assert not objects.structure_parser.parse("").success assert not objects.structure_parser.parse("B({s})").success + assert not objects.structure_parser.parse("B(S{s}, S{a})").success + assert not objects.structure_parser.parse("B(S{a}, S{a})").success + assert not objects.structure_parser.parse("B(S{_}, S{a})").success