Compare commits
No commits in common. "20cb689d12d8f08a62e03376236813b058d69d70" and "6a4e2ccd17dbbc77c58532dc9f29df145e7dad5c" have entirely different histories.
20cb689d12
...
6a4e2ccd17
|
@ -44,7 +44,7 @@
|
||||||
:dict (dict-str value)
|
:dict (dict-str value)
|
||||||
:set
|
:set
|
||||||
(string/join (map stringify (keys value)) ", ")
|
(string/join (map stringify (keys value)) ", ")
|
||||||
:box (stringify (value :^value))
|
:ref (stringify (value :^value))
|
||||||
:fn (string "fn " (value :name))
|
:fn (string "fn " (value :name))
|
||||||
:applied (string "fn " (value :name))
|
:applied (string "fn " (value :name))
|
||||||
:function (string "builtin " (string value))
|
:function (string "builtin " (string value))
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
:list (string "[" (stringify x) "]")
|
:list (string "[" (stringify x) "]")
|
||||||
:dict (string "#{" (stringify x) "}")
|
:dict (string "#{" (stringify x) "}")
|
||||||
:set (string "${" (stringify x) "}")
|
:set (string "${" (stringify x) "}")
|
||||||
:box (string "box " (x :name) " [ " (stringify x) " ]")
|
:ref (string "box " (x :name) " [ " (stringify x) " ]")
|
||||||
:pkg (show-pkg x)
|
:pkg (show-pkg x)
|
||||||
(stringify x)))
|
(stringify x)))
|
||||||
|
|
||||||
|
|
|
@ -1,34 +1,10 @@
|
||||||
(import spork/json :as j)
|
(import spork/json :as j)
|
||||||
(import /base :as b)
|
(import /base :as b)
|
||||||
|
|
||||||
(defn- get-line [source line]
|
|
||||||
((string/split "\n" source) (dec line)))
|
|
||||||
|
|
||||||
(defn scan-error [e out] (set (out :errors) e) (j/encode out))
|
(defn scan-error [e out] (set (out :errors) e) (j/encode out))
|
||||||
|
|
||||||
(defn parse-error [e]
|
(defn parse-error [e out] (set (out :errors) e) (j/encode out))
|
||||||
(def msg (e :msg))
|
|
||||||
(def line-num (get-in e [:token :line]))
|
|
||||||
(def source (get-in e [:token :source]))
|
|
||||||
(def source-line (get-line source line-num))
|
|
||||||
(print "Parsing error: " msg)
|
|
||||||
(print "On line " line-num ":")
|
|
||||||
(print source-line))
|
|
||||||
|
|
||||||
|
(defn validation-error [e out] (set (out :errors) e) (j/encode out))
|
||||||
(defn validation-error [e]
|
|
||||||
(def msg (e :msg))
|
|
||||||
(def line-num (get-in e [:node :token :line]))
|
|
||||||
(def source (get-in e [:node :token :source]))
|
|
||||||
(def source-line (get-line source line-num))
|
|
||||||
(case msg
|
|
||||||
"unbound name"
|
|
||||||
(do
|
|
||||||
(print "Validation error: " msg " " (get-in e [:node :data]))
|
|
||||||
(print "on line " line-num)
|
|
||||||
(print source-line)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defn runtime-error [e out] (set (out :errors) e) (j/encode out))
|
(defn runtime-error [e out] (set (out :errors) e) (j/encode out))
|
||||||
|
|
|
@ -340,7 +340,7 @@
|
||||||
(defn- ref [ast ctx]
|
(defn- ref [ast ctx]
|
||||||
(def {:data value-ast :name name} ast)
|
(def {:data value-ast :name name} ast)
|
||||||
(def value (interpret value-ast ctx))
|
(def value (interpret value-ast ctx))
|
||||||
(def box @{:^type :box :^value value :name name})
|
(def box @{:^type :ref :^value value :name name})
|
||||||
(set (ctx name) box)
|
(set (ctx name) box)
|
||||||
box)
|
box)
|
||||||
|
|
||||||
|
|
|
@ -16,16 +16,16 @@ The API from the old Clojure Ludus interpreter returns an object with four field
|
||||||
* `errors`: an array of errors, which are just strings
|
* `errors`: an array of errors, which are just strings
|
||||||
|
|
||||||
This new scene will have to return a JSON POJSO:
|
This new scene will have to return a JSON POJSO:
|
||||||
{:console "..." :result "..." :draw [...] :errors [...]}
|
{:console [...] :result "..." :draw [...] :errors [...]}
|
||||||
)
|
)
|
||||||
|
|
||||||
(def prelude-src (slurp "prelude.ld"))
|
(def console @"")
|
||||||
(def prelude-scanned (s/scan prelude-src))
|
(setdyn :out console)
|
||||||
(def prelude-parsed (p/parse prelude-scanned))
|
(print "foo")
|
||||||
(def parse-errors (prelude-parsed :errors))
|
(pp {:a 1 :b 2})
|
||||||
(when (any? parse-errors) (each err parse-errors (e/parse-error err)))
|
(setdyn :out stdout)
|
||||||
(def prelude-validated (v/valid prelude-parsed @{"base" b/base}))
|
(print "collected out")
|
||||||
(each err (prelude-validated :errors) (e/validation-error err))
|
(print console)
|
||||||
|
|
||||||
(defn run [source]
|
(defn run [source]
|
||||||
(def errors @[])
|
(def errors @[])
|
||||||
|
@ -44,7 +44,7 @@ This new scene will have to return a JSON POJSO:
|
||||||
(break (-> :errors validated (e/validation-error out))))
|
(break (-> :errors validated (e/validation-error out))))
|
||||||
(setdyn :out console)
|
(setdyn :out console)
|
||||||
(try
|
(try
|
||||||
(set result (b/show (i/interpret (parsed :ast) @{:^parent b/base})))
|
(set result (b/show (i/interpret (parsed :ast) @{})))
|
||||||
([err] (e/runtime-error err out)))
|
([err] (e/runtime-error err out)))
|
||||||
(set (out :result) result)
|
(set (out :result) result)
|
||||||
(j/encode out))
|
(j/encode out))
|
||||||
|
@ -56,7 +56,7 @@ This new scene will have to return a JSON POJSO:
|
||||||
(run source))
|
(run source))
|
||||||
|
|
||||||
(def source `
|
(def source `
|
||||||
let foo = fn () -> :bar
|
fn foo () -> :foo
|
||||||
foo ()
|
foo ()
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
### A recursive descent parser for Ludus
|
### A recursive descent parser for Ludus
|
||||||
|
|
||||||
### We still need to scan some things
|
### We still need to scan some things
|
||||||
(try (os/cd "janet") ([_] nil)) # when in repl to do relative imports
|
# (try (os/cd "janet") ([_] nil)) # when in repl to do relative imports
|
||||||
(import ./scanner :as s)
|
(import ./scanner :as s)
|
||||||
|
|
||||||
(defmacro declare
|
(defmacro declare
|
||||||
|
@ -773,7 +773,7 @@
|
||||||
(defn- lambda [parser]
|
(defn- lambda [parser]
|
||||||
(def origin (current parser))
|
(def origin (current parser))
|
||||||
(expect parser :fn) (advance parser)
|
(expect parser :fn) (advance parser)
|
||||||
@{:type :fn :data ((fn-simple parser) :clauses) :token origin})
|
@{:type :fn :data (fn-simple parser) :token origin})
|
||||||
|
|
||||||
(defn- fnn [parser]
|
(defn- fnn [parser]
|
||||||
(if (= :lparen (-> parser peek type)) (break (lambda parser)))
|
(if (= :lparen (-> parser peek type)) (break (lambda parser)))
|
||||||
|
@ -1104,7 +1104,6 @@
|
||||||
(def origin (current parser))
|
(def origin (current parser))
|
||||||
(def lines @[])
|
(def lines @[])
|
||||||
(while (not (check parser :eof))
|
(while (not (check parser :eof))
|
||||||
(accept-many parser :newline)
|
|
||||||
(array/push lines (capture toplevel parser))
|
(array/push lines (capture toplevel parser))
|
||||||
(capture terminator parser))
|
(capture terminator parser))
|
||||||
{:type :script :data lines :token origin})
|
{:type :script :data lines :token origin})
|
||||||
|
@ -1117,10 +1116,10 @@
|
||||||
|
|
||||||
# (do
|
# (do
|
||||||
(comment
|
(comment
|
||||||
(def source `fn () -> 42
|
(def source `pkg Foo {}
|
||||||
`)
|
`)
|
||||||
(def scanned (s/scan source))
|
(def scanned (s/scan source))
|
||||||
# (print "\n***NEW PARSE***\n")
|
# (print "\n***NEW PARSE***\n")
|
||||||
(def a-parser (new-parser scanned))
|
(def a-parser (new-parser scanned))
|
||||||
(def parsed (fnn a-parser))
|
(def parsed (pkg a-parser))
|
||||||
)
|
)
|
||||||
|
|
1405
janet/prelude.ld
1405
janet/prelude.ld
File diff suppressed because it is too large
Load Diff
|
@ -173,7 +173,7 @@ Deferred until a later iteration of Ludus:
|
||||||
:dict
|
:dict
|
||||||
:list
|
:list
|
||||||
:fn
|
:fn
|
||||||
:box
|
:ref
|
||||||
:pkg
|
:pkg
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ Deferred until a later iteration of Ludus:
|
||||||
(defn- fnn [validator]
|
(defn- fnn [validator]
|
||||||
(def ast (validator :ast))
|
(def ast (validator :ast))
|
||||||
(def name (ast :name))
|
(def name (ast :name))
|
||||||
(print "function name: " name)
|
# (print "function name: " name)
|
||||||
(def status (validator :status))
|
(def status (validator :status))
|
||||||
(def tail? (status :tail))
|
(def tail? (status :tail))
|
||||||
(set (status :tail) true)
|
(set (status :tail) true)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user