def test_superApply(self): one = t.Action("1") x = t.Action("x") a = t.Apply("super", "main", [one, x]) self.assertEqual(writeBytecode(a), [t.Python('1'), t.Push(), t.Python('x'), t.Push(), t.SuperCall('main')])
def generate_Repeat(self, out, min, max, expr, debugname=None): out.emit(t.Python(str(min.data))) out.emit(t.Push()) out.emit(t.Python(str(max.data))) out.emit(t.Push()) L = out.emit(t.RepeatChoice()) self._generateNode(out, expr, debugname) L2 = out.emit(t.Commit()) out.patchNext(L) out.backpatch(L2, L)
def test_foreignApply(self): one = t.Action("1") x = t.Action("x") a = t.ForeignApply("thegrammar", "foo", "main", [one, x]) self.assertEqual(writeBytecode(a), [t.Python('1'), t.Push(), t.Python('x'), t.Push(), t.ForeignCall('thegrammar', 'foo')])
def test_repeat(self): x = t.Repeat(3, 4, t.Exactly('x')) self.assertEqual(writeBytecode(x), [t.Python("3"), t.Push(), t.Python("4"), t.Push(), t.RepeatChoice(3), t.Match('x'), t.Commit(-2)])
def test_apply(self): one = t.Action("1") x = t.Action("x") a = t.Apply("foo", "main", [one, x]) self.assertEqual(writeBytecode(a), [t.Python('1'), t.Push(), t.Python('x'), t.Push(), t.Call('foo')])
def generate_Apply(self, out, ruleName, codeName, rawArgs, debugname=None): for arg in rawArgs.args: self._generateNode(out, arg, debugname) out.emit(t.Push()) if ruleName.data == "super": out.emit(t.SuperCall(codeName)) else: out.emit(t.Call(ruleName))
def generate_ForeignApply(self, out, grammarName, ruleName, codeName, rawArgs, debugname=None): for arg in rawArgs.args: self._generateNode(out, arg, debugname) out.emit(t.Push()) out.emit(t.ForeignCall(grammarName, ruleName))