diff --git a/repl.py b/repl.py index 92820da..1bb5f29 100644 --- a/repl.py +++ b/repl.py @@ -9,7 +9,8 @@ if __name__ == "__main__": expr = input('> ') if expr not in EXIT_CONDITION: try: - parse_expression(expr) + result = parse_expression(expr) + print(result) except Exception as e: print(f"[red]Failed:[/red] {e}") else: diff --git a/ziffers/__pycache__/ebnf.cpython-310.pyc b/ziffers/__pycache__/ebnf.cpython-310.pyc index 4de9599..7a2358c 100644 Binary files a/ziffers/__pycache__/ebnf.cpython-310.pyc and b/ziffers/__pycache__/ebnf.cpython-310.pyc differ diff --git a/ziffers/__pycache__/parser.cpython-310.pyc b/ziffers/__pycache__/parser.cpython-310.pyc index 433c0ad..220598c 100644 Binary files a/ziffers/__pycache__/parser.cpython-310.pyc and b/ziffers/__pycache__/parser.cpython-310.pyc differ diff --git a/ziffers/ebnf.py b/ziffers/ebnf.py index 972154f..7297307 100644 --- a/ziffers/ebnf.py +++ b/ziffers/ebnf.py @@ -1,14 +1,18 @@ + ebnf = r""" - expr = (number ws?)+ - number = factor additive* - additive = ("+"/"-") factor - factor = primary multiplicative* - multiplicative = ("*" / "/") primary - primary = parens / neg / number - parens = "(" number ")" - neg = "-" primary - number = ((~"[0-9]"+ "."? ~"[0-9]"*) / ("." ~"[0-9]"+)) (("e"/"E") ("-"/"+") ~"[0-9]"+)? - ws = ~"\s*" + expr = (bar / octup / octdown / escape / rhythm / float / chord / pc / ws?)+ + + escape = (lt (chord / pc) gt) + + chord = pc{2,} + pc = (neg_pc / pc_basic) + neg_pc = (~r"-" pc) + pc_basic = ~r"[0-9TE]" + + rhythm = ~r"[mklpdcwyhnqaefsxtgujoz]" + + float = ~r"\d+\.\d+" + lpar = "(" rpar = ")" lbra = "[" @@ -17,13 +21,19 @@ ebnf = r""" rcbra = "}" lt = "<" gt = ">" - comma = "," + + octup = "^" octdown = "_" - barsign = "|" + + bar = "|" + plus = "+" minus = "-" times = "*" div = "/" + emptyline = ws+ + comma = "," + ws = ~"\s*" """