Exemplo n.º 1
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)
Exemplo n.º 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)
Exemplo n.º 3
0
 def testAlternative(self):
     self.rules = [
         Rule(
             "alternative",
             Alternative([
                 NonTerminal("with"),
                 NonTerminal("several"),
                 NonTerminal("branches")
             ]))
     ]
Exemplo n.º 4
0
 def testBackwardAlternative(self):
     self.rules = [
         Rule(
             "repetition",
             Repetition(
                 NonTerminal("forward"),
                 Alternative([
                     NonTerminal("foo"),
                     NonTerminal("bar"),
                     NonTerminal("baz")
                 ])))
     ]
Exemplo n.º 5
0
 def testAlternativeWithOneBranch(self):
     self.rules = [
         Rule("alternative", Alternative([NonTerminal("with one branch")]))
     ]
Exemplo n.º 6
0
 def testMultipleSimplifcationSteps(self):
     a = builder.makeAlternative(
         [Terminal("bar"),
          Alternative([Terminal("bar"), Terminal("bar")])])
     b = Terminal("bar")
     self.assertEqual(a, b)
Exemplo n.º 7
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)