Skip to content

Commit

Permalink
core: Support YeS expr on LHS of YeS pair
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Sep 6, 2024
1 parent 9b1d88f commit 2f9a3d0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
22 changes: 11 additions & 11 deletions core/src/yamlscript/ast.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
22 changes: 17 additions & 5 deletions core/src/yamlscript/constructor.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion core/test/compiler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,6 @@
clojure: |
(get+ (DBG foo) 'bar)
- name: Error Clojure style comments
yamlscript: |
!yamlscript/v0
Expand Down Expand Up @@ -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)

0 comments on commit 2f9a3d0

Please sign in to comment.