21 lines
438 B
Python
21 lines
438 B
Python
from rich import print
|
|
from .mapper import *
|
|
from pathlib import Path
|
|
from lark import Lark
|
|
|
|
grammar_path = Path(__file__).parent
|
|
grammar = grammar_path / "ziffers.lark"
|
|
|
|
ziffers_parser = Lark.open(
|
|
grammar,
|
|
rel_to=__file__,
|
|
start="root",
|
|
parser="lalr",
|
|
transformer=ZiffersTransformer(),
|
|
)
|
|
|
|
|
|
def parse_expression(expr: str):
|
|
"""Parse an expression using the Ziffers parser"""
|
|
return ziffers_parser.parse(expr)
|