diff --git a/lark/lark.py b/lark/lark.py index ed1dfbc..4aa9e7e 100644 --- a/lark/lark.py +++ b/lark/lark.py @@ -288,7 +288,12 @@ class Lark(Serialize): if self.options.parser == 'lalr': self.options.lexer = 'contextual' elif self.options.parser == 'earley': - self.options.lexer = 'dynamic' + if self.options.postlex is not None: + logger.info("postlex can't be used with the dynamic lexer, so we use standard instead. " + "Consider using lalr with contextual instead of earley") + self.options.lexer = 'standard' + else: + self.options.lexer = 'dynamic' elif self.options.parser == 'cyk': self.options.lexer = 'standard' else: @@ -298,6 +303,8 @@ class Lark(Serialize): assert issubclass(lexer, Lexer) # XXX Is this really important? Maybe just ensure interface compliance else: assert_config(lexer, ('standard', 'contextual', 'dynamic', 'dynamic_complete')) + if self.options.postlex is not None and 'dynamic' in lexer: + raise ConfigurationError("Can't use postlex with a dynamic lexer. Use standard or contextual instead") if self.options.ambiguity == 'auto': if self.options.parser == 'earley': diff --git a/lark/parser_frontends.py b/lark/parser_frontends.py index 5acbbeb..04d38a4 100644 --- a/lark/parser_frontends.py +++ b/lark/parser_frontends.py @@ -83,6 +83,7 @@ class ParsingFrontend(Serialize): lexer_type = lexer_conf.lexer_type self.skip_lexer = False if lexer_type in ('dynamic', 'dynamic_complete'): + assert lexer_conf.postlex is None self.skip_lexer = True return