~pepe/jlnt.kak

9ee79d5bcc932a19e75209a9db38d5764664226f — Josef Pospíšil 8 months ago d3b04ca
And continue
1 files changed, 35 insertions(+), 31 deletions(-)

M jlnt
M jlnt => jlnt +35 -31
@@ 5,39 5,43 @@
  (var lines 0)
  (def p (parser/new))
  (def emit (partial printf "%s:%i:%i: %s: %s" file))
  (def- importers {'import true 'import* true 'dofile true 'require true})
  (with [f (file/open file :r)]
    (while (def line (:read f :line))
      (++ lines)
      (when (> (length line) 80)
        (emit lines 80 "warning" "Line too long"))
      (:consume p line)))
  (if (= :error (:status p))
    (do
      (var [l c] (:where p))
      (when (> l lines) (set l lines) (set c 1))
      (emit l c "error" (:error p)))
    (unless com
      (def- importers {'import true 'import* true 'dofile true 'require true})
      (def macros @[])
      (while (:has-more p)
        (pp (:where p))
        (def pr (:produce p))
        (def cr (compile pr))
        (if (function? cr)
          (match pr
            [(s (= 'tracev s))] (emit ;(:where p) "warning" "Tracev")
            [(i (importers i))] (cr)
            [(m (= 'defmacro m))]
            (do
              (array/push macros m)
              (cr))
            [(m (find |(= $ m) macros)) _] (cr)
            [(w (= 'when w)) _ (b (< (length b) 2))]
            (emit ;(:where p) "warning" "When with only one form, use if")
            [(w (= 'unless w)) _ (b (< (length b) 2))]
            (emit ;(:where p) "warning"
                  "Unless with only one form, use if not"))
          (do
            (var {:line l :column c :error e} cr)
            (unless (pos? l) (set l 1) (set c 1))
            (emit l c "error" e)))))))
      (:consume p line)
      (if (= :error (:status p))
        (do
          (var [l c] (:where p))
          (when (> l lines) (set l lines) (set c 1))
          (emit l c "error" (:error p))
          (break))
        (unless com
          (def macros @[])
          (def pos (-> (array ;(:where p))
                       (update 0 dec)
                       (update 1 inc)))
          (when (:has-more p)
            (def pr (:produce p))
            (def cr (compile pr))
            (if (function? cr)
              (match pr
                [(i (importers i))] (cr)
                [(m (= 'defmacro m))]
                (do
                  (array/push macros m)
                  (cr))
                [(m (find |(= $ m) macros)) _] (cr)

                [(s (= 'tracev s))] (emit ;pos "warning" "Tracev")
                [(w (= 'when w)) _ (b (< (length b) 2))]
                (emit ;pos "warning" "When with only one form, use if")
                [(u (= 'unless u)) _ (b (< (length b) 2))]
                (emit ;pos "warning"
                      "Unless with only one form, use if not"))
              (do
                (var {:line l :column c :error e} cr)
                (unless (pos? l) (set l 1) (set c 1))
                (emit l c "error" e)))))))))