From 42d7144453a4fe09c77b44cee0870317036a6bae Mon Sep 17 00:00:00 2001 From: marsninja Date: Fri, 23 Feb 2024 21:58:24 -0500 Subject: [PATCH] feat: Basic type style filter comprs in --- examples/reference/connect_expressions.py | 7 ++----- examples/reference/data_spatial_calls.py | 8 ++------ examples/reference/data_spatial_references.py | 4 +--- .../reference/data_spatial_typed_context_blocks.py | 8 ++------ jaclang/compiler/parser.py | 2 ++ jaclang/plugin/default.py | 11 ++--------- jaclang/plugin/feature.py | 2 -- jaclang/plugin/spec.py | 1 - 8 files changed, 11 insertions(+), 32 deletions(-) diff --git a/examples/reference/connect_expressions.py b/examples/reference/connect_expressions.py index e36442389..63593756b 100644 --- a/examples/reference/connect_expressions.py +++ b/examples/reference/connect_expressions.py @@ -40,15 +40,12 @@ def travel(self, here: Jac.RootType | node_a) -> None: here, None, Jac.EdgeDir.OUT, - filter_type=MyEdge, - filter_func=lambda x: [i for i in x if i.val <= 6], + filter_func=lambda x: [i for i in x if isinstance(i, MyEdge) if i.val <= 6], ): print(i.value) if Jac.visit_node( self, - Jac.edge_ref( - here, None, Jac.EdgeDir.OUT, filter_type=None, filter_func=None - ), + Jac.edge_ref(here, None, Jac.EdgeDir.OUT, filter_func=None), ): pass diff --git a/examples/reference/data_spatial_calls.py b/examples/reference/data_spatial_calls.py index 71b4fcda0..f06137ed7 100644 --- a/examples/reference/data_spatial_calls.py +++ b/examples/reference/data_spatial_calls.py @@ -17,9 +17,7 @@ def func2(self, here: Jac.RootType) -> None: i += 1 if Jac.visit_node( self, - Jac.edge_ref( - here, None, Jac.EdgeDir.OUT, filter_type=None, filter_func=None - ), + Jac.edge_ref(here, None, Jac.EdgeDir.OUT, filter_func=None), ): pass @@ -33,9 +31,7 @@ def func_1(self, here: Creator) -> None: print("visiting ", self) if Jac.visit_node( here, - Jac.edge_ref( - self, None, Jac.EdgeDir.OUT, filter_type=None, filter_func=None - ), + Jac.edge_ref(self, None, Jac.EdgeDir.OUT, filter_func=None), ): pass diff --git a/examples/reference/data_spatial_references.py b/examples/reference/data_spatial_references.py index e60da1e46..b7f105e5b 100644 --- a/examples/reference/data_spatial_references.py +++ b/examples/reference/data_spatial_references.py @@ -25,9 +25,7 @@ def create(self, here: Jac.RootType) -> None: ) if Jac.visit_node( self, - Jac.edge_ref( - here, None, Jac.EdgeDir.OUT, filter_type=None, filter_func=None - ), + Jac.edge_ref(here, None, Jac.EdgeDir.OUT, filter_func=None), ): pass diff --git a/examples/reference/data_spatial_typed_context_blocks.py b/examples/reference/data_spatial_typed_context_blocks.py index ad8983a22..591d1c017 100644 --- a/examples/reference/data_spatial_typed_context_blocks.py +++ b/examples/reference/data_spatial_typed_context_blocks.py @@ -17,9 +17,7 @@ def produce(self, here: Jac.RootType) -> None: i += 1 if Jac.visit_node( self, - Jac.edge_ref( - here, None, Jac.EdgeDir.OUT, filter_type=None, filter_func=None - ), + Jac.edge_ref(here, None, Jac.EdgeDir.OUT, filter_func=None), ): pass @@ -33,9 +31,7 @@ def make(self, here: Producer) -> None: print(f"Hi, I am {self} returning a String") if Jac.visit_node( here, - Jac.edge_ref( - self, None, Jac.EdgeDir.OUT, filter_type=None, filter_func=None - ), + Jac.edge_ref(self, None, Jac.EdgeDir.OUT, filter_func=None), ): pass diff --git a/jaclang/compiler/parser.py b/jaclang/compiler/parser.py index 4da888e38..9c499f6ce 100644 --- a/jaclang/compiler/parser.py +++ b/jaclang/compiler/parser.py @@ -3294,6 +3294,8 @@ def filter_compr(self, kid: list[ast.AstNode]) -> ast.FilterCompr: if isinstance(kid[2], ast.SubNodeList): return self.nu(ast.FilterCompr(compares=kid[2], f_type=None, kid=kid)) elif isinstance(kid[3], ast.FilterCompr): + kid[3].add_kids_left(kid[:3]) + kid[3].add_kids_right(kid[4:]) return self.nu(kid[3]) else: raise self.ice() diff --git a/jaclang/plugin/default.py b/jaclang/plugin/default.py index 71af130be..a29e88ebc 100644 --- a/jaclang/plugin/default.py +++ b/jaclang/plugin/default.py @@ -316,7 +316,6 @@ def disconnect( left: NodeArchitype | list[NodeArchitype], right: NodeArchitype | list[NodeArchitype], dir: EdgeDir, - filter_type: Optional[type], filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]], ) -> bool: # noqa: ANN401 """Jac's disconnect operator feature.""" @@ -326,17 +325,11 @@ def disconnect( for i in left: for j in right: edge_list: list[EdgeArchitype] = [*i._jac_.edges] - if filter_type: - edge_list = [e for e in edge_list if isinstance(e, filter_type)] edge_list = filter_func(edge_list) if filter_func else edge_list for e in edge_list: - if ( - e._jac_.target - and e._jac_.source - and (not filter_type or isinstance(e, filter_type)) - ): + if e._jac_.target and e._jac_.source: if ( - dir in ["OUT", "ANY"] + dir in ["OUT", "ANY"] # TODO: Not ideal and i._jac_.obj == e._jac_.source and e._jac_.target == j._jac_.obj ): diff --git a/jaclang/plugin/feature.py b/jaclang/plugin/feature.py index b88e500cb..56787db24 100644 --- a/jaclang/plugin/feature.py +++ b/jaclang/plugin/feature.py @@ -175,7 +175,6 @@ def disconnect( left: NodeArchitype | list[NodeArchitype], right: NodeArchitype | list[NodeArchitype], dir: EdgeDir, - filter_type: Optional[type], filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]], ) -> bool: """Jac's disconnect operator feature.""" @@ -183,7 +182,6 @@ def disconnect( left=left, right=right, dir=dir, - filter_type=filter_type, filter_func=filter_func, ) diff --git a/jaclang/plugin/spec.py b/jaclang/plugin/spec.py index 180cc0834..6f196f855 100644 --- a/jaclang/plugin/spec.py +++ b/jaclang/plugin/spec.py @@ -175,7 +175,6 @@ def disconnect( left: NodeArchitype | list[NodeArchitype], right: NodeArchitype | list[NodeArchitype], dir: EdgeDir, - filter_type: Optional[type], filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]], ) -> bool: # noqa: ANN401 """Jac's disconnect operator feature."""