Skip to content

Added parse_lark_grammar.py and the syntax parameter/registry #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lark/lark.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class LarkOptions(Serialize):
edit_terminals: Optional[Callable[[TerminalDef], TerminalDef]]
import_paths: 'List[Union[str, Callable[[Union[None, str, PackageResource], str], Tuple[str, str]]]]'
source_path: Optional[str]
syntax: Union[str, Callable[[str, str], Tree]]

OPTIONS_DOC = """
**=== General Options ===**
Expand Down Expand Up @@ -136,6 +137,9 @@ class LarkOptions(Serialize):
A List of either paths or loader functions to specify from where grammars are imported
source_path
Override the source of from where the grammar was loaded. Useful for relative imports and unconventional grammar loading
syntax
Select the syntax with which the grammar is parsed. Either a function or a registered syntax
(default guess based on extension / uses lark when that fails)
**=== End of Options ===**
"""
if __doc__:
Expand Down Expand Up @@ -169,6 +173,7 @@ class LarkOptions(Serialize):
'use_bytes': False,
'import_paths': [],
'source_path': None,
'syntax': None
}

def __init__(self, options_dict):
Expand Down Expand Up @@ -328,7 +333,7 @@ def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None:


# Parse the grammar file and compose the grammars
self.grammar, used_files = load_grammar(grammar, self.source_path, self.options.import_paths, self.options.keep_all_tokens)
self.grammar, used_files = load_grammar(grammar, self.source_path, self.options)
else:
assert isinstance(grammar, Grammar)
self.grammar = grammar
Expand Down
Loading