示例#1
0
 def testRuleNamesWithAscentAndDescent(self):
     self.rules = [
         Rule("aaaaa", NonTerminal("ascent and descent")),
         Rule("ppppp", NonTerminal("should")),
         Rule("ddddd", NonTerminal("look")),
         Rule("dddpp", NonTerminal("right"))
     ]
示例#2
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)
示例#3
0
 def testRepetitionWithLongForwardBranch(self):
     self.rules = [
         Rule(
             "repetition",
             Repetition(NonTerminal("forward branch is longer"),
                        NonTerminal("backward")))
     ]
示例#4
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)
示例#5
0
 def testSequence(self):
     self.rules = [
         Rule(
             "sequence",
             Sequence([
                 NonTerminal("with"),
                 NonTerminal("one"),
                 NonTerminal("branch")
             ]))
     ]
示例#6
0
 def testAlternative(self):
     self.rules = [
         Rule(
             "alternative",
             Alternative([
                 NonTerminal("with"),
                 NonTerminal("several"),
                 NonTerminal("branches")
             ]))
     ]
示例#7
0
 def testImbricatedRepetitions(self):
     self.rules = [
         Rule(
             "repetition",
             Repetition(
                 Repetition(NonTerminal("forward 1"),
                            NonTerminal("backward 1")),
                 Repetition(NonTerminal("forward 2"),
                            NonTerminal("backward 2"))))
     ]
示例#8
0
 def testBackwardAlternative(self):
     self.rules = [
         Rule(
             "repetition",
             Repetition(
                 NonTerminal("forward"),
                 Alternative([
                     NonTerminal("foo"),
                     NonTerminal("bar"),
                     NonTerminal("baz")
                 ])))
     ]
示例#9
0
 def testAlternativeWithOneBranch(self):
     self.rules = [
         Rule("alternative", Alternative([NonTerminal("with one branch")]))
     ]
示例#10
0
 def testLongRuleName(self):
     self.rules = [
         Rule("this long rule name should not be truncated",
              NonTerminal("foo")),
     ]
示例#11
0
 def testNonTerminal(self):
     self.rules = [Rule("non terminal", NonTerminal("in a rectangle"))]
示例#12
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)
示例#13
0
 def testCommonNonTerminalBeforeRepetition(self):
     a = builder.makeSequence(
         [NonTerminal("a"),
          Repetition(Null, NonTerminal("a"))])
     b = Repetition(NonTerminal("a"), Null)
     self.assertEqual(a, b)
示例#14
0
 def testSequenceWithOneElement(self):
     a = builder.makeSequence([NonTerminal("foo")])
     b = NonTerminal("foo")
     self.assertEqual(a, b)