stash work

This commit is contained in:
Scott Richmond 2024-01-19 16:50:01 -05:00
parent f02532ee40
commit d253dc3d3e
3 changed files with 19 additions and 14 deletions

View File

@ -33,7 +33,7 @@
(array? seq) (array/slice 1 len))))
(defn some? [val] (not (nil? val)))
(defn apply-kw-parser [kw tokens]
(let [token (first tokens)]
#(if (= kw (get token :type)) (println "Matched " kw))

View File

@ -1,7 +1,7 @@
(def reserved-words
"List of Ludus reserved words."
## see ludus-spec repo for more info
{"as" :as ## impl for `import`# not yet for patterns
{"as" :as ## impl
"do" :do ## impl
"else" :else ## impl
"false" :false ## impl -> literal word
@ -111,7 +111,7 @@
(def terminators {
":" true
"#" true
";" true
"\n" true
"{" true
"}" true
@ -141,7 +141,7 @@
:line (get scanner :line)
:start (get scanner :start)
:source (get scanner :source)
:start (get scanner :input)}))
:input (get scanner :input)}))
## TODO: errors should also be in the vector of tokens
## The goal is to be able to be able to hand this to an LSP?
@ -190,17 +190,15 @@
## TODO: activate string interpolation
(defn- add-string
[scanner]
(print "Adding string")
(defn recur [scanner buff interpolate?]
(print "\n printing a thing from add-stirng" buff)
(let [char (current-char scanner)]
(case char
"{" (recur (advance scanner) (buffer/push buff char) true)
# allow multiline strings
"\n" (recur (update (advance scanner) :line inc) (buffer/push buff char) interpolate?)
"\"" (if interpolate?
#(add-token (advance scanner) :interpolated string)
#no interpolation yet
(add-token (advance scanner) :string (string buff))
(add-token (advance scanner) :string (string buff)))
"\"" (add-token (advance scanner) :string (string buff))
"\\" (let [next (next-char scanner)
scanner (if (= next "\n")
(update scanner :line inc)
@ -255,7 +253,7 @@
"}" (add-token (add-token scanner :break) :rbrace)
"[" (add-token scanner :lbracket)
"]" (add-token (add-token scanner :break) :rbracket)
"#" (add-token scanner :semicolon)
";" (add-token scanner :semicolon)
"," (add-token scanner :comma)
"\n" (add-token (update scanner :line inc) :newline)
"\\" (add-token scanner :backslash)
@ -315,7 +313,8 @@
(defn- next-token [scanner]
(put scanner :start (get scanner :current)))
(defn scan [source input]
(defn scan [source &opt input]
(default input "")
(defn recur [scanner]
(if (at-end? scanner)
(let [scanner (add-token (add-token scanner :break) :eof)]
@ -323,3 +322,4 @@
:errors (get scanner :errors)})
(recur (-> scanner (scan-token) (next-token)))))
(recur (new-scanner source input)))

View File

@ -4,14 +4,19 @@ build:
# open a janet repl in a different os window
repl:
kitten @ launch --type=os-window --allow-remote-control --cwd=current --title=hx_repl:ludus janet -s
kitten @ launch --type=os-window --allow-remote-control --cwd=current --title=hx_repl:ludus
kitten @ send-text -m "title:hx_repl:ludus" "janet -s\n"
restart:
kitten @ send-text -m "title:hx_repl:ludus" "\04"
kitten @ send-text -m "title:hx_repl:ludus" "janet -s\n"
# send what's selected to the repl and evaluate it
eval:
sd "$" "\n" | sd "\n\n" "\n" | kitten @ send-text -m "title:hx_repl:ludus" --stdin
# send what's selected to a buffer, and then evaluate what's in the buffer
buffer:
sd "$" "\n" | sd "\n\n" "\n" > .repl-buffer
kitten @ send-text -m "title:hx_repl:ludus" --from-file .repl-buffer
sd "$" "\n" | sd "\n\n" "\n" > .repl-buffer.janet
kitten @ send-text -m "title:hx_repl:ludus" "(import ./.repl-buffer :prefix \"\")"