Esempio n. 1
0
    def test_grammar_choice_mismatch(self):
        grammar = Grammar(Choice(Sequence('NUMBER', 'WORD'), 'WORD'))

        datas = [([('NUMBER', '1', 5)], -1),
                 ([('NUMBER', '1', 5), ('NUMBER', '2', 7)], 7)]

        self.parse_and_assert_mismatch(grammar, datas)
Esempio n. 2
0
    def test_grammar_choice(self):
        grammar = Grammar(Choice('NUMBER', 'WORD'))

        datas = [
            (
                [('WORD', 'm')],
                'm'
            ),
            (
                [('NUMBER', '5')],
                '5'
            )
        ]

        self.parse_and_assert_tree(grammar, datas)
Esempio n. 3
0
 def grammar(self):
     return Choice(Sequence('NUMBER', 'WORD'), 'WORD')