1
0
mirror of https://github.com/janet-lang/janet synced 2025-07-06 12:02:53 +00:00

Update indentation in boot and init to be more like

most lisps.
This commit is contained in:
Calvin Rose 2018-07-01 21:12:46 -04:00
parent 79225ad3d5
commit e60c8a9b75
2 changed files with 821 additions and 819 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,18 @@
# Copyright 2017-2018 (C) Calvin Rose # Copyright 2017-2018 (C) Calvin Rose
(do (do
(var *should-repl* :private false) (var *should-repl* :private false)
(var *no-file* :private true) (var *no-file* :private true)
(var *raw-stdin* :private false) (var *raw-stdin* :private false)
(var *handleopts* :private true) (var *handleopts* :private true)
(var *exit-on-error* :private true) (var *exit-on-error* :private true)
# Flag handlers # Flag handlers
(def handlers :private { (def handlers :private
"h" (fn [] {"h" (fn []
(print "usage: " (get args 0) " [options] scripts...") (print "usage: " (get args 0) " [options] scripts...")
(print `Options are: (print
`Options are:
-h Show this help -h Show this help
-v Print the version string -v Print the version string
-s Use raw stdin instead of getline like functionality -s Use raw stdin instead of getline like functionality
@ -19,43 +20,40 @@
-r Enter the repl after running all scripts -r Enter the repl after running all scripts
-p Keep on executing if there is a top level error (persistent) -p Keep on executing if there is a top level error (persistent)
-- Stop handling options`) -- Stop handling options`)
(os.exit 0) (os.exit 0)
1) 1)
"v" (fn [] (print VERSION) (os.exit 0) 1) "v" (fn [] (print VERSION) (os.exit 0) 1)
"s" (fn [] (:= *raw-stdin* true) (:= *should-repl* true) 1) "s" (fn [] (:= *raw-stdin* true) (:= *should-repl* true) 1)
"r" (fn [] (:= *should-repl* true) 1) "r" (fn [] (:= *should-repl* true) 1)
"p" (fn [] (:= *exit-on-error* false) 1) "p" (fn [] (:= *exit-on-error* false) 1)
"-" (fn [] (:= *handleopts* false) 1) "-" (fn [] (:= *handleopts* false) 1)
"e" (fn [i] "e" (fn [i]
(:= *no-file* false) (:= *no-file* false)
(eval (get args (+ i 1))) (eval (get args (+ i 1)))
2) 2)})
})
(defn- dohandler [n i] (defn- dohandler [n i]
(def h (get handlers n)) (def h (get handlers n))
(if h (h i) (print "unknown flag -" n))) (if h (h i) (print "unknown flag -" n)))
# Process arguments # Process arguments
(var i 1) (var i 1)
(def lenargs (length args)) (def lenargs (length args))
(while (< i lenargs) (while (< i lenargs)
(def arg (get args i)) (def arg (get args i))
(if (and *handleopts* (= "-" (string.slice arg 0 1))) (if (and *handleopts* (= "-" (string.slice arg 0 1)))
(+= i (dohandler (string.slice arg 1 2) i)) (+= i (dohandler (string.slice arg 1 2) i))
(do (do
(:= *no-file* false) (:= *no-file* false)
(import* _env arg :exit *exit-on-error*) (import* _env arg :exit *exit-on-error*)
(++ i)))) (++ i))))
(when (or *should-repl* *no-file*) (when (or *should-repl* *no-file*)
(if *raw-stdin* (if *raw-stdin*
(repl nil identity) (repl nil identity)
(do (do
(print (string "Dst " VERSION " Copyright (C) 2017-2018 Calvin Rose")) (print (string "Dst " VERSION " Copyright (C) 2017-2018 Calvin Rose"))
(repl (fn [buf p] (repl (fn [buf p]
(def [line] (parser.where p)) (def [line] (parser.where p))
(def prompt (string "dst:" line ":" (parser.state p) "> ")) (def prompt (string "dst:" line ":" (parser.state p) "> "))
(getline prompt buf)))))) (getline prompt buf)))))))
)