Beispiel #1
0
 def expandBindings(self, bindings):
     #expand the name
     newName = util.expandFact(self._name, bindings)
     #expand the query
     newQuery = self._query.expandBindings(bindings)
     #expand the actions
     newActions = [x.expandBindings(bindings) for x in self._actions]
     return Rule(newQuery,
                 newActions,
                 transform=self._transform,
                 name=newName,
                 tags=self._tags)
Beispiel #2
0
def expansion_pass(toks):
    """ Expand any bindings that are stored in the parse """
    if not bool(toks):
        return toks
    elif len(toks) > 1:
        raise Exception("Unexpected toks size for binding expansion")
    #if a fact:
    if isinstance(toks[0], list):
        return [expandFact(toks[0], parseBindings)]
    #or if a rule or action macro:
    elif isinstance(toks[0], (Rule, ActionMacro)):
        return [toks[0].expandBindings(parseBindings)]
    return toks
Beispiel #3
0
 def expandBindings(self, bindings):
     """ Expand stored bindings at interpret time
     ie: +(.a.b.$x) + { x : .a.b.c } -> +(.a.b.a.b.c)
     """
     newValues = []
     for x in self._values:
         if isinstance(x, util.Bind) and x.value in bindings:
             newValues.append(bindings[x.value])
         elif isinstance(x, list):
             newValues.append(util.expandFact(x, bindings))
         else:
             newValues.append(x)
     return Action(self._op, newValues)
Beispiel #4
0
 def test_binding_expansion(self):
     bindings = { "a" : FP.parseString(".blah")[0], "b": FP.parseString(".bloo")[0] }
     result = FP.parseString('$a.b.$b!c')[0]
     expanded = util.expandFact(result, bindings)
     asString = "".join([str(x) for x in expanded if not x.is_root()])
     self.assertEqual(asString, ".blah.b.bloo!c")
Beispiel #5
0
 def expandBindings(self, bindings):
     newComponents = expandFact(self.components, bindings)
     return Clause(newComponents, negated=self.negated)