From f8ff0a0c3e995a6e5cf8299c3cdae6dee0766808 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 21 Oct 2022 14:41:24 -0700 Subject: [PATCH] Changed parsing syntax --- parser.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/parser.py b/parser.py index 2bba6b1..85e9e8b 100755 --- a/parser.py +++ b/parser.py @@ -14,8 +14,6 @@ class Parser: lp = pp.Suppress("(") rp = pp.Suppress(")") - func_char = pp.Suppress("->") - macro_char = pp.Suppress("=") # Simple tokens pp_expr = pp.Forward() @@ -26,14 +24,14 @@ class Parser: # Right associative. # # => - pp_lambda_fun = pp_name + func_char + pp_expr + pp_lambda_fun = (pp.Suppress("λ") | pp.Suppress("\\")) + pp_name + pp.Suppress(".") + pp_expr pp_lambda_fun.set_parse_action(tokens.lambda_func.from_parse) # Assignment. # Can only be found at the start of a line. # # = - pp_macro_def = pp.line_start() + pp_name + macro_char + pp_expr + pp_macro_def = pp.line_start() + pp_name + pp.Suppress("=") + pp_expr pp_macro_def.set_parse_action(tokens.macro_expression.from_parse) # Function calls. @@ -50,15 +48,21 @@ class Parser: pp_expr <<= pp_lambda_fun ^ (lp + pp_expr + rp) ^ pp_name ^ (lp + pp_call + rp) pp_all = pp_expr | pp_macro_def - @staticmethod - def parse_expression(line): - return Parser.pp_expr.parse_string(line, parse_all = True)[0] + pp_command = ":" + pp_name + pp_command.set_parse_action(tokens.command.from_parse) @staticmethod - def parse_assign(line): - return ( - Parser.pp_macro_def - ).parse_string(line, parse_all = True)[0] + def parse_line(line): + k = ( + Parser.pp_expr ^ + Parser.pp_macro_def ^ + Parser.pp_command ^ Parser.pp_call + ).parse_string( + line, + parse_all = True + )[0] + print(k) + return(k) @staticmethod def run_tests(lines):