Changed parsing syntax

master
Mark 2022-10-21 14:41:24 -07:00
parent 5f4f3db48f
commit f8ff0a0c3e
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 15 additions and 11 deletions

View File

@ -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.
#
# <var> => <exp>
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.
#
# <var> = <exp>
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):