~pepe/jlnt.kak

fe92e3e80a20e767b584306c09afbb0b0b8fed4d — Josef Pospíšil 8 months ago 4438d7d
Add warnings for tracev and long lines
1 files changed, 14 insertions(+), 6 deletions(-)

M jlnt
M jlnt => jlnt +14 -6
@@ 2,16 2,22 @@

(defn main [_ file]
  (def c (= file "project.janet"))
  (def src (slurp file))
  (def lines (length (peg/find-all "\n" src)))
  (var lines 0)
  (def p (parser/new))
  (:consume p src)
  (def emit (partial printf "%s:%i:%i: %s: %s" file))
  (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))
      (printf "%s:%i:%i: %s: %s" file l c "error" (:error p)))
      (emit l c "error" (:error p)))
    (unless c
      (def- importers {'import true 'import* true 'dofile true 'require true})
      (:eof p)
      (def macros @[])
      (while (:has-more p)


@@ 20,7 26,9 @@
        (def cr (compile pr))
        (if (function? cr)
          (cond
            (= f 'import) (cr)
            (= f 'tracev)
            (emit lines c "warning" "Tracev")
            (importers f) (cr)
            (= f 'defmacro) (do
                              (array/push macros s)
                              (cr))


@@ 28,4 36,4 @@
          (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)))))))
            (emit l c "error" e)))))))