Make a little better error messages

Let's get ready to decide how to handle the errors.  Especially in coercing.
4 files changed, 13 insertions(+), 13 deletions(-)

M src/lexer.lisp
M src/parser-utils.lisp
M src/utils.lisp
M t/parser-tests.lisp
M src/lexer.lisp +0 -5
@@ 51,11 51,6 @@ literals."
    :prev prev
    :value value))
 
-
-(defmethod print-object ((token token) stream)
-  (format stream "<TOKEN: kind = ~a line = ~a column = ~a"
-          (kind token) (line token) (column token)))
-
 (defclass* source
   body
   name

          
M src/parser-utils.lisp +8 -3
@@ 170,7 170,9 @@ all nodes."
   (with-token
     (if (peek kind)
         (progn (advance-one-token) *token*)
-        (gql-error "Expected ~a, found ~a" kind (kind *token*)))))
+        (with-slots (line column) *token*
+          (gql-error "Expected ~a, found ~a at line: ~a, column: ~a"
+                     kind (kind *token*) line column)))))
 
 (defun expect-optional-token (kind)
   (with-token

          
@@ 181,7 183,9 @@ all nodes."
   (with-token
     (if (and (peek 'name) (equalp (value *token*) value))
         (advance-one-token)
-        (gql-error "Expected ~a, found ~a" value (value *token*)))))
+        (with-slots (line column) *token*
+          (gql-error "Expected ~a, found ~a at line: ~a, column: ~a"
+                     value (value *token*) line column)))))
 
 (defun expect-optional-keyword (value)
   (with-token

          
@@ 191,7 195,8 @@ all nodes."
 
 (defun unexpected (&optional token)
   (let ((token (if token token *token*)))
-    (gql-error "Unexpected token: ~a" token)))
+    (with-slots (line column) token
+      (gql-error "Unexpected token: ~a at line: ~a, column: ~a" token line column))))
 
 (defun any (open-kind parse-kind close-kind &key (constp nil))
   (expect-token open-kind)

          
M src/utils.lisp +3 -3
@@ 58,11 58,11 @@ 
            :message message
            :locations (mapcar
                        (lambda (node)
-                         (let ((start-token (start-token (location node))))
+                         (with-slots (line column) (start-token (location node))
                            (make-instance
                             'error-location
-                            :line (line start-token)
-                            :column (column start-token))))
+                            :line line
+                            :column column)))
                        node-list)
            :path nil
            :extensions nil)

          
M t/parser-tests.lisp +2 -2
@@ 2,7 2,7 @@ 
 
 (deftest parser
   (testing "Detects EOF"
-    (signals-with-check "{" gql::gql-simple-error "Expected NAME, found EOF"))
+    (signals-with-check "{" gql::gql-simple-error "Expected NAME, found EOF at line: 1, column: 2"))
   (testing "Returns OK"
     (ok (gql "query withFragments {
   user(id: 4) {

          
@@ 120,7 120,7 @@ fragment friendFields on User {
   (testing "Schema"
     (ok (gql (asdf:system-relative-pathname 'gql-tests #p"t/test-files/example-schema.txt")))
     (signals-with-check (gql (asdf:system-relative-pathname 'gql-tests #p"t/test-files/empty-object.txt"))
-                        gql::gql-simple-error "Expected NAME, found BRACE-R")
+                        gql::gql-simple-error "Expected NAME, found BRACE-R at line: 1, column: 1")
     (ok (gql "
 \"\"\" 
 Some description at the start