From 7cd78a842b35da59b81c5a2cce16ec8c0590a392 Mon Sep 17 00:00:00 2001 From: Ben Greenman Date: Thu, 9 Jun 2016 01:34:09 -0400 Subject: [PATCH] [regexp] add src lines to group error message --- trivial/private/regexp.rkt | 10 ++++++---- trivial/untyped/regexp.rkt | 16 +++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/trivial/private/regexp.rkt b/trivial/private/regexp.rkt index 240dfd2..40e2af3 100644 --- a/trivial/private/regexp.rkt +++ b/trivial/private/regexp.rkt @@ -42,10 +42,12 @@ (begin-for-syntax (define errloc-key 'regexp-match:) - (define (group-error str reason) - (raise-argument-error - errloc-key - (format "Invalid regexp pattern (unmatched ~a)" reason) + (define (group-error stx str reason) + (raise-user-error errloc-key + "(~a:~a) Invalid regexp pattern (unmatched ~a) in ~a" + (syntax-line stx) + (syntax-column stx) + reason str)) ;; Dispatch for counting groups diff --git a/trivial/untyped/regexp.rkt b/trivial/untyped/regexp.rkt index 87915ae..b851d20 100644 --- a/trivial/untyped/regexp.rkt +++ b/trivial/untyped/regexp.rkt @@ -42,10 +42,12 @@ (begin-for-syntax (define errloc-key 'regexp-match:) - (define (group-error str reason) - (raise-argument-error - errloc-key - (format "Invalid regexp pattern (unmatched ~a)" reason) + (define (group-error stx str reason) + (raise-user-error errloc-key + "(~a:~a) Invalid regexp pattern (unmatched ~a) in ~a" + (syntax-line stx) + (syntax-column stx) + reason str)) ;; Dispatch for counting groups @@ -86,9 +88,9 @@ (if (> i last-index) (cond [(not (null? in-paren)) - (group-error str (format "'(' at index ~a" (car in-paren)))] + (group-error stx str (format "'(' at index ~a" (car in-paren)))] [(unbox in-square?) - (group-error str (format "'[' at index ~a" (car in-paren)))] + (group-error stx str (format "'[' at index ~a" (car in-paren)))] [else (list num-groups null-idx*)]) (if (unbox in-square?) @@ -110,7 +112,7 @@ [(#\)) (cond [(null? in-paren) - (group-error str (format "')' at index ~a" i))] + (group-error stx str (format "')' at index ~a" i))] [(eq? #f (car in-paren)) ;; Matched closing paren, but does not count as a group (loop (+ i 1) (cdr in-paren) num-groups null-idx*)]