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)
def test_grammar_choice(self): grammar = Grammar(Choice('NUMBER', 'WORD')) datas = [ ( [('WORD', 'm')], 'm' ), ( [('NUMBER', '5')], '5' ) ] self.parse_and_assert_tree(grammar, datas)
def grammar(self): return Choice(Sequence('NUMBER', 'WORD'), 'WORD')