From 3a3f1765abb9f10eff6f2b3bd8e97ef358d3bdae Mon Sep 17 00:00:00 2001 From: Alexander Nutz Date: Sun, 31 Aug 2025 11:20:06 +0200 Subject: [PATCH] c --- example.lsp | 67 ++++++++++++++++++++++++++++++++++++++++++++++------- sexpr.ml | 6 +++++ 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/example.lsp b/example.lsp index bda5a78..ec7e645 100644 --- a/example.lsp +++ b/example.lsp @@ -1,21 +1,72 @@ (:macro seq ()) +(:macro c-not ( c ) + ) +; works because this has a higher constraints score: +(:macro c-not ( (c (:c-eq () _)) ) + ()) + +(:macro seq-exp (hd) + (':ot (':str-cat "- " (':t2ot-elt hd)))) +(:macro seq-exp (hd .. tl) + (':seq-exp hd) (':seq-exp tl)) + (:macro seq (hd) - (:t "- " hd)) - + (':t (':seq-exp hd))) (:macro seq (hd .. tl) - (:t (':seq hd) (':seq tl))) + (':t (':seq-exp hd tl))) -(:macro @ ( (k(:c-atm _)) ) - (:t k ":")) +(:macro c-paren-eval ()) +(:macro c-paren-eval (x) + (':c-atm x) + (':c-not (':c-colon-id x))) -(:macro @ ( (k(:c-atm _)) v ) - (:t k ": " v)) +(:macro @ ( (k(:c-paren-eval _)) ) + (':t (':str-cat (':t2ot-elt k) ":"))) -(:macro @ ( (k(:c-atm _)) v .. other) +(:macro @ ( (k(:c-paren-eval _)) v ) + (':t k ": " v)) + +(:macro @ ( (k(:c-paren-eval _)) (v(:c-atm _)) ) + (':t (':str-cat (':str-cat (':atm-to-str k) ": ") (':atm-to-str v) ))) + +(:macro @ ( (k(:c-paren-eval _)) v .. other) (k v) other) +(:macro t2ot-elt ( hd ) + (':atm-to-str hd)) + +(:macro t2ot-elt ( hd .. tl ) + (':tree + (':t2ot-elt hd) + (':t2ot-elt tl))) + +(:macro t () (':ot)) +(:macro t ( .. tl ) + (':ot + (':t2ot-elt tl))) + +(:macro ot ( x ) + (':yot (':indent x))) + +(:macro indent ( (x(:c-str _)) ) + (':str-cat " " x)) + +(:macro indent ( (hd(:c-atm _)) .. tl ) + (':indent hd) + (':indent tl)) + +(:macro indent-each ( hd .. tl ) + (':indent hd) + (':indent tl)) + +(:macro rm-first (x .. tl) + tl) + +(:macro indent ( (x(:c-li0-eq _ :tree)) ) + (':tree (':indent-each (':rm-first (':unpack x))))) + (name "Complex CI/CD Pipeline") (on diff --git a/sexpr.ml b/sexpr.ml index 88a70e0..b42782a 100644 --- a/sexpr.ml +++ b/sexpr.ml @@ -735,8 +735,12 @@ module SExprMacroExp = struct li1 (Str (Float.to_string x)), true, ctx | Cons(Id ":str-cat", Cons(Str l, Cons(Str r, Nil))) -> li1 (Str (l ^ r)), true, ctx + | Cons(Id ":unpack", Cons(x, Nil)) when is_list x -> + x, true, ctx | Cons(Id ":c-eq", Cons(l, Cons(r, Nil))) when l = r -> Nil, true, ctx + | Cons(Id ":c-li0-eq", Cons( Cons(l, _) , Cons( r , Nil))) when l = r -> + Nil, true, ctx | Cons(Id ":c-int", Cons(Int _, Nil)) -> Nil, true, ctx | Cons(Id ":c-float", Cons(Flt _, Nil)) -> @@ -748,6 +752,8 @@ module SExprMacroExp = struct Nil, true, ctx | Cons(Id ":c-id", Cons(Id _, Nil)) -> Nil, true, ctx + | Cons(Id ":c-colon-id", Cons(Id x, Nil)) when String.contains x ':' -> + Nil, true, ctx | Cons(Id ":c-list", Cons(x, Nil)) when is_list x -> Nil, true, ctx | Cons(Id ":c-atm", Cons(Int _, Nil))