| @@ -4,6 +4,7 @@ from .tree import * | |||||
| from .visitors import * | from .visitors import * | ||||
| from .exceptions import * | from .exceptions import * | ||||
| from .lexer import * | from .lexer import * | ||||
| from .load_grammar import * | |||||
| from .lark import * | from .lark import * | ||||
| from logging import Logger as _Logger | from logging import Logger as _Logger | ||||
| @@ -0,0 +1,9 @@ | |||||
| from typing import Optional, Tuple | |||||
| class RuleOptions: | |||||
| keep_all_tokens: bool | |||||
| expand1: bool | |||||
| priority: int | |||||
| template_source: Optional[str] | |||||
| empty_indices: Tuple[bool, ...] | |||||
| @@ -8,6 +8,7 @@ from .visitors import Transformer | |||||
| from .lexer import Token, Lexer, TerminalDef | from .lexer import Token, Lexer, TerminalDef | ||||
| from .tree import Tree | from .tree import Tree | ||||
| from .exceptions import UnexpectedInput | from .exceptions import UnexpectedInput | ||||
| from .load_grammar import Grammar | |||||
| _T = TypeVar('_T') | _T = TypeVar('_T') | ||||
| @@ -54,13 +55,14 @@ class FromPackageLoader: | |||||
| class Lark: | class Lark: | ||||
| source_path: str | source_path: str | ||||
| source_grammar: str | source_grammar: str | ||||
| grammar: Grammar | |||||
| options: LarkOptions | options: LarkOptions | ||||
| lexer: Lexer | lexer: Lexer | ||||
| terminals: List[TerminalDef] | terminals: List[TerminalDef] | ||||
| def __init__( | def __init__( | ||||
| self, | self, | ||||
| grammar: Union[str, IO[str]], | |||||
| grammar: Union[Grammar, str, IO[str]], | |||||
| *, | *, | ||||
| start: Union[None, str, List[str]] = "start", | start: Union[None, str, List[str]] = "start", | ||||
| parser: Literal["earley", "lalr", "cyk"] = "auto", | parser: Literal["earley", "lalr", "cyk"] = "auto", | ||||
| @@ -0,0 +1,28 @@ | |||||
| from typing import List, Tuple, Union, Callable, Dict, Optional | |||||
| from lark import Tree | |||||
| from lark.grammar import RuleOptions | |||||
| class Grammar: | |||||
| rule_defs: List[Tuple[str, Tuple[str, ...], Tree, RuleOptions]] | |||||
| term_defs: List[Tuple[str, Tuple[Tree, int]]] | |||||
| ignore: List[str] | |||||
| class GrammarBuilder: | |||||
| global_keep_all_tokens: bool | |||||
| import_paths: List[Union[str, Callable]] | |||||
| def __init__(self, global_keep_all_tokens=..., import_paths=...): ... | |||||
| def load_grammar(self, grammar_text: str, grammar_name: str = ..., mangle: Callable[[str], str] = None): ... | |||||
| def do_import(self, dotted_path: Tuple[str, ...], base_path: Optional[str], aliases: Dict[str, str], | |||||
| base_mangle: Callable[[str], str] = None): ... | |||||
| def get_mangle(self, prefix: str, aliases: Dict[str, str], base_mangle: Callable[[str], str] = None): ... | |||||
| def check(self): ... | |||||
| def build(self) -> Grammar: ... | |||||
| @@ -960,7 +960,7 @@ class GrammarBuilder: | |||||
| base = self._definitions[name][1] | base = self._definitions[name][1] | ||||
| while len(base.children) == 2: | while len(base.children) == 2: | ||||
| assert isinstance(base.children[0], Tree) and base.children[0].data == 'expansions', tree | |||||
| assert isinstance(base.children[0], Tree) and base.children[0].data == 'expansions', base | |||||
| base = base.children[0] | base = base.children[0] | ||||
| base.children.insert(0, exp) | base.children.insert(0, exp) | ||||