From 256424f64680cd4a2906a5dcc07dbd2c37629948 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sat, 3 Dec 2022 02:20:50 +0100 Subject: [PATCH] Catching more tokens --- repl.py | 3 +- ziffers/__pycache__/ebnf.cpython-310.pyc | Bin 846 -> 811 bytes ziffers/__pycache__/parser.cpython-310.pyc | Bin 1794 -> 1794 bytes ziffers/ebnf.py | 34 +++++++++++++-------- 4 files changed, 24 insertions(+), 13 deletions(-) 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 4de9599d8ec4d921d43952bdf002ff767931397b..7a2358c828ebfde036cbfee3b72800642c76b28c 100644 GIT binary patch delta 390 zcmX@dwwjGMpO=@50SF?NbS1Bt$g5L7gNcEGO92Q{D+-DfY!x(;5{ne{74nlyN(&%# zN`84Bkd<1ToLG%n?K_S*vWR~zZng0%vTf&!rKywvn~u-OI4@kxornaP@9HBe!& zR*kwMC0!+;2@olmLXfFInP>xD%MjOCC5W9+_k;D-Spj8pvvUeklFKVI@(L4E(~2uf z(o3`Qt6<6@z67}jY*tK)c8ng7P~w`rfpH-t*W?r?O;NCWKmi85` z?1B-`pOk>5SbFE)cl~U&VmKUlu*BPI_IcoWU%Ke79u%kWsXlDEcje{13y&NmA7CCJ zSoFS#+)g80=%GAWX1PwH<^A zx4Hi=>H9BuejJ@FaER~-&rn+i1dj0m?MX-o@_kHU$}^bLhtL?FfOHHqbLK|r7uIV6 z+O-PoC)& delta 19 ZcmZqTYvSX|=jG*M00N!a8@Yb40RSa=1U>)& 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*" """