repeat until not changed anymore
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
(:t "- " hd))
|
(:t "- " hd))
|
||||||
|
|
||||||
(:macro seq (hd .. tl)
|
(:macro seq (hd .. tl)
|
||||||
(':seq hd) (':seq tl))
|
(:t (':seq hd) (':seq tl)))
|
||||||
|
|
||||||
(:macro @ (k)
|
(:macro @ (k)
|
||||||
(:t k ":"))
|
(:t k ":"))
|
||||||
|
37
sexpr.ml
37
sexpr.ml
@@ -687,12 +687,18 @@ module SExprMacroExp = struct
|
|||||||
|
|
||||||
let rec eval (ctx: (string * (SExpr.t * SExpr.t)) list) s =
|
let rec eval (ctx: (string * (SExpr.t * SExpr.t)) list) s =
|
||||||
let open SExpr in
|
let open SExpr in
|
||||||
let s, ctx = if is_list s then
|
let s, ch1, ctx = if is_list s then begin
|
||||||
aggr_flat_map eval ctx s
|
let s, (ch,ctx) = aggr_flat_map (fun aggr s ->
|
||||||
else
|
let ch1, ctx = aggr in
|
||||||
s, ctx
|
let s, ch2, ctx = eval ctx s in
|
||||||
|
s, ((ch1 || ch2), ctx)
|
||||||
|
) (false, ctx) s in
|
||||||
|
s, ch, ctx
|
||||||
|
end else
|
||||||
|
s, false, ctx
|
||||||
in
|
in
|
||||||
check_expands_while ctx s
|
let s, ch2, ctx = check_expands ctx s in
|
||||||
|
s, (ch1 || ch2), ctx
|
||||||
(* expr -> list(new exprs) * bool:changed * ctx *)
|
(* expr -> list(new exprs) * bool:changed * ctx *)
|
||||||
and check_expands ctx s =
|
and check_expands ctx s =
|
||||||
let open SExpr in
|
let open SExpr in
|
||||||
@@ -726,12 +732,6 @@ module SExprMacroExp = struct
|
|||||||
end
|
end
|
||||||
in
|
in
|
||||||
test (assoc_all i ctx) ctx
|
test (assoc_all i ctx) ctx
|
||||||
and check_expands_while ctx s =
|
|
||||||
let s', c, ctx' = check_expands ctx s in
|
|
||||||
if c then
|
|
||||||
SExpr.aggr_flat_map check_expands_while ctx' s'
|
|
||||||
else
|
|
||||||
s', ctx'
|
|
||||||
and match_macro_arg args margs =
|
and match_macro_arg args margs =
|
||||||
let open SExpr in
|
let open SExpr in
|
||||||
match args, margs with
|
match args, margs with
|
||||||
@@ -765,12 +765,21 @@ module SExprMacroExp = struct
|
|||||||
else
|
else
|
||||||
perfm expr
|
perfm expr
|
||||||
and expand_macro args macro =
|
and expand_macro args macro =
|
||||||
let (margs, mbody) = macro in
|
let margs, mbody = macro in
|
||||||
let defs = match_macro_arg args margs in
|
let defs = match_macro_arg args margs in
|
||||||
expand_macro_eval mbody defs
|
expand_macro_eval mbody defs
|
||||||
let do_eval s =
|
|
||||||
eval [] s
|
let do_eval s = begin
|
||||||
|
let rec inner ctx s = begin
|
||||||
|
let s, ch, ctx = eval ctx s in
|
||||||
|
if ch then
|
||||||
|
SExpr.aggr_flat_map inner ctx s
|
||||||
|
else
|
||||||
|
s, ctx
|
||||||
|
end in
|
||||||
|
inner [] s
|
||||||
|> fst
|
|> fst
|
||||||
|
end
|
||||||
|
|
||||||
(* only use this for testing! *)
|
(* only use this for testing! *)
|
||||||
let sparse src =
|
let sparse src =
|
||||||
|
Reference in New Issue
Block a user