diff --git a/lark/exceptions.py b/lark/exceptions.py index da982e33..dafe0b37 100644 --- a/lark/exceptions.py +++ b/lark/exceptions.py @@ -72,7 +72,7 @@ def get_context(self, text: str, span: int=40) -> str: after = text[pos:end].split(b'\n', 1)[0] return (before + after + b'\n' + b' ' * len(before.expandtabs()) + b'^\n').decode("ascii", "backslashreplace") - def match_examples(self, parse_fn: 'Callable[[str], Tree]', + def match_examples(self, parse_fn: 'Callable[[str], Tree]', examples: Union[Mapping[T, Iterable[str]], Iterable[Tuple[T, Iterable[str]]]], token_type_match_fallback: bool=False, use_accepts: bool=True @@ -229,7 +229,7 @@ class UnexpectedToken(ParseError, UnexpectedInput): def __init__(self, token, expected, considered_rules=None, state=None, interactive_parser=None, terminals_by_name=None, token_history=None): super(UnexpectedToken, self).__init__() - + # TODO considered_rules and expected can be figured out using state self.line = getattr(token, 'line', '?') self.column = getattr(token, 'column', '?') diff --git a/lark/lark.py b/lark/lark.py index 8da98409..9f80ef06 100644 --- a/lark/lark.py +++ b/lark/lark.py @@ -310,7 +310,7 @@ def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None: else: if self.options.cache is not True: raise ConfigurationError("cache argument must be bool or str") - + try: username = getpass.getuser() except Exception: @@ -339,7 +339,7 @@ def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None: pass except Exception: # We should probably narrow done which errors we catch here. logger.exception("Failed to load Lark from cache: %r. We will try to carry on.", cache_fn) - + # In theory, the Lark instance might have been messed up by the call to `_load`. # In practice the only relevant thing that might have been overwritten should be `options` self.options = old_options @@ -609,7 +609,7 @@ def lex(self, text: str, dont_ignore: bool=False) -> Iterator[Token]: def get_terminal(self, name: str) -> TerminalDef: """Get information about a terminal""" return self._terminals_dict[name] - + def parse_interactive(self, text: Optional[str]=None, start: Optional[str]=None) -> 'InteractiveParser': """Start an interactive parsing session. diff --git a/lark/parser_frontends.py b/lark/parser_frontends.py index e162edfa..4e28e361 100644 --- a/lark/parser_frontends.py +++ b/lark/parser_frontends.py @@ -74,7 +74,7 @@ def __init__(self, lexer_conf, parser_conf, options, parser=None): if lexer_conf.postlex: self.lexer = PostLexConnector(self.lexer, lexer_conf.postlex) - + def _verify_start(self, start=None): if start is None: start_decls = self.parser_conf.start @@ -94,7 +94,7 @@ def parse(self, text, start=None, on_error=None): kw = {} if on_error is None else {'on_error': on_error} stream = self._make_lexer_thread(text) return self.parser.parse(stream, chosen_start, **kw) - + def parse_interactive(self, text=None, start=None): chosen_start = self._verify_start(start) if self.parser_conf.parser_type != 'lalr':