Skip to content

Commit

Permalink
Starting to tidy up mathics.core.pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera committed Sep 16, 2024
1 parent ebdc6b9 commit 8e2bf04
Show file tree
Hide file tree
Showing 2 changed files with 408 additions and 302 deletions.
18 changes: 10 additions & 8 deletions mathics/builtin/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,10 +1005,10 @@ def __repr__(self):
def get_match_count(self, vars={}):
return self.pattern.get_match_count(vars)

def match(self, yield_func, expression, vars, evaluation, **kwargs):
existing = vars.get(self.varname, None)
def match(self, yield_func, expression, vars_dict, evaluation, **kwargs):
existing = vars_dict.get(self.varname, None)
if existing is None:
new_vars = vars.copy()
new_vars = vars_dict.copy()
new_vars[self.varname] = expression
# for vars_2, rest in self.pattern.match(
# expression, new_vars, evaluation):
Expand All @@ -1021,22 +1021,24 @@ def match(self, yield_func, expression, vars, evaluation, **kwargs):
self.pattern.match(yield_func, expression, new_vars, evaluation)
else:
if existing.sameQ(expression):
yield_func(vars, None)
yield_func(vars_dict, None)

def get_match_candidates(
self, elements: tuple, expression, attributes, evaluation, vars={}
self, elements: tuple, expression, attributes, evaluation, vars_dict=None
):
existing = vars.get(self.varname, None)
if vars_dict is None:
vars_dict = {}
existing = vars_dict.get(self.varname, None)
if existing is None:
return self.pattern.get_match_candidates(
elements, expression, attributes, evaluation, vars
elements, expression, attributes, evaluation, vars_dict
)
else:
# Treat existing variable as verbatim
verbatim_expr = Expression(SymbolVerbatim, existing)
verbatim = Verbatim(verbatim_expr)
return verbatim.get_match_candidates(
elements, expression, attributes, evaluation, vars
elements, expression, attributes, evaluation, vars_dict
)


Expand Down
Loading

0 comments on commit 8e2bf04

Please sign in to comment.