From 2f9a3d0038cf9e6b6f582c6ffb650fe962e0f221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Thu, 5 Sep 2024 21:43:34 -0700 Subject: [PATCH] core: Support YeS expr on LHS of YeS pair --- core/src/yamlscript/ast.clj | 22 +++++++++++----------- core/src/yamlscript/constructor.clj | 22 +++++++++++++++++----- core/test/compiler.yaml | 9 ++++++++- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/core/src/yamlscript/ast.clj b/core/src/yamlscript/ast.clj index a16c4d74..09a9de8a 100644 --- a/core/src/yamlscript/ast.clj +++ b/core/src/yamlscript/ast.clj @@ -67,19 +67,19 @@ {:Clj c}) (def operators - {(Sym '.) (Sym '_dot_) - (Sym '..) (Sym 'rng) - (Sym '+) (Sym 'add+) - (Sym '*) (Sym 'mul+) - (Sym '/) (Sym 'div+) - (Sym '!=) (Sym 'not=) - (Sym '||) (Sym 'or) - (Sym '&&) (Sym 'and) + {(Sym '.) (Sym '_dot_) + (Sym '..) (Sym 'rng) + (Sym '+) (Sym 'add+) + (Sym '*) (Sym 'mul+) + (Sym '/) (Sym 'div+) + (Sym '!=) (Sym 'not=) + (Sym '||) (Sym 'or) + (Sym '&&) (Sym 'and) (Sym '|||) (Sym 'or?) (Sym '&&&) (Sym 'and?) - (Sym '%) (Sym 'rem) - (Sym '%%) (Sym 'mod) - (Sym '**) (Sym 'pow)}) + (Sym '%) (Sym 'rem) + (Sym '%%) (Sym 'mod) + (Sym '**) (Sym 'pow)}) (comment [(Lst [1 2 3]) diff --git a/core/src/yamlscript/constructor.clj b/core/src/yamlscript/constructor.clj index df4117ab..c3697b45 100644 --- a/core/src/yamlscript/constructor.clj +++ b/core/src/yamlscript/constructor.clj @@ -69,16 +69,28 @@ (concat [(Sym 'apply)] [fun] new splats))))) nodes)) -(defn apply-yes [key val] +(defn apply-yes-lhs [key val] (if-lets [_ (vector? key) - _ (= 2 (count key)) - _ (map? val) - [a b] key + _ (= 4 (count key)) + [a b c d] key + _ (re-matches re/osym (str (:Sym d))) _ (re-matches re/osym (str (:Sym b))) b (or (ast/operators b) b)] - [[b a] val] + [[(Lst [b a c]) d] val] [key val])) + #_(YSC "=>: foo.>.bar") +(defn apply-yes [key val] + (let [[key val] (apply-yes-lhs key val)] + (if-lets [_ (vector? key) + _ (= 2 (count key)) + _ (map? val) + [a b] key + _ (re-matches re/osym (str (:Sym b))) + b (or (ast/operators b) b)] + [[b a] val] + [key val]))) + (defn construct-call [[key val]] (let [[key val] (apply-yes key val)] (cond diff --git a/core/test/compiler.yaml b/core/test/compiler.yaml index ae3ab298..7d13169d 100644 --- a/core/test/compiler.yaml +++ b/core/test/compiler.yaml @@ -1168,7 +1168,6 @@ clojure: | (get+ (DBG foo) 'bar) - - name: Error Clojure style comments yamlscript: | !yamlscript/v0 @@ -1399,3 +1398,11 @@ (def a (fn [& args] nil)) (def b (fn [& _] nil)) (def c (fn c [& _] nil)) + + +- name: YeS in LHS or YeS pair + yamlscript: | + !yamlscript/v0 + a && b ||: c + clojure: | + (or (and a b) c)