Created
June 1, 2022 14:32
-
-
Save mbednarski/ea004594b22dbe96cafd799eb0f3e27f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
import lark | |
import rich | |
class Parser: | |
def __init__( | |
self, grammar_path: Path = Path("grammar.lark"), start: str = "program" | |
) -> None: | |
with grammar_path.open("rt") as f: | |
grammar_text = f.read() | |
self.lark = lark.Lark(grammar_text, start=start, ambiguity="explicit") | |
def parse_text(self, program_text: str) -> lark.ParseTree: | |
parsed = self.lark.parse(program_text) | |
return parsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment