~technomancy/fennel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH] Output compile/parse errors in a more standard format

Rudolf Adamkovič <rudolf@adamkovic.org>
Details
Message ID
<20240219135512.15842-1-rudolf@adamkovic.org>
DKIM signature
pass
Download raw message
Patch: +12 -12
The errors are missing a trailing colon after the line/column number which makes
them "invisible" to standard tools, such as the Compilation Mode in Emacs.
---
 src/fennel/compiler.fnl |  2 +-
 src/fennel/friend.fnl   |  4 ++--
 src/fennel/parser.fnl   |  2 +-
 test/failures.fnl       | 16 ++++++++--------
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/fennel/compiler.fnl b/src/fennel/compiler.fnl
index 94d94e0..5814391 100644
--- a/src/fennel/compiler.fnl
+++ b/src/fennel/compiler.fnl
@@ -39,7 +39,7 @@ implement nesting. "
        line (or (and m m.line) ast-tbl.line "?")
        col (or (and m m.col) ast-tbl.col "?")
        target (tostring (or (utils.sym? (. ast-tbl 1)) (. ast-tbl 1) "()"))]
    (string.format "%s:%s:%s Compile error in '%s': %s"
    (string.format "%s:%s:%s: Compile error in '%s': %s"
                   filename line col target msg)))

;; If you add new calls to this function, please update fennel.friend
diff --git a/src/fennel/friend.fnl b/src/fennel/friend.fnl
index 452a8cb..ea48e2d 100644
--- a/src/fennel/friend.fnl
+++ b/src/fennel/friend.fnl
@@ -142,7 +142,7 @@
  "A drop-in replacement for the internal assert-compile with friendly messages."
  (when (not condition)
    (let [{: filename : line : col} (utils.ast-source ast)]
      (error (friendly-msg (: "%s:%s:%s Compile error: %s" :format
      (error (friendly-msg (: "%s:%s:%s: Compile error: %s" :format
                              ;; still need fallbacks because backtick erases
                              ;; source and macros can generate source-less ast
                              (or filename :unknown) (or line "?")
@@ -152,7 +152,7 @@

(fn parse-error [msg filename line col source opts]
  "A drop-in replacement for the internal parse-error with friendly messages."
  (error (friendly-msg (: "%s:%s:%s Parse error: %s" :format
  (error (friendly-msg (: "%s:%s:%s: Parse error: %s" :format
                          filename line col msg)
                       {: filename : line : col} source opts) 0))

diff --git a/src/fennel/parser.fnl b/src/fennel/parser.fnl
index f537f2b..8625dd8 100644
--- a/src/fennel/parser.fnl
+++ b/src/fennel/parser.fnl
@@ -98,7 +98,7 @@ Also returns a second function to clear the buffer in the byte stream."
                               source utils.root.reset))
        (utils.root.reset)
        (if unfriendly
            (error (string.format "%s:%s:%s Parse error: %s"
            (error (string.format "%s:%s:%s: Parse error: %s"
                                  filename (or line "?") col msg) 0)
            (friend.parse-error msg filename (or line "?") col source options)))))

diff --git a/test/failures.fnl b/test/failures.fnl
index e75ac5a..33813db 100644
--- a/test/failures.fnl
+++ b/test/failures.fnl
@@ -123,18 +123,18 @@

(fn test-parse-fails []
  (test-failures
   {"\n\n(+))" "unknown:3:3 Parse error: unexpected closing delimiter )"
   {"\n\n(+))" "unknown:3:3: Parse error: unexpected closing delimiter )"
    "(foo:)" "malformed multisym"
    "(foo.bar:)" "malformed multisym"}))

(fn test-core-fails []
  (test-failures
   {"\n\n(let [f (lambda []\n(local))] (f))" "unknown:4:0 "
    "\n\n(let [x.y 9] nil)" "unknown:3:0 Compile error in 'let': unexpected multi"
    "\n(when)" "unknown:2:0 Compile error in 'when'"
   {"\n\n(let [f (lambda []\n(local))] (f))" "unknown:4:0: "
    "\n\n(let [x.y 9] nil)" "unknown:3:0: Compile error in 'let': unexpected multi"
    "\n(when)" "unknown:2:0: Compile error in 'when'"
    "()" "expected a function, macro, or special"
    "(789)" "cannot call literal value"
    "(do\n\n\n(each \n[x (pairs {})] (when)))" "unknown:5:15 "
    "(do\n\n\n(each \n[x (pairs {})] (when)))" "unknown:5:15: "
    "(each [k v (pairs {})] (BAD k v))" "BAD"
    "(f" "expected closing delimiter )"
    "(match [1 2 3] [a & b c] nil)" "rest argument before last parameter"
@@ -154,7 +154,7 @@
    "(each [i x (y) (do-iter)] (print x))" "unexpected bindings in iterator"
    "(for [i 1 3 2 other-stuff] nil)" "unexpected arguments"
    "(do\n\n\n(each \n[x 34 (pairs {})] 21))"
    "unknown:5:0 Compile error in 'x': unable to bind number 34"
    "unknown:5:0: Compile error in 'x': unable to bind number 34"
    "(with-open [(x y z) (values 1 2 3)])"
    "with-open only allows symbols in bindings"
    "([])" "cannot call literal value table"
@@ -214,8 +214,8 @@
                                        "(icollect [_ _ \n(pairs [])]\n)"
                                        {:error-pinpoint [">>>" "<<<"]})]
    ;; use the standard prefix
    (t.match "^%S+:%d+:%d+ Compile error: .+" msg)
    (t.match "^%S+:%d+:%d+ Parse error: .+" parse-msg)
    (t.match "^%S+:%d+:%d+: Compile error: .+" msg)
    (t.match "^%S+:%d+:%d+: Parse error: .+" parse-msg)
    ;; show the raw error message
    (t.match "expected var x" msg)
    ;; offer suggestions
-- 
2.43.0
Details
Message ID
<87h6i4gvaa.fsf@hagelb.org>
In-Reply-To
<20240219135512.15842-1-rudolf@adamkovic.org> (view parent)
DKIM signature
pass
Download raw message
Rudolf Adamkovič <rudolf@adamkovic.org> writes:

> The errors are missing a trailing colon after the line/column number which makes
> them "invisible" to standard tools, such as the Compilation Mode in Emacs.

Thanks; I've applied this patch. Does it necessitate changes in the
tests for faith as well?

-Phil
Rudolf Adamkovič <rudolf@adamkovic.org>
Details
Message ID
<m234tnjkza.fsf@adamkovic.org>
In-Reply-To
<87h6i4gvaa.fsf@hagelb.org> (view parent)
DKIM signature
pass
Download raw message
Phil Hagelberg <phil@hagelb.org> writes:

> Thanks; I've applied this patch.

Thank you!

> Does it necessitate changes in the tests for faith as well?

I pulled both and, with your latest commits, all works well.

Rudy
-- 
"Chop your own wood and it will warm you twice."
--- Henry Ford; Francis Kinloch, 1819; Henry David Thoreau, 1854

Rudolf Adamkovič <rudolf@adamkovic.org> [he/him]
Studenohorská 25, 84103 Bratislava, Slovakia, European Union
Reply to thread Export thread (mbox)