コード例 #1
0
 def testNullInSequence(self):
     a = builder.makeSequence(
         [NonTerminal("foo"), Null,
          Terminal("bar"), Null,
          Terminal("baz")])
     b = Sequence([NonTerminal("foo"), Terminal("bar"), Terminal("baz")])
     self.assertEqual(a, b)
コード例 #2
0
 def testDuplicateBranchInAlternative(self):
     a = builder.makeAlternative(
         [Terminal("bar"),
          Terminal("foo"),
          Terminal("bar"), Null])
     b = Alternative([Terminal("bar"), Terminal("foo"), Null])
     self.assertEqual(a, b)
コード例 #3
0
 def testRestrictionWithLongerException(self):
     self.rules = [
         Rule(
             "restriction",
             Restriction(Terminal("base"),
                         Terminal("long exception branch")))
     ]
コード例 #4
0
 def testRestrictionWithShorterException(self):
     self.rules = [
         Rule(
             "restriction",
             Restriction(Terminal("long base branch"),
                         Terminal("exception")))
     ]
コード例 #5
0
 def testRepetitionWithLongBackwardBranch(self):
     self.rules = [
         Rule(
             "repetition",
             Repetition(Terminal("forward"),
                        Terminal("backward branch is longer")))
     ]
コード例 #6
0
 def testCommonSequenceAfterRepetition(self):
     a = builder.makeSequence([
         Repetition(Null, Sequence([NonTerminal("b"),
                                    Terminal("a")])),
         NonTerminal("b"),
         Terminal("a")
     ])
     b = Repetition(Sequence([NonTerminal("b"), Terminal("a")]), Null)
     self.assertEqual(a, b)
コード例 #7
0
 def testNull(self):
     self.rules = [
         Rule(
             "sequence with null",
             Sequence([
                 Terminal("space here ->"), Null,
                 Terminal("should be like here ->"),
                 Terminal("foo")
             ]))
     ]
コード例 #8
0
 def testCommonRestrictionAfterRepetition(self):
     a = builder.makeSequence([
         Repetition(Null, Restriction(Terminal("d"), Terminal("e"))),
         Restriction(Terminal("d"), Terminal("e"))
     ])
     b = Repetition(Restriction(Terminal("d"), Terminal("e")), Null)
     self.assertEqual(a, b)
コード例 #9
0
 def testCommonAlternativeAfterRepetition(self):
     a = builder.makeSequence([
         Repetition(Null, Alternative([Terminal("d"),
                                       Terminal("e")])),
         Alternative([Terminal("d"), Terminal("e")])
     ])
     b = Repetition(Alternative([Terminal("d"), Terminal("e")]), Null)
     self.assertEqual(a, b)
コード例 #10
0
 def testTerminal(self):
     self.rules = [Rule("terminal", Terminal("in a rounded rectangle"))]
コード例 #11
0
 def testNoCommonNullAfterRepetition(self):
     a = builder.makeSequence(
         [Repetition(NonTerminal("b"), Null),
          Terminal("d")])
     b = Sequence([Repetition(NonTerminal("b"), Null), Terminal("d")])
     self.assertEqual(a, b)
コード例 #12
0
 def testCommonTerminalBeforeRepetition(self):
     a = builder.makeSequence(
         [Terminal("a"), Repetition(Null, Terminal("a"))])
     b = Repetition(Terminal("a"), Null)
     self.assertEqual(a, b)
コード例 #13
0
 def testMultipleSimplifcationSteps(self):
     a = builder.makeAlternative(
         [Terminal("bar"),
          Alternative([Terminal("bar"), Terminal("bar")])])
     b = Terminal("bar")
     self.assertEqual(a, b)
コード例 #14
0
 def testAlternativeInAlternative(self):
     a = builder.makeAlternative(
         [Terminal("foo"),
          Alternative([Terminal("bar"), Terminal("baz")])])
     b = Alternative([Terminal("foo"), Terminal("bar"), Terminal("baz")])
     self.assertEqual(a, b)
コード例 #15
0
 def testAlternativeWithOneBranch(self):
     a = builder.makeAlternative([Terminal("foo")])
     b = Terminal("foo")
     self.assertEqual(a, b)