Exemplo n.º 1
0
 def init(self, expr):
     super(Except, self).init(expr)
     self.c = Pattern.create(expr.leaves[0])
     if len(expr.leaves) == 2:
         self.p = Pattern.create(expr.leaves[1])
     else:
         self.p = Pattern.create(Expression('Blank'))
Exemplo n.º 2
0
 def init(self, expr):
     super(Optional, self).init(expr)
     self.pattern = Pattern.create(expr.leaves[0])
     if len(expr.leaves) == 2:
         self.default = expr.leaves[1]
     else:
         self.default = None
Exemplo n.º 3
0
def match(expr, form, evaluation):        
    class StopGenerator_MatchQ(StopGenerator):
        pass
    
    form = Pattern.create(form)
    def yield_func(vars, rest):
        raise StopGenerator_MatchQ(Symbol("True"))
    try:
        form.match(yield_func, expr, {}, evaluation)
    except StopGenerator_MatchQ, exc:
        return True
Exemplo n.º 4
0
    def init(self, expr, min=1):
        self.pattern = Pattern.create(expr.leaves[0])

        self.max = None
        self.min = min
        if len(expr.leaves) == 2:
            leaf_1 = expr.leaves[1]
            if (leaf_1.has_form('List', 1, 2) and all(leaf.get_int_value() for leaf in leaf_1.leaves)):
                self.max = leaf_1.leaves[-1].get_int_value()
                self.min = leaf_1.leaves[0].get_int_value()
            elif leaf_1.get_int_value():
                self.max = leaf_1.get_int_value()
            else:
                self.error('range', 2, expr)
Exemplo n.º 5
0
 def apply(self, expr, form, evaluation):
     'MatchQ[expr_, form_]'
     
     class StopGenerator_MatchQ(StopGenerator):
         pass
     
     form = Pattern.create(form)
     #for vars, rest in form.match(expr, {}, evaluation):
     def yield_func(vars, rest):
         #return Symbol("True")
         raise StopGenerator_MatchQ(Symbol("True"))
     try:
         form.match(yield_func, expr, {}, evaluation)
     except StopGenerator_MatchQ, exc:
         return exc.value
Exemplo n.º 6
0
 def __init__(self, pattern, system=False):
     super(BaseRule, self).__init__()
     self.pattern = Pattern.create(pattern)
     self.system = system
Exemplo n.º 7
0
 def init(self, expr):
     super(HoldPattern, self).init(expr)
     self.pattern = Pattern.create(expr.leaves[0])
Exemplo n.º 8
0
 def init(self, expr):
     super(Pattern_, self).init(expr)
     self.varname = expr.leaves[0].get_name()
     if self.varname is None:
         self.error('patvar', expr)
     self.pattern = Pattern.create(expr.leaves[1])
Exemplo n.º 9
0
 def init(self, expr):
     super(Alternatives, self).init(expr)
     self.alternatives = [Pattern.create(leaf) for leaf in expr.leaves]
Exemplo n.º 10
0
 def init(self, expr):
     super(Condition, self).init(expr)
     self.pattern = Pattern.create(expr.leaves[0])
     self.test = expr.leaves[1]
Exemplo n.º 11
0
 def init(self, expr):
     super(Condition, self).init(expr)
     self.pattern = Pattern.create(expr.leaves[0])
     self.test = expr.leaves[1]
Exemplo n.º 12
0
 def init(self, expr):
     super(PatternTest, self).init(expr)
     self.pattern = Pattern.create(expr.leaves[0])
     self.test = expr.leaves[1]
     self.test_name = self.test.get_name()
Exemplo n.º 13
0
 def __init__(self, form):
     self.form = Pattern.create(form)
Exemplo n.º 14
0
 def init(self, expr):
     super(HoldPattern, self).init(expr)
     self.pattern = Pattern.create(expr.leaves[0])
Exemplo n.º 15
0
 def __init__(self, pattern, system=False) -> None:
     self.pattern = Pattern.create(pattern)
     self.system = system
Exemplo n.º 16
0
 def __init__(self, pattern, system=False):
     super(BaseRule, self).__init__()
     self.pattern = Pattern.create(pattern)
     self.system = system
Exemplo n.º 17
0
 def init(self, expr):
     super(Pattern_, self).init(expr)
     self.varname = expr.leaves[0].get_name()
     if self.varname is None:
         self.error('patvar', expr)
     self.pattern = Pattern.create(expr.leaves[1])
Exemplo n.º 18
0
 def __init__(self, pattern, system=False):
     self.pattern = Pattern.create(pattern)
     self.system = system
Exemplo n.º 19
0
 def __init__(self, form):
     self.form = Pattern.create(form)
Exemplo n.º 20
0
 def init(self, expr):
     super(Alternatives, self).init(expr)
     self.alternatives = [Pattern.create(leaf) for leaf in expr.leaves]
Exemplo n.º 21
0
 def init(self, expr):
     super(PatternTest, self).init(expr)
     self.pattern = Pattern.create(expr.leaves[0])
     self.test = expr.leaves[1]
     self.test_name = self.test.get_name()