mirror of https://github.com/janet-lang/janet
Fix some typos, make jpm repl work without a project.janet.
This commit is contained in:
parent
f5433dcaa4
commit
3eb84fcb13
|
@ -2,6 +2,7 @@
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## Unreleased - ???
|
## Unreleased - ???
|
||||||
|
- Fix bug in `getline`.
|
||||||
- Add `sh-rule` and `sh-phony` to jpm's dialect of Janet.
|
- Add `sh-rule` and `sh-phony` to jpm's dialect of Janet.
|
||||||
- Change C api's `janet_formatb` -> `janet_formatbv`.
|
- Change C api's `janet_formatb` -> `janet_formatbv`.
|
||||||
- Add C `janet_formatb` to C api.
|
- Add C `janet_formatb` to C api.
|
||||||
|
|
37
auxbin/jpm
37
auxbin/jpm
|
@ -187,20 +187,25 @@
|
||||||
[into x]
|
[into x]
|
||||||
(when x
|
(when x
|
||||||
(proto-flatten into (table/getproto x))
|
(proto-flatten into (table/getproto x))
|
||||||
(loop [k :keys x]
|
(merge-into into x))
|
||||||
(put into k (x k))))
|
|
||||||
into)
|
into)
|
||||||
|
|
||||||
|
(defn make-jpm-env
|
||||||
|
"Build an environment table with jpm functions preloaded."
|
||||||
|
[&opt no-deps]
|
||||||
|
(def env (make-env))
|
||||||
|
(put env :jpm-no-deps no-deps)
|
||||||
|
(loop [k :keys _env :when (symbol? k)]
|
||||||
|
(unless ((_env k) :private) (put env k (_env k))))
|
||||||
|
env)
|
||||||
|
|
||||||
(defn require-jpm
|
(defn require-jpm
|
||||||
"Require a jpm file project file. This is different from a normal require
|
"Require a jpm file project file. This is different from a normal require
|
||||||
in that code is loaded in the jpm environment."
|
in that code is loaded in the jpm environment."
|
||||||
[path &opt no-deps]
|
[path &opt no-deps]
|
||||||
(def env (make-env))
|
|
||||||
(put env :jpm-no-deps no-deps)
|
|
||||||
(unless (os/stat path :mode)
|
(unless (os/stat path :mode)
|
||||||
(error (string "cannot open " path)))
|
(error (string "cannot open " path)))
|
||||||
(loop [k :keys _env :when (symbol? k)]
|
(def env (make-jpm-env no-deps))
|
||||||
(unless ((_env k) :private) (put env k (_env k))))
|
|
||||||
(def currenv (proto-flatten @{} (fiber/getenv (fiber/current))))
|
(def currenv (proto-flatten @{} (fiber/getenv (fiber/current))))
|
||||||
(loop [k :keys currenv :when (keyword? k)]
|
(loop [k :keys currenv :when (keyword? k)]
|
||||||
(put env k (currenv k)))
|
(put env k (currenv k)))
|
||||||
|
@ -1053,17 +1058,23 @@ Flags are:
|
||||||
|
|
||||||
(defn jpm-repl
|
(defn jpm-repl
|
||||||
[]
|
[]
|
||||||
(def env (require-jpm "./project.janet"))
|
(def env
|
||||||
(def p (env :project))
|
(try
|
||||||
(def name (p :name))
|
(require-jpm "./project.janet")
|
||||||
|
([err f]
|
||||||
|
(if (= "cannot open ./project.janet" err)
|
||||||
|
(put (make-jpm-env) :project {})
|
||||||
|
(propagate err f)))))
|
||||||
(setdyn :pretty-format (if-not (dyn :nocolor) "%.20Q" "%.20q"))
|
(setdyn :pretty-format (if-not (dyn :nocolor) "%.20Q" "%.20q"))
|
||||||
(setdyn :err-color (if-not (dyn :nocolor) true))
|
(setdyn :err-color (if-not (dyn :nocolor) true))
|
||||||
(print "Project: " name)
|
(def p (env :project))
|
||||||
(print "Repository: " (p :repo))
|
(def name (p :name))
|
||||||
(print "Author: " (p :author))
|
(if name (print "Project: " name))
|
||||||
|
(if-let [r (p :repo)] (print "Repository: " r))
|
||||||
|
(if-let [a (p :author)] (print "Author: " a))
|
||||||
(defn getchunk [buf p]
|
(defn getchunk [buf p]
|
||||||
(def [line] (parser/where p))
|
(def [line] (parser/where p))
|
||||||
(getline (string "jpm[" name "]:" line ":" (parser/state p :delimiters) "> ") buf env))
|
(getline (string "jpm[" (or name "repl") "]:" line ":" (parser/state p :delimiters) "> ") buf env))
|
||||||
(repl getchunk nil env))
|
(repl getchunk nil env))
|
||||||
|
|
||||||
(def- subcommands
|
(def- subcommands
|
||||||
|
|
|
@ -501,7 +501,7 @@
|
||||||
that define something to loop over. They are formatted like:\n\n
|
that define something to loop over. They are formatted like:\n\n
|
||||||
\tbinding :verb object/expression\n\n
|
\tbinding :verb object/expression\n\n
|
||||||
Where binding is a binding as passed to def, :verb is one of a set of keywords,
|
Where binding is a binding as passed to def, :verb is one of a set of keywords,
|
||||||
and object is any janet expression. The available verbs are:\n\n
|
and object is any expression. The available verbs are:\n\n
|
||||||
\t:iterate - repeatedly evaluate and bind to the expression while it is truthy.\n
|
\t:iterate - repeatedly evaluate and bind to the expression while it is truthy.\n
|
||||||
\t:range - loop over a range. The object should be two element tuple with a start
|
\t:range - loop over a range. The object should be two element tuple with a start
|
||||||
and end value, and an optional positive step. The range is half open, [start, end).\n
|
and end value, and an optional positive step. The range is half open, [start, end).\n
|
||||||
|
@ -1482,10 +1482,10 @@
|
||||||
###
|
###
|
||||||
|
|
||||||
(defn- env-walk
|
(defn- env-walk
|
||||||
[pred &opt env]
|
[pred &opt env local]
|
||||||
(default env (fiber/getenv (fiber/current)))
|
(default env (fiber/getenv (fiber/current)))
|
||||||
(def envs @[])
|
(def envs @[])
|
||||||
(do (var e env) (while e (array/push envs e) (set e (table/getproto e))))
|
(do (var e env) (while e (array/push envs e) (set e (table/getproto e)) (if local (break))))
|
||||||
(def ret-set @{})
|
(def ret-set @{})
|
||||||
(loop [envi :in envs
|
(loop [envi :in envs
|
||||||
k :keys envi
|
k :keys envi
|
||||||
|
@ -1494,16 +1494,18 @@
|
||||||
(sort (keys ret-set)))
|
(sort (keys ret-set)))
|
||||||
|
|
||||||
(defn all-bindings
|
(defn all-bindings
|
||||||
"Get all symbols available in an enviroment. Defaults to the current
|
"Get all symbols available in an environment. Defaults to the current
|
||||||
fiber's environment."
|
fiber's environment. If local is truthy, will not show inherited bindings
|
||||||
[&opt env]
|
(from prototype tables)."
|
||||||
(env-walk symbol? env))
|
[&opt env local]
|
||||||
|
(env-walk symbol? env local))
|
||||||
|
|
||||||
(defn all-dynamics
|
(defn all-dynamics
|
||||||
"Get all dynamic bindings in an environment. Defaults to the current
|
"Get all dynamic bindings in an environment. Defaults to the current
|
||||||
fiber's environment."
|
fiber's environment. If local is truthy, will not show inherited bindings
|
||||||
[&opt env]
|
(from prototype tables)."
|
||||||
(env-walk keyword? env))
|
[&opt env local]
|
||||||
|
(env-walk keyword? env local))
|
||||||
|
|
||||||
(defn doc-format
|
(defn doc-format
|
||||||
"Reformat text to wrap at a given line."
|
"Reformat text to wrap at a given line."
|
||||||
|
@ -1701,7 +1703,7 @@
|
||||||
ret)
|
ret)
|
||||||
|
|
||||||
(defn all
|
(defn all
|
||||||
"Returns true if all xs are truthy, otherwise the resulty of first
|
"Returns true if all xs are truthy, otherwise the result of first
|
||||||
falsey predicate value, (pred x)."
|
falsey predicate value, (pred x)."
|
||||||
[pred xs]
|
[pred xs]
|
||||||
(var ret true)
|
(var ret true)
|
||||||
|
@ -1915,7 +1917,7 @@
|
||||||
(eflush))
|
(eflush))
|
||||||
|
|
||||||
(defn run-context
|
(defn run-context
|
||||||
"Run a context. This evaluates expressions of janet in an environment,
|
"Run a context. This evaluates expressions in an environment,
|
||||||
and is encapsulates the parsing, compilation, and evaluation.
|
and is encapsulates the parsing, compilation, and evaluation.
|
||||||
Returns (in environment :exit-value environment) when complete.
|
Returns (in environment :exit-value environment) when complete.
|
||||||
opts is a table or struct of options. The options are as follows:\n\n\t
|
opts is a table or struct of options. The options are as follows:\n\n\t
|
||||||
|
@ -2672,7 +2674,7 @@
|
||||||
###
|
###
|
||||||
###
|
###
|
||||||
|
|
||||||
(def root-env "The root environment used to create envionments with (make-env)" _env)
|
(def root-env "The root environment used to create environments with (make-env)" _env)
|
||||||
|
|
||||||
(do
|
(do
|
||||||
(put _env 'boot/opts nil)
|
(put _env 'boot/opts nil)
|
||||||
|
|
Loading…
Reference in New Issue