@@ -80,18 +80,26 @@ class Pattern:
80
80
def create (expr : BaseElement ) -> "Pattern" :
81
81
"""
82
82
If ``expr`` is listed in ``pattern_object`` return the pattern found there.
83
- Otherwise, if ``expr`` is an ``Atom``, create and return ``AtomPattern`` for ``expr``.
84
- Otherwise, create and return and ``ExpressionPattern`` for ``expr``.
83
+ Otherwise, if ``expr`` is an ``Atom``, create and return ``AtomPattern`` for ``expr``;
84
+ if it is an ``Expression`` create and return and ``ExpressionPattern`` for ``expr``.
85
+ Finally, it tries to get one object of one of these classes
86
+ by calling the method ``to_expression``, and then call the function
87
+ again with this new object as input.
85
88
"""
89
+ if not isinstance (expr , (Atom , Expression )):
90
+ expr = expr .to_expression ()
86
91
87
92
name = expr .get_head_name ()
88
93
pattern_object = pattern_objects .get (name )
89
94
if pattern_object is not None :
90
95
return pattern_object (expr )
91
96
if isinstance (expr , Atom ):
92
97
return AtomPattern (expr )
93
- else :
98
+ elif isinstance ( expr , Expression ) :
94
99
return ExpressionPattern (expr )
100
+ # Otherwise, try to get an expression and
101
+ # call again.
102
+ return Pattern .create (expr .to_expression ())
95
103
96
104
def match (
97
105
self ,
0 commit comments