| @@ -451,9 +451,12 @@ class TerminalTreeToPattern(Transformer): | |||||
| def expansions(self, exps): | def expansions(self, exps): | ||||
| if len(exps) == 1: | if len(exps) == 1: | ||||
| return exps[0] | return exps[0] | ||||
| if len({i.flags for i in exps}) > 1: | |||||
| raise GrammarError("Lark doesn't support joining terminals with conflicting flags!") | |||||
| return PatternRE('(?:%s)' % ('|'.join(i.to_regexp() for i in exps)), exps[0].flags) | |||||
| if not Py36: | |||||
| if len({i.flags for i in exps}) > 1: | |||||
| raise GrammarError("Lark doesn't support joining terminals with conflicting flags!") | |||||
| return PatternRE('(?:%s)' % ('|'.join(i.to_regexp() for i in exps)), exps[0].flags) | |||||
| else: | |||||
| return PatternRE('(?:%s)' % ('|'.join(i.to_regexp() for i in exps)), ()) | |||||
| def expr(self, args): | def expr(self, args): | ||||
| inner, op = args[:2] | inner, op = args[:2] | ||||
| @@ -1078,6 +1078,18 @@ def _make_parser_test(LEXER, PARSER): | |||||
| self.assertEqual(g.parse(" ").children,[" "]) | self.assertEqual(g.parse(" ").children,[" "]) | ||||
| self.assertEqual(g.parse("\n ").children,["\n "]) | self.assertEqual(g.parse("\n ").children,["\n "]) | ||||
| self.assertRaises(UnexpectedCharacters, g.parse, "\n\n") | self.assertRaises(UnexpectedCharacters, g.parse, "\n\n") | ||||
| g = r""" | |||||
| start: A | |||||
| A: B | C | |||||
| B: "b"i | |||||
| C: "c" | |||||
| """ | |||||
| g = _Lark(g) | |||||
| self.assertEqual(g.parse("b").children,["b"]) | |||||
| self.assertEqual(g.parse("B").children,["B"]) | |||||
| self.assertEqual(g.parse("c").children,["c"]) | |||||
| self.assertRaises(UnexpectedCharacters, g.parse, "C") | |||||
| def test_lexer_token_limit(self): | def test_lexer_token_limit(self): | ||||