fix string interpolation, prelude bugs
This commit is contained in:
parent
a6e2e11e4a
commit
4d0a37328d
41
prelude.ld
41
prelude.ld
|
@ -249,33 +249,32 @@ fn concat {
|
|||
& the console: sending messages to the outside world
|
||||
& the console is *both* something we send to the host language's console
|
||||
& ...and also a list of messages.
|
||||
box console = []
|
||||
& box console = []
|
||||
|
||||
fn flush! {
|
||||
"Clears the console, and returns the messages."
|
||||
() -> {
|
||||
let msgs = unbox (console)
|
||||
store! (console, [])
|
||||
msgs
|
||||
}
|
||||
}
|
||||
& fn flush! {
|
||||
& "Clears the console, and returns the messages."
|
||||
& () -> {
|
||||
& let msgs = unbox (console)
|
||||
& store! (console, [])
|
||||
& msgs
|
||||
& }
|
||||
& }
|
||||
|
||||
fn add_msg! {
|
||||
"Adds a message to the console."
|
||||
(msg as :string) -> update! (console, append (_, msg))
|
||||
(msgs as :list) -> {
|
||||
base :print! (("adding msg", msgs))
|
||||
let msg = do msgs > map (string, _) > join
|
||||
base :print! (("msg: ", msg))
|
||||
update! (console, append (_, msg))
|
||||
}
|
||||
}
|
||||
& fn add_msg! {
|
||||
& "Adds a message to the console."
|
||||
& (msg as :string) -> update! (console, append (_, msg))
|
||||
& (msgs as :list) -> {
|
||||
& base :print! (("adding msg", msgs))
|
||||
& let msg = do msgs > map (string, _) > join
|
||||
& base :print! (("msg: ", msg))
|
||||
& update! (console, append (_, msg))
|
||||
& }
|
||||
& }
|
||||
|
||||
fn print! {
|
||||
"Sends a text representation of Ludus values to the console."
|
||||
(...args) -> {
|
||||
base :print! (args)
|
||||
& add_msg! (args)
|
||||
:ok
|
||||
}
|
||||
}
|
||||
|
@ -1306,7 +1305,6 @@ pkg Prelude {
|
|||
coll?
|
||||
colors
|
||||
concat
|
||||
console
|
||||
cos
|
||||
count
|
||||
dec
|
||||
|
@ -1332,7 +1330,6 @@ pkg Prelude {
|
|||
filter
|
||||
first
|
||||
floor
|
||||
flush!
|
||||
fn?
|
||||
fold
|
||||
forward!
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
(print source-line))
|
||||
|
||||
(defn runtime-error [e]
|
||||
(when (= :string (type e)) (print e) (break e))
|
||||
(when (= :string (type e)) (print (string "Internal Ludus error: " e)) (break e))
|
||||
(def msg (e :msg))
|
||||
(case msg
|
||||
"no match: function call" (fn-no-match e)
|
||||
|
|
|
@ -251,7 +251,9 @@
|
|||
(interpret last-line ctx))
|
||||
|
||||
(defn- to_string [ctx] (fn [x]
|
||||
(b/stringify (interpret x ctx))))
|
||||
(if (buffer? x)
|
||||
(string x)
|
||||
(b/stringify (interpret x ctx)))))
|
||||
|
||||
(defn- interpolated [ast ctx]
|
||||
(def terms (ast :data))
|
||||
|
@ -620,9 +622,9 @@
|
|||
(set interpret interpret*)
|
||||
|
||||
# # repl
|
||||
# (import ./scanner :as s)
|
||||
# (import ./parser :as p)
|
||||
# (import ./validate :as v)
|
||||
# (import /src/scanner :as s)
|
||||
# (import /src/parser :as p)
|
||||
# (import /src/validate :as v)
|
||||
|
||||
# (var source nil)
|
||||
|
||||
|
@ -637,14 +639,16 @@
|
|||
# # (when (has-errors? validated) (break (validated :errors)))
|
||||
# # (def cleaned (get-in parsed [:ast :data 1]))
|
||||
# # # (pp cleaned)
|
||||
# # (interpret (parsed :ast) @{:^parent b/ctx})
|
||||
# (try (interpret (parsed :ast) @{:^parent b/ctx})
|
||||
# ([e] (if (struct? e) (error (e :msg)) (error e)))))
|
||||
# (interpret (parsed :ast) @{:^parent b/ctx})
|
||||
# # (try (interpret (parsed :ast) @{:^parent b/ctx})
|
||||
# # ([e] (if (struct? e) (error (e :msg)) (error e))))
|
||||
# )
|
||||
|
||||
# # (do
|
||||
# (comment
|
||||
# (set source `
|
||||
|
||||
# let foo = 42
|
||||
# "{foo} bar baz"
|
||||
# `)
|
||||
# (def result (run))
|
||||
# )
|
||||
|
|
|
@ -24,13 +24,13 @@
|
|||
(set (out :errors) (scanned :errors))
|
||||
(each err (scanned :errors)
|
||||
(e/scan-error err))
|
||||
(break out))
|
||||
(break (j/encode out)))
|
||||
(def parsed (p/parse scanned))
|
||||
(when (any? (parsed :errors))
|
||||
(set (out :errors) (parsed :errors))
|
||||
(each err (parsed :errors)
|
||||
(e/parse-error err))
|
||||
(break out))
|
||||
(break (j/encode out)))
|
||||
(def validated (v/valid parsed ctx))
|
||||
(when (any? (validated :errors))
|
||||
(set (out :errors) (validated :errors))
|
||||
|
@ -43,7 +43,7 @@
|
|||
([err]
|
||||
(e/runtime-error err)
|
||||
(set (out :errors) [err])
|
||||
(break out)))
|
||||
(break (j/encode out))))
|
||||
(setdyn :out stdout)
|
||||
(set (out :result) (b/show result))
|
||||
(var post @{})
|
||||
|
@ -53,4 +53,7 @@
|
|||
(set (out :draw) (post :draw))
|
||||
(string (j/encode out)))
|
||||
|
||||
|
||||
(ludus `
|
||||
let foo = 42
|
||||
"{foo} bar baz"
|
||||
`)
|
||||
|
|
|
@ -1116,10 +1116,11 @@
|
|||
|
||||
# (do
|
||||
(comment
|
||||
(def source `...
|
||||
(def source `
|
||||
"{f} a {f}"
|
||||
`)
|
||||
(def scanned (s/scan source))
|
||||
# (print "\n***NEW PARSE***\n")
|
||||
(def a-parser (new-parser scanned))
|
||||
(def parsed (splat a-parser))
|
||||
(def parsed (interpolated a-parser))
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user