~pepe/jlnt.kak

27843d63221d6c500c223e848a66a549cb49f59d — Josef Pospíšil 8 months ago 71fbda3
Fix eof, remove cruft and printf
1 files changed, 12 insertions(+), 20 deletions(-)

M jlnt
M jlnt => jlnt +12 -20
@@ 1,31 1,23 @@
#!/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] ":")))))))
      (printf "%s:%i:%i: %s: %s" file l c "error" (:error p)))
    (do
      (:eof 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))
            (printf "%s:%i:%i: %s: %s" file l c "error" e)))))))