From b8571d32ab934bf275878ff136487c8b5bc505b5 Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Mon, 19 May 2025 23:56:46 +0200 Subject: Support for parenthesis inside macro arguments --- ppc.fun | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'ppc.fun') diff --git a/ppc.fun b/ppc.fun index 0aae7b6..23684ab 100644 --- a/ppc.fun +++ b/ppc.fun @@ -579,15 +579,26 @@ struct (tk, pos, ppc) end - fun parseArg ppc acc = + fun parseArg level ppc acc = let val (tk, pos, ppc) = getTokenRestricted ppc + fun continue dx = parseArg (level + dx) ppc ((tk, pos) :: acc) in case tk of T.EOS => error mPos `"unfinished argument list" % - | T.Coma => (true, rev acc, ppc) - | T.RParen => (false, rev acc, ppc) - | _ => parseArg ppc ((tk, pos) :: acc) + | T.LParen => continue 1 + | T.Coma => + if level > 0 then + continue 0 + else + (true, rev acc, ppc) + | T.RParen => + if level > 0 then + continue (~1) + else + (false, rev acc, ppc) + | T.NewLine => parseArg level ppc acc + | _ => continue 0 end fun parseArgs ppc params acc = @@ -595,7 +606,7 @@ struct fun bind _ [] = error mPos `"too many arguments" % | bind body (param :: params) = ((param, body), params) - val (continue, arg, ppc) = parseArg ppc [] + val (continue, arg, ppc) = parseArg 0 ppc [] val (bindedParam, otherParams) = bind arg params in if continue then @@ -941,6 +952,15 @@ struct updatePpc P u#buffer (updateH head) % end + and getTokenSkipNL ppc = + let + val (tk, pos, ppc) = getToken ppc + in + case tk of + T.NewLine => getTokenSkipNL ppc + | _ => (tk, pos, ppc) + end + fun debugPrint' (out, cache, ppc) = let val (tk, pos, ppc) = getToken ppc @@ -960,16 +980,5 @@ struct end fun getClass ppc clList = - let - fun getTokenSkipNL ppc = - let - val (tk, pos, ppc) = getToken ppc - in - case tk of - T.NewLine => getTokenSkipNL ppc - | _ => (tk, pos, ppc) - end - in getClassGeneric clList getTokenSkipNL ppc - end end -- cgit v1.2.3