From 9ab02b465c7568d25b382ab18c44ddf9414795be Mon Sep 17 00:00:00 2001 From: MegaIng1 Date: Thu, 16 Jul 2020 19:55:09 +0200 Subject: [PATCH] Added comment with explanation --- lark/load_grammar.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lark/load_grammar.py b/lark/load_grammar.py index eac1473..736d67c 100644 --- a/lark/load_grammar.py +++ b/lark/load_grammar.py @@ -441,6 +441,9 @@ class TerminalTreeToPattern(Transformer): assert items if len(items) == 1: return items[0] + # In Python 3.6, a new syntax for flags was introduced. We are already using it in `lexer.Pattern._get_flags` + # It allows us to activate flags just in a specific part, like in this case for a specific terminal. + # The `to_regexp` method already does this, so we don't have to continue to pass around the flags. if not Py36: if len({i.flags for i in items}) > 1: raise GrammarError("Lark doesn't support joining terminals with conflicting flags in python <3.6!") @@ -451,6 +454,7 @@ class TerminalTreeToPattern(Transformer): def expansions(self, exps): if len(exps) == 1: return exps[0] + # See `expansion` if not Py36: if len({i.flags for i in exps}) > 1: raise GrammarError("Lark doesn't support joining terminals with conflicting flags!")