Compare commits
No commits in common. "84e33567583917c975b7539e4062d79ac9c62eb0" and "feb02dc1b6990416da619ab3511b7ed4c576e91c" have entirely different histories.
84e3356758
...
feb02dc1b6
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@ludus/ludus-js-pure",
|
"name": "@ludus/ludus-js-pure",
|
||||||
"version": "0.1.0-alpha.7.7",
|
"version": "0.1.0-alpha.7.6",
|
||||||
"description": "A Ludus interpreter in a pure JS function.",
|
"description": "A Ludus interpreter in a pure JS function.",
|
||||||
"main": "target/js/ludus.js",
|
"main": "target/js/ludus.js",
|
||||||
"directories": {},
|
"directories": {},
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
the_line (nth lines (dec line))]
|
the_line (nth lines (dec line))]
|
||||||
the_line))
|
the_line))
|
||||||
|
|
||||||
(string/split-lines "abcd")
|
|
||||||
|
|
||||||
(defn get-underline [source {:keys [line start lexeme]} prefix]
|
(defn get-underline [source {:keys [line start lexeme]} prefix]
|
||||||
(let [lines (string/split-lines source)
|
(let [lines (string/split-lines source)
|
||||||
lines-before (subvec lines 0 (dec line))
|
lines-before (subvec lines 0 (dec line))
|
||||||
|
@ -39,4 +37,3 @@
|
||||||
(str "Ludus panicked on line " line ":\n" (get-line source {:line line}) "\n" message)
|
(str "Ludus panicked on line " line ":\n" (get-line source {:line line}) "\n" message)
|
||||||
(str "Ludus panicked!\n" message)
|
(str "Ludus panicked!\n" message)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,11 @@
|
||||||
(quiet :rbrace)
|
(quiet :rbrace)
|
||||||
])
|
])
|
||||||
|
|
||||||
; (defp struct-pattern group order-1 [(quiet :startstruct)
|
(defp struct-pattern group order-1 [(quiet :startstruct)
|
||||||
; (quiet (zero+ separator))
|
(quiet (zero+ separator))
|
||||||
; (zero+ dict-pattern-entry)
|
(zero+ dict-pattern-entry)
|
||||||
; (quiet :rbrace)
|
(quiet :rbrace)
|
||||||
; ])
|
])
|
||||||
|
|
||||||
(defp guard order-0 [(quiet :if) simple])
|
(defp guard order-0 [(quiet :if) simple])
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
:else
|
:else
|
||||||
tuple-pattern
|
tuple-pattern
|
||||||
dict-pattern
|
dict-pattern
|
||||||
;struct-pattern
|
struct-pattern
|
||||||
list-pattern])
|
list-pattern])
|
||||||
|
|
||||||
(defp match-clause group weak-order [pattern (maybe guard) (quiet :rarrow) expression])
|
(defp match-clause group weak-order [pattern (maybe guard) (quiet :rarrow) expression])
|
||||||
|
@ -141,15 +141,14 @@
|
||||||
|
|
||||||
(defp pair group order-0 [:keyword non-binding])
|
(defp pair group order-0 [:keyword non-binding])
|
||||||
|
|
||||||
;; "struct-term" and "struct-entry" are necessary for nses
|
|
||||||
(defp struct-term flat choice [:word pair])
|
(defp struct-term flat choice [:word pair])
|
||||||
|
|
||||||
(defp struct-entry order-1 [struct-term separators])
|
(defp struct-entry order-1 [struct-term separators])
|
||||||
|
|
||||||
; (defp struct-literal group order-1 [(quiet :startstruct)
|
(defp struct-literal group order-1 [(quiet :startstruct)
|
||||||
; (quiet (zero+ separator))
|
(quiet (zero+ separator))
|
||||||
; (zero+ struct-entry)
|
(zero+ struct-entry)
|
||||||
; (quiet :rbrace)])
|
(quiet :rbrace)])
|
||||||
|
|
||||||
(defp dict-term flat choice [splat :word pair])
|
(defp dict-term flat choice [splat :word pair])
|
||||||
|
|
||||||
|
@ -231,8 +230,7 @@
|
||||||
|
|
||||||
(defp repeat-expr group order-1 [(quiet :repeat) (choice :times [:word :number]) block])
|
(defp repeat-expr group order-1 [(quiet :repeat) (choice :times [:word :number]) block])
|
||||||
|
|
||||||
(defp collection flat choice [;struct-literal
|
(defp collection flat choice [struct-literal dict list-literal set-literal tuple])
|
||||||
dict list-literal set-literal tuple])
|
|
||||||
|
|
||||||
(defp simple flat choice [literal collection synthetic recur-call lambda])
|
(defp simple flat choice [literal collection synthetic recur-call lambda])
|
||||||
|
|
||||||
|
|
|
@ -442,7 +442,7 @@
|
||||||
(throw (ex-info (str "Struct error: no member at " kw) {:ast kw}))))
|
(throw (ex-info (str "Struct error: no member at " kw) {:ast kw}))))
|
||||||
(get map kw))))))
|
(get map kw))))))
|
||||||
|
|
||||||
(defn- call-fn [lfn args ctx from]
|
(defn- call-fn [lfn args ctx]
|
||||||
;(println "Calling function " (:name lfn))
|
;(println "Calling function " (:name lfn))
|
||||||
(cond
|
(cond
|
||||||
(= ::data/partial (first args))
|
(= ::data/partial (first args))
|
||||||
|
@ -452,8 +452,7 @@
|
||||||
(call-fn
|
(call-fn
|
||||||
lfn
|
lfn
|
||||||
(into [::data/tuple] (replace {::data/placeholder arg} (rest args)))
|
(into [::data/tuple] (replace {::data/placeholder arg} (rest args)))
|
||||||
ctx
|
ctx))}
|
||||||
from))}
|
|
||||||
|
|
||||||
(= (::data/type lfn) ::data/clj) (apply (:body lfn) (next args))
|
(= (::data/type lfn) ::data/clj) (apply (:body lfn) (next args))
|
||||||
|
|
||||||
|
@ -493,7 +492,7 @@
|
||||||
(interpret-ast body fn-ctx)))
|
(interpret-ast body fn-ctx)))
|
||||||
(recur (first clauses) (rest clauses))))
|
(recur (first clauses) (rest clauses))))
|
||||||
|
|
||||||
(throw (ex-info (str "Match Error: No match found for " (show/show args) " in function " (:name lfn)) {:ast from})))))
|
(throw (ex-info (str "Match Error: No match found for " (show/show args) " in function " (:name lfn)) {:ast (:ast lfn)})))))
|
||||||
|
|
||||||
(keyword? lfn)
|
(keyword? lfn)
|
||||||
(if (= 2 (count args))
|
(if (= 2 (count args))
|
||||||
|
@ -532,7 +531,7 @@
|
||||||
(throw (ex-info (str "Namespace error: no member " (:value curr) " in ns " (::data/name prev-value)) {:ast curr}))
|
(throw (ex-info (str "Namespace error: no member " (:value curr) " in ns " (::data/name prev-value)) {:ast curr}))
|
||||||
(throw (ex-info (str "Struct error: no member " (:value curr)) {:ast curr}))))
|
(throw (ex-info (str "Struct error: no member " (:value curr)) {:ast curr}))))
|
||||||
(get prev-value (first data)))
|
(get prev-value (first data)))
|
||||||
(call-fn prev-value (interpret-args data ctx) ctx curr))))
|
(call-fn prev-value (interpret-args data ctx) ctx))))
|
||||||
|
|
||||||
(defn- interpret-synthetic [ast ctx]
|
(defn- interpret-synthetic [ast ctx]
|
||||||
;;(println "interpreting synthetic " ast)
|
;;(println "interpreting synthetic " ast)
|
||||||
|
@ -607,7 +606,7 @@
|
||||||
(let [data (:data ast)
|
(let [data (:data ast)
|
||||||
root (interpret-ast (first data) ctx)
|
root (interpret-ast (first data) ctx)
|
||||||
fns (rest data)]
|
fns (rest data)]
|
||||||
(reduce #(call-fn (interpret-ast %2 ctx) [::data/tuple %1] ctx ast) root fns)))
|
(reduce #(call-fn (interpret-ast %2 ctx) [::data/tuple %1] ctx) root fns)))
|
||||||
|
|
||||||
(defn- map-values [f]
|
(defn- map-values [f]
|
||||||
(map (fn [kv]
|
(map (fn [kv]
|
||||||
|
@ -774,9 +773,9 @@
|
||||||
:pair (let [data (:data member) k (-> data first :data first) v (second data)]
|
:pair (let [data (:data member) k (-> data first :data first) v (second data)]
|
||||||
(assoc struct k (interpret-ast v ctx))))))
|
(assoc struct k (interpret-ast v ctx))))))
|
||||||
|
|
||||||
; (defn- interpret-struct [ast ctx]
|
(defn- interpret-struct [ast ctx]
|
||||||
; (let [members (:data ast)]
|
(let [members (:data ast)]
|
||||||
; (assoc (reduce (struct-term ctx) {} members) ::data/struct true)))
|
(assoc (reduce (struct-term ctx) {} members) ::data/struct true)))
|
||||||
|
|
||||||
(defn- ns-term [ctx]
|
(defn- ns-term [ctx]
|
||||||
(fn [ns member]
|
(fn [ns member]
|
||||||
|
@ -883,8 +882,8 @@
|
||||||
|
|
||||||
:dict (interpret-dict ast ctx)
|
:dict (interpret-dict ast ctx)
|
||||||
|
|
||||||
; :struct-literal
|
:struct-literal
|
||||||
; (interpret-struct ast ctx)
|
(interpret-struct ast ctx)
|
||||||
|
|
||||||
(throw (ex-info (str "Unknown AST node type " (get ast :type :err) " on line " (get-in ast [:token :line])) {:ast ast}))))
|
(throw (ex-info (str "Unknown AST node type " (get ast :type :err) " on line " (get-in ast [:token :line])) {:ast ast}))))
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,7 @@
|
||||||
(defn run [source]
|
(defn run [source]
|
||||||
(let [user_scanned (s/scan source)
|
(let [user_scanned (s/scan source)
|
||||||
user_tokens (:tokens user_scanned)
|
user_tokens (:tokens user_scanned)
|
||||||
_ (println "Tokens: " user_tokens)
|
|
||||||
user_parsed (p/apply-parser g/script user_tokens)
|
user_parsed (p/apply-parser g/script user_tokens)
|
||||||
_ (println "Ast: " (i/prettify-ast user_parsed))
|
|
||||||
user_result (i/interpret-safe source user_parsed {})
|
user_result (i/interpret-safe source user_parsed {})
|
||||||
result_str (show/show user_result)
|
result_str (show/show user_result)
|
||||||
post_scanned (s/scan pre/postlude)
|
post_scanned (s/scan pre/postlude)
|
||||||
|
@ -59,4 +57,3 @@
|
||||||
(clean-out clj_result)
|
(clean-out clj_result)
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
|
@ -920,7 +920,7 @@ fn assert! {
|
||||||
|
|
||||||
& some basic colors
|
& some basic colors
|
||||||
&&& TODO: add colors
|
&&& TODO: add colors
|
||||||
let colors = #{
|
let colors = @{
|
||||||
:white (255, 255, 255, 255)
|
:white (255, 255, 255, 255)
|
||||||
:light_gray (150, 150, 150, 255)
|
:light_gray (150, 150, 150, 255)
|
||||||
:dark_gray (50, 50, 50, 255)
|
:dark_gray (50, 50, 50, 255)
|
||||||
|
|
|
@ -281,10 +281,10 @@
|
||||||
(add-token (advance scanner) :startset)
|
(add-token (advance scanner) :startset)
|
||||||
(add-error scanner (str "Expected beginning of set: ${. Got " char next)))
|
(add-error scanner (str "Expected beginning of set: ${. Got " char next)))
|
||||||
|
|
||||||
;; struct @{: Deleted from the language in December 2023
|
;; struct @{
|
||||||
; \@ (if (= next \{)
|
\@ (if (= next \{)
|
||||||
; (add-token (advance scanner) :startstruct)
|
(add-token (advance scanner) :startstruct)
|
||||||
; (add-error scanner (str "Expected beginning of struct: @{. Got " char next)))
|
(add-error scanner (str "Expected beginning of struct: @{. Got " char next)))
|
||||||
|
|
||||||
;; placeholders
|
;; placeholders
|
||||||
;; there's a flat _, and then ignored words
|
;; there's a flat _, and then ignored words
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
51500
|
|
Loading…
Reference in New Issue
Block a user