~pepe/jlnt.kak

ref: 27843d63221d6c500c223e848a66a549cb49f59d jlnt.kak/jlnt -rwxr-xr-x 696 bytes
27843d63Josef Pospíšil Fix eof, remove cruft and printf 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env janet

(defn main [_ file]
  (def src (slurp file))
  (def lines (length (peg/find-all "\n" src)))
  (def p (parser/new))
  (:consume p src)
  (if (= :error (:status p))
    (do
      (var [l c] (:where p))
      (when (> l lines) (set l lines) (set c 1))
      (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)))))))