def semanticPredicateExpr(self): """ Find and generate code for a Python expression terminated by a close-paren, whose return value determines the success of the pattern it's in. """ expr = t.Action(self.pythonExpr(')')[0][0]) self.exactly(')') return t.Predicate(expr)
def test_pred(self): """ Test code generation for predicate expressions. """ x = t.Predicate(t.Exactly("x")) self.assertEqual( writePython(x, ""), dd(""" def _G_pred_1(): _G_exactly_2, lastError = self.exactly('x') self.considerError(lastError, None) return (_G_exactly_2, self.currentError) _G_pred_3, lastError = self.pred(_G_pred_1) self.considerError(lastError, None) _G_pred_3 """))
def test_pred(self): x = t.Predicate(t.Action("doStuff()")) self.assertEqual( writeBytecode(x), [t.Python('doStuff()'), t.Predicate()])
def generate_Predicate(self, out, expr, debugname=None): self._generateNode(out, expr) out.emit(t.Predicate())