Catching more tokens

This commit is contained in:
2022-12-03 02:20:50 +01:00
parent 5296396107
commit 256424f646
4 changed files with 24 additions and 13 deletions

View File

@ -9,7 +9,8 @@ if __name__ == "__main__":
expr = input('> ') expr = input('> ')
if expr not in EXIT_CONDITION: if expr not in EXIT_CONDITION:
try: try:
parse_expression(expr) result = parse_expression(expr)
print(result)
except Exception as e: except Exception as e:
print(f"[red]Failed:[/red] {e}") print(f"[red]Failed:[/red] {e}")
else: else:

View File

@ -1,14 +1,18 @@
ebnf = r""" ebnf = r"""
expr = (number ws?)+ expr = (bar / octup / octdown / escape / rhythm / float / chord / pc / ws?)+
number = factor additive*
additive = ("+"/"-") factor escape = (lt (chord / pc) gt)
factor = primary multiplicative*
multiplicative = ("*" / "/") primary chord = pc{2,}
primary = parens / neg / number pc = (neg_pc / pc_basic)
parens = "(" number ")" neg_pc = (~r"-" pc)
neg = "-" primary pc_basic = ~r"[0-9TE]"
number = ((~"[0-9]"+ "."? ~"[0-9]"*) / ("." ~"[0-9]"+)) (("e"/"E") ("-"/"+") ~"[0-9]"+)?
ws = ~"\s*" rhythm = ~r"[mklpdcwyhnqaefsxtgujoz]"
float = ~r"\d+\.\d+"
lpar = "(" lpar = "("
rpar = ")" rpar = ")"
lbra = "[" lbra = "["
@ -17,13 +21,19 @@ ebnf = r"""
rcbra = "}" rcbra = "}"
lt = "<" lt = "<"
gt = ">" gt = ">"
comma = ","
octup = "^" octup = "^"
octdown = "_" octdown = "_"
barsign = "|"
bar = "|"
plus = "+" plus = "+"
minus = "-" minus = "-"
times = "*" times = "*"
div = "/" div = "/"
emptyline = ws+ emptyline = ws+
comma = ","
ws = ~"\s*"
""" """