~pepe/jlnt.kak

ref: 4438d7d1c8bea7af4b1af21c0576685425c2a8ac jlnt.kak/jlnt -rwxr-xr-x 947 bytes
4438d7d1Josef Pospíšil Fix linting macros 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
24
25
26
27
28
29
30
31
#!/usr/bin/env janet

(defn main [_ file]
  (def c (= file "project.janet"))
  (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)))
    (unless c
      (:eof p)
      (def macros @[])
      (while (:has-more p)
        (def pr (:produce p))
        (def [f s _] pr)
        (def cr (compile pr))
        (if (function? cr)
          (cond
            (= f 'import) (cr)
            (= f 'defmacro) (do
                              (array/push macros s)
                              (cr))
            (find |(= $ f) macros) (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)))))))