コード例 #1
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 def test_sequence(self):
     x = t.Exactly("x")
     y = t.Exactly("y")
     z = t.And([x, y])
     self.assertEqual(writeBytecode(z),
                      [t.Match('x'),
                       t.Match('y')])
コード例 #2
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 def test_not(self):
     x = t.Not(t.Exactly("x"))
     self.assertEqual(writeBytecode(x),
                      [t.Choice(4),
                       t.Match('x'),
                       t.Commit(1),
                       t.Fail()])
コード例 #3
0
 def test_optional(self):
     x = t.Optional(t.Exactly("x"))
     self.assertEqual(writeBytecode(x),
                      [t.Choice(3),
                       t.Match('x'),
                       t.Commit(2),
                       t.Python("None")])
コード例 #4
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 def test_many1(self):
     xs = t.Many1(t.Exactly("x"))
     self.assertEqual(writeBytecode(xs),
                      [t.Match('x'),
                       t.Choice(3),
                       t.Match('x'),
                       t.Commit(-2)])
コード例 #5
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 def test_optional(self):
     x = t.Optional(t.Exactly("x"))
     self.assertEqual(writeBytecode(x),
                      [t.Choice(3),
                       t.Match('x'),
                       t.Commit(2),
                       t.Python("None")])
コード例 #6
0
 def test_many1(self):
     xs = t.Many1(t.Exactly("x"))
     self.assertEqual(writeBytecode(xs),
                      [t.Match('x'),
                       t.Choice(3),
                       t.Match('x'),
                       t.Commit(-2)])
コード例 #7
0
 def test_sequence(self):
     x = t.Exactly("x")
     y = t.Exactly("y")
     z = t.And([x, y])
     self.assertEqual(writeBytecode(z),
                      [t.Match('x'),
                       t.Match('y')])
コード例 #8
0
 def test_not(self):
     x = t.Not(t.Exactly("x"))
     self.assertEqual(writeBytecode(x),
                      [t.Choice(4),
                       t.Match('x'),
                       t.Commit(1),
                       t.Fail()])
コード例 #9
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 def test_doubleOr(self):
     xy = t.Or([t.Exactly("x"),
                t.Exactly("y")])
     self.assertEqual(writeBytecode(xy),
                      [t.Choice(3),
                       t.Match('x'),
                       t.Commit(2),
                       t.Match('y')])
コード例 #10
0
 def test_doubleOr(self):
     xy = t.Or([t.Exactly("x"),
                t.Exactly("y")])
     self.assertEqual(writeBytecode(xy),
                      [t.Choice(3),
                       t.Match('x'),
                       t.Commit(2),
                       t.Match('y')])
コード例 #11
0
ファイル: test_vm_builder.py プロジェクト: mdboom/parsley
 def test_lookahead(self):
     x = t.Lookahead(t.Exactly("x"))
     self.assertEqual(writeBytecode(x),
                      [t.Choice(5),
                       t.Choice(3),
                       t.Match('x'),
                       t.Commit(4),
                       t.Fail()])
コード例 #12
0
 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')])
コード例 #13
0
 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')])
コード例 #14
0
 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)])
コード例 #15
0
 def test_lookahead(self):
     x = t.Lookahead(t.Exactly("x"))
     self.assertEqual(writeBytecode(x),
                      [t.Choice(7),
                       t.Choice(4),
                       t.Match('x'),
                       t.Commit(1),
                       t.Fail(),
                       t.Commit(1),
                       t.Fail()])
コード例 #16
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 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')])
コード例 #17
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 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')])
コード例 #18
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 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')])
コード例 #19
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 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)])
コード例 #20
0
 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')])
コード例 #21
0
 def test_singleOr(self):
     x1 = t.Or([t.Exactly("x")])
     x = t.Exactly("x")
     self.assertEqual(writeBytecode(x1), writeBytecode(x))
コード例 #22
0
 def test_or(self):
     xy = t.Or([t.Exactly("x"), t.Exactly("y")])
     self.assertEqual(writeBytecode(xy), [t.Choice(3), t.Match("x"), t.Commit(4), t.Match("y")])
コード例 #23
0
 def test_many1(self):
     xs = t.Many1(t.Exactly("x"))
     self.assertEqual(writeBytecode(xs), [t.Match("x"), t.Choice(4), t.Match("x"), t.PartialCommit(1)])
コード例 #24
0
 def test_bind(self):
     x = t.Exactly("x")
     b = t.Bind("var", x)
     self.assertEqual(writeBytecode(b), [t.Match('x'), t.Bind('var')])
コード例 #25
0
 def test_bind_apply(self):
     x = t.Apply("members", "object", [])
     b = t.Bind("m", x)
     self.assertEqual(writeBytecode(b), [t.Call('members'), t.Bind('m')])
コード例 #26
0
 def test_exactly(self):
     x = t.Exactly("a")
     self.assertEqual(writeBytecode(x), [t.Match("a")])
コード例 #27
0
 def test_exactly(self):
     x = t.Exactly("a")
     self.assertEqual(writeBytecode(x), [t.Match("a")])
コード例 #28
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 def test_consumedby(self):
     x = t.ConsumedBy(t.Exactly('x'))
     self.assertEqual(writeBytecode(x),
                      [t.StartSlice(),
                       t.Match('x'),
                       t.EndSlice()])
コード例 #29
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 def test_pred(self):
     x = t.Predicate(t.Action("doStuff()"))
     self.assertEqual(writeBytecode(x),
                      [t.Python('doStuff()'),
                       t.Predicate()])
コード例 #30
0
ファイル: test_vm_builder.py プロジェクト: abenassi/parsley
 def test_bind_apply(self):
     x = t.Apply("members", "object", [])
     b = t.Bind("m", x)
     self.assertEqual(writeBytecode(b),
                      [t.Call('members'),
                       t.Bind('m')])
コード例 #31
0
 def test_listpattern(self):
     x = t.List(t.Exactly("x"))
     self.assertEqual(
         writeBytecode(x),
         [t.Descend(), t.Match('x'), t.Ascend()])
コード例 #32
0
 def test_optional(self):
     x = t.Optional(t.Exactly("x"))
     self.assertEqual(writeBytecode(x), [t.Choice(3), t.Match("x"), t.Commit(4), t.Push(None)])
コード例 #33
0
 def test_pred(self):
     x = t.Predicate(t.Action("doStuff()"))
     self.assertEqual(writeBytecode(x), [t.Eval("doStuff()"), t.FailIfFalse()])
コード例 #34
0
 def test_not(self):
     x = t.Not(t.Exactly("x"))
     self.assertEqual(writeBytecode(x), [t.Choice(3), t.Match("x"), t.FailTwice()])
コード例 #35
0
 def test_consumedby(self):
     x = t.ConsumedBy(t.Exactly('x'))
     self.assertEqual(
         writeBytecode(x),
         [t.StartSlice(), t.Match('x'),
          t.EndSlice()])
コード例 #36
0
 def test_bind(self):
     x = t.Exactly("x")
     b = t.Bind("var", x)
     self.assertEqual(writeBytecode(b), [t.Match("x"), t.Bind("var")])
コード例 #37
0
 def test_pred(self):
     x = t.Predicate(t.Action("doStuff()"))
     self.assertEqual(
         writeBytecode(x),
         [t.Python('doStuff()'), t.Predicate()])
コード例 #38
0
 def test_listpattern(self):
     x = t.List(t.Exactly("x"))
     self.assertEqual(writeBytecode(x), [t.Descend(2), t.Match("x")])
コード例 #39
0
 def test_singleOr(self):
     x1 = t.Or([t.Exactly("x")])
     x = t.Exactly("x")
     self.assertEqual(writeBytecode(x1), writeBytecode(x))