File tree Expand file tree Collapse file tree 17 files changed +440
-46
lines changed
Expand file tree Collapse file tree 17 files changed +440
-46
lines changed Original file line number Diff line number Diff line change 11{
22 "calva.fmt.configPath" : " .cljfmt.edn" ,
33 "cSpell.words" : [
4+ " concat" ,
45 " cond" ,
6+ " defmacro" ,
57 " defn" ,
8+ " doall" ,
69 " fizzbuzz" ,
710 " mapv" ,
811 " yamlscript"
Original file line number Diff line number Diff line change 11
2+ - version: 0.1.29
3+ date: Wed Dec 20 10:12:44 AM PST 2023
4+ changes:
5+ - core: Support --native for compiling YS to machine code
6+
27- version: 0.1.28
38 date: Mon Dec 18 08:57:06 AM PST 2023
49 changes:
Original file line number Diff line number Diff line change @@ -8,8 +8,8 @@ export PATH := $(GRAALVM_HOME)/bin:$(PATH)
88YAMLSCRIPT_LANG_INSTALLED := \
99 $(HOME ) /.m2/repository/yamlscript/core/maven-metadata-local.xml
1010YAMLSCRIPT_CORE_SRC := \
11- ../core/src/yamlscript/* \
12- ../core/src/ys/* \
11+ ../core/src/yamlscript/*.clj \
12+ ../core/src/ys/*.clj \
1313
1414ifdef w
1515 export WARN_ON_REFLECTION := 1
Original file line number Diff line number Diff line change 3333
3434(defn Key [s] {:Key (keyword s)})
3535
36+ (defn Tok [s] {:Tok (str s)})
37+
3638(defn Bln [b]
3739 (if (re-matches #"(true|True|TRUE)" b)
3840 {:Bln true }
Original file line number Diff line number Diff line change 127127 (keys (get-declares node defn-names )))
128128 form (Lst (cons (Sym 'declare) declares))]
129129 (if (seq declares)
130- (update-in node [:Top ]
131- #(vec (concat [form] %)))
130+ (if (= 'ns (get-in node [:Top 0 :Lst 0 :Sym ]))
131+ (update-in node [:Top ]
132+ #(vec (concat [(first %)] [form] (rest %))))
133+ (update-in node [:Top ]
134+ #(vec (concat [form] %))))
132135 node)))
133136
134137(def call-main
Original file line number Diff line number Diff line change 77(ns yamlscript.printer
88 (:use yamlscript.debug)
99 (:require
10- [clojure.edn :as edn]
1110 [clojure.string :as str]
12- [clojure.pprint :as pp]
13- [yamlscript.builder :as builder]
14- [clj-yaml.core :as yaml])
11+ [clojure.pprint :as pp])
1512 (:refer-clojure :exclude [print]))
1613
1714(def string-escape
5148 :Chr (str " \\ " val)
5249 :Spc (str/replace val #"::" " ." )
5350 :Sym (str val)
51+ :Tok (str val)
5452 :Key (str val)
5553 :Int (str val)
5654 :Flt (str val)
6058 (Exception. (str " Unknown AST node type:"
6159 node))))))
6260
63- (defn pretty-format [s]
64- (str
65- (with-out-str (pp/write s))
66- " \n " ))
61+ (defn pretty-format [code]
62+ (->> code
63+ (#(str " (do " % " \n )\n " ))
64+ read-string
65+ rest
66+ (map #(str
67+ (with-out-str (pp/write %))
68+ " \n " ))
69+ (str/join " " )))
70+
6771
6872(defn print
6973 " Render a YAMLScript AST as Clojure code."
7276 code (->> list
7377 (map print-node)
7478 (str/join " \n " )
75- (#(str " (do " % " \n )\n " ))
76- edn/read-string
77- rest
78- (map pretty-format)
79- (str/join " " ))]
79+ pretty-format)]
8080 code))
8181
8282(comment
8383 (print :Empty )
84+ (read-string "
85+ (defmacro each [bindings & body]
86+ `(do
87+ (doall (for [~@bindings] (do ~@body)))
88+ nil)))" )
8489 (print
8590 {:Lst [{:Sym 'a} {:Sym 'b} {:Sym 'c}]})
8691 (print {:Map [{:Str " foo" } {:Str " \\ a" }]})
Original file line number Diff line number Diff line change 6464(def pkey (re #"(?:$symw|$pnum|$strg)" )) ; Path key
6565(def path (re #"(?:$symw(?:\. $pkey)+)" )) ; Lookup path
6666(def keyw (re #"(?:\: $symw)" )) ; Keyword token
67- (def symb (re #"(?:$symw[?!]?)" )) ; Symbol token
67+ (def symb (re #"(?:_[*+.]| $symw[?!]?)" )) ; Symbol token
6868(def nspc (re #"(?:$symw(?:\:\: $symw)+)" )) ; Namespace symbol
6969(def fqsm (re #"(?:$nspc\. $symb)" )) ; Fully qualified symbol
7070 ; Symbol followed by paren
Original file line number Diff line number Diff line change 2929(def ys-ys (sci/create-ns 'ys))
3030(def ys-ys-vars (sci/copy-ns ys.ys ys-ys))
3131
32- cast unquote-splicing update-keys update-vals
33-
3432(def argv (sci/new-dynamic-var 'ARGV nil ))
3533(def env (sci/new-dynamic-var 'ENV nil ))
3634
Original file line number Diff line number Diff line change 4040(defn is-quote? [token]
4141 (and token (= " '" (str token))))
4242
43+ (defn is-syntax-quote? [token]
44+ (and token (= " `" (str token))))
45+
46+ (defn is-unquote-splice? [token]
47+ (and token (= " ~@" (str token))))
48+
4349(defn is-string? [token]
4450 (and token (re-matches re/strg (str token))))
4551
6975 $fqsm | # Fully qualified symbol
7076 $nspc | # Namespace symbol
7177 $path | # Lookup path
78+ $lnum | # Number token
7279 $symb | # Symbol token
7380 $oper | # Operator token
7481 $char | # Character token
195202 (is-string? %) (Str (normalize-string %))
196203 :else (throw (Exception. (str " Invalid path token: " %))))
197204 keys)
198- form (cons (Sym '_. ) (cons (Sym value) form))]
205+ form (cons (Sym '__ ) (cons (Sym value) form))]
199206 (Lst form)))
200207
201208(defn read-scalar [[token & tokens]]
214221 [(Sym n) tokens])
215222 (is-number? token) [(Int token) tokens]
216223 (is-operator? token) [(Sym token) tokens]
224+ (is-unquote-splice? token) [(Tok token) tokens]
225+ (is-syntax-quote? token) [(Tok token) tokens]
217226 (is-string? token) [(Str (normalize-string token)) tokens]
218227 (is-keyword? token) [(Key (subs token 1 )) tokens]
219228 (is-character? token) [(Chr (subs token 1 )) tokens]
Original file line number Diff line number Diff line change 2222(defn zzz [& xs]
2323 (apply yamlscript.debug/zzz xs))
2424
25- (defn toB [x] boolean x )
25+ (defn toBoo [x] boolean x )
2626
27- (defn toF [x] (parse-double x))
27+ (defn toFlt [x] (parse-double x))
2828
29- (defn toI [x] (parse-long x))
29+ (defn toInt [x] (parse-long x))
3030
31- (defn toM
31+ (defn toMap
3232 ([] {})
3333 ([x] (apply hash-map x))
3434 ([k v & xs] (apply hash-map k v xs)))
3535
36- (defn toS [& xs] (apply str xs))
37-
38- (defn => [this] this )
36+ (defn toStr [& xs] (apply str xs))
3937
4038(defn _get [coll key]
4139 (if (string? key)
4442 (get coll key))
4543 )
4644
47- (defn _. [x & xs]
45+ (defn __ [x & xs]
4846 (reduce _get x xs))
4947
5048(defn _+ [x & xs]
You can’t perform that action at this time.
0 commit comments