[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error context info



Consider the following example:

(define-struct a (b-exprs))
(define-struct b (c-exprs))
(define-struct c (c-field))

(define-syntax validate
  (lambda (stx)
    (syntax-case stx (a)
      [(_ (a x ...)) (syntax (make-a (list (validate-b x) ...)))]))) ; <--
expression on this line is highlighted

(define-syntax validate-b
  (lambda (stx)
    (syntax-case stx (b)
      [(_ (b x ...)) (syntax (make-b (list (validate-c x) ...)))])))

(define-syntax validate-c
  (lambda (stx)
    (syntax-case stx (c)
      [(_ (c c-field))
       (syntax (if (string? c-field) (make-c c-field)
                   (raise-syntax-error 'c (format "expected string, given:
~a ~a" c-f (syntax-line (syntax c-field))))))])))

(validate (a (b (c "foo")
                (c "bar")) ;<--- misplaced paren here causes error
                (c "baz")
             (b (c "this")
                (c "is")
                (c "a")
                (c "test"))))


In the example, a paren is deliberately misplaced in order to cause an
error.
When the error occurs the expression on the indicated line is highlighted
and
the following error message is printed:

#<struct:object:derived-from-definitions-text%>:8:22: validate-b: bad syntax
in: (validate-b (c "baz"))

I would rather that the expression, '(c "baz") were highlighted on the line
where the error occured.
I tried doing a ... (syntax/loc stx (make-a ...))...  but in this case, no
line was highlighted.

When I modify validate like this:
(define-syntax validate
  (lambda (stx)
    (display (syntax-line stx)) ;display the context information of stx
    (syntax-case stx (a)
      [(_ (a x ...)) (syntax (make-a (list (validate-b x) ...)))])))


It displays 23, which is the line number of the invocation of validate, so
I would have expected that syntax/loc would have used this line-number.