~pepe/jlnt.kak

77a8fad45e7e38005b637dd86dd95556bd23bff9 — Josef Pospíšil 8 months ago 1d74975
Finish prototype
3 files changed, 32 insertions(+), 5 deletions(-)

D bad.janet
A jlnt
M project.janet
D bad.janet => bad.janet +0 -1
@@ 1,1 0,0 @@
(print "HOHO" a

A jlnt => jlnt +31 -0
@@ 0,0 1,31 @@
#!/usr/bin/env janet

(defn main [_ file]
  (defn bp [p where]
    (def [line col] (:where p))
    (print
      (string/join [where (string line) (string col) "parse" (:error p)] ":")))

  (defn bc [msg macrof where]
    (print (string/join [where "0" "0" "compile" msg] ":"))
    (flush))

  (def src (slurp file))
  (def lines (length (peg/find-all "\n" src)))
  (def p (parser/new))
  (:consume p src)
  (:eof p)
  (if (= :error (:status p))
    (do
      (var [l c] (:where p))
      (when (> l lines) (set l lines) (set c 1))
      (print (string/join [file (string l) (string c) " error" (:error p)] ":")))
    (while (:has-more p)
      (def pr (:produce p))
      (def cr (compile pr (fiber/getenv (fiber/current))))
      (if (function? cr)
        (cr)
        (do
          (var {:line l :column c :error e} cr)
          (unless (pos? l) (set l 1) (set c 1))
          (print (string/join [file (string l) (string c) " error" e] ":")))))))

M project.janet => project.janet +1 -4
@@ 2,7 2,4 @@
  :name "jlnt"
  :description "Janet linter for Kakoune")

(declare-executable
  :name "jlnt"
  :entry "jlnt.janet"
  :install true)
(declare-bin :main "jlnt")