From 405d76160290f37b75a6eded7a61997c35e27c4b Mon Sep 17 00:00:00 2001 From: "Jesse A. Tov" Date: Thu, 25 Jul 2019 19:36:40 -0500 Subject: [PATCH 1/2] Demonstrates bug in char-complement. This commit adds 3 tests. All 3 should pass, but right now 2 of them fail because char-complement is considering (repetition n n e) to be a charset for *any* n, so long as e is a charset. --- br-parser-tools-lib/br-parser-tools/private-lex/stx.rkt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/br-parser-tools-lib/br-parser-tools/private-lex/stx.rkt b/br-parser-tools-lib/br-parser-tools/private-lex/stx.rkt index 7d887b1..16ee1d5 100644 --- a/br-parser-tools-lib/br-parser-tools/private-lex/stx.rkt +++ b/br-parser-tools-lib/br-parser-tools/private-lex/stx.rkt @@ -147,6 +147,7 @@ (check-equal? (char-set? '(repetition 1 2 #\1)) #f) (check-equal? (char-set? '(repetition 1 1 "12")) #f) (check-equal? (char-set? '(repetition 1 1 "1")) #t) + (check-equal? (char-set? '(repetition 6 6 "1")) #f) (check-equal? (char-set? '(union "1" "2" "3")) #t) (check-equal? (char-set? '(union "1" "" "3")) #f) (check-equal? (char-set? '(intersection "1" "2" (union "3" "4"))) #t) @@ -182,4 +183,8 @@ (check-equal? (parse #'(char-range #\1 "1") null) '(char-range #\1 #\1)) (check-equal? (parse #'(char-range "1" "3") null) '(char-range #\1 #\3)) (check-equal? (parse #'(char-complement (union "1" "2")) null) - '(char-complement (union "1" "2")))) + '(char-complement (union "1" "2"))) + (check-equal? (parse #'(char-complement (repetition 1 1 "1")) null) + '(char-complement (repetition 1 1 "1"))) + (check-exn #rx"not a character set" + (λ () (parse #'(char-complement (repetition 6 6 "1")) null)))) -- 2.25.1 From 773f613ecdf928343799e50c495d76d00cdb6cb1 Mon Sep 17 00:00:00 2001 From: "Jesse A. Tov" Date: Thu, 25 Jul 2019 19:39:03 -0500 Subject: [PATCH 2/2] Fixes bug demonstrated by previous commit. Now (repetition 1 1 e) is a charset if e is a charset, but other number of repetitions are not. --- br-parser-tools-lib/br-parser-tools/private-lex/stx.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/br-parser-tools-lib/br-parser-tools/private-lex/stx.rkt b/br-parser-tools-lib/br-parser-tools/private-lex/stx.rkt index 16ee1d5..326ecb3 100644 --- a/br-parser-tools-lib/br-parser-tools/private-lex/stx.rkt +++ b/br-parser-tools-lib/br-parser-tools/private-lex/stx.rkt @@ -134,7 +134,7 @@ [(list? s-re) (case (car s-re) [(union intersection) (andmap char-set? (cdr s-re))] [(char-range char-complement) #t] - [(repetition) (and (= (cadr s-re) (caddr s-re)) (char-set? (cadddr s-re)))] + [(repetition) (and (= 1 (cadr s-re) (caddr s-re)) (char-set? (cadddr s-re)))] [(concatenation) (and (= 2 (length s-re)) (char-set? (cadr s-re)))] (else #f))] [else #f])) -- 2.25.1