[private] rx: stop using unsafe-ref
This commit is contained in:
parent
f18c207d11
commit
f99ef2ffa1
|
@ -40,20 +40,34 @@
|
||||||
;; --- can't handle starred groups
|
;; --- can't handle starred groups
|
||||||
(ann (regexp-match: "(a)*(b)" "b")
|
(ann (regexp-match: "(a)*(b)" "b")
|
||||||
(U #f (List String String)))
|
(U #f (List String String)))
|
||||||
) (test-compile-error
|
)
|
||||||
#:require trivial/regexp
|
|
||||||
#:exn #rx"mutation not allowed"
|
|
||||||
;; -- set! problems
|
|
||||||
(ann (let-regexp: ([a #rx"(b)(B)"])
|
|
||||||
(set! a #rx"")
|
|
||||||
(regexp-match: a "hai"))
|
|
||||||
(List String String String))
|
|
||||||
(let ()
|
|
||||||
(define-regexp: a #rx"h(i)")
|
|
||||||
(set! a #rx"hi")
|
|
||||||
(regexp-match a "hi"))
|
|
||||||
|
|
||||||
(let-regexp: ([a #rx"h(i)"])
|
(test-compile-error
|
||||||
(set! a #rx"(h)(i)")
|
#:require trivial/regexp racket/port
|
||||||
(regexp-match a "hi"))
|
#:exn #rx"Type Checker"
|
||||||
))
|
;; -- expected String, given Bytes
|
||||||
|
(with-input-from-string "hello"
|
||||||
|
(lambda ()
|
||||||
|
(define m (regexp-match #rx#"lang" (current-input-port)))
|
||||||
|
(and m (string=? (car m) "lang"))))
|
||||||
|
)
|
||||||
|
|
||||||
|
;; 2016-06-13 : these really should be errors, just no-opts
|
||||||
|
;(test-compile-error
|
||||||
|
; #:require trivial/regexp
|
||||||
|
; #:exn #rx"mutation not allowed"
|
||||||
|
; ;; -- set! problems
|
||||||
|
; (ann (let-regexp: ([a #rx"(b)(B)"])
|
||||||
|
; (set! a #rx"")
|
||||||
|
; (regexp-match: a "hai"))
|
||||||
|
; (List String String String))
|
||||||
|
; (let ()
|
||||||
|
; (define-regexp: a #rx"h(i)")
|
||||||
|
; (set! a #rx"hi")
|
||||||
|
; (regexp-match a "hi"))
|
||||||
|
;
|
||||||
|
; (let-regexp: ([a #rx"h(i)"])
|
||||||
|
; (set! a #rx"(h)(i)")
|
||||||
|
; (regexp-match a "hi"))
|
||||||
|
;)
|
||||||
|
)
|
||||||
|
|
|
@ -8,11 +8,18 @@
|
||||||
trivial/regexp
|
trivial/regexp
|
||||||
typed/rackunit)
|
typed/rackunit)
|
||||||
|
|
||||||
;; -- TODO
|
;; -- TODO (handle regexp . format)
|
||||||
; (define re:normal-name (regexp (format "~a*<([^>]*)>~a*" blank blank)))
|
; (define re:normal-name (regexp (format "~a*<([^>]*)>~a*" blank blank)))
|
||||||
|
|
||||||
;; -- regexps, from the world
|
;; -- regexps, from the world
|
||||||
|
|
||||||
|
(let ([str
|
||||||
|
|
||||||
|
(let () ;; -- from klocker? anyway the unicode will segfault `unsafe-string-ref`
|
||||||
|
(check-equal?
|
||||||
|
(ann (regexp-match: #rx"⇒" "yolo") (U #f (List String)))
|
||||||
|
#f))
|
||||||
|
|
||||||
(let ([str "dont care"]) ;; from `tests/racket/contract/multi-file.rkt`
|
(let ([str "dont care"]) ;; from `tests/racket/contract/multi-file.rkt`
|
||||||
(check-equal?
|
(check-equal?
|
||||||
(ann
|
(ann
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
;; =============================================================================
|
;; =============================================================================
|
||||||
|
|
||||||
(: *TRIVIAL-LOG* (Parameterof Boolean))
|
(: *TRIVIAL-LOG* (Parameterof Boolean))
|
||||||
(define *TRIVIAL-LOG* (make-parameter #t))
|
(define *TRIVIAL-LOG* (make-parameter #f))
|
||||||
|
|
||||||
(: *STOP-LIST* (Parameterof (Listof Identifier)))
|
(: *STOP-LIST* (Parameterof (Listof Identifier)))
|
||||||
(define *STOP-LIST* (make-parameter '()))
|
(define *STOP-LIST* (make-parameter '()))
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
typed/racket/base
|
typed/racket/base
|
||||||
(only-in racket/list range)
|
(only-in racket/list range)
|
||||||
(only-in racket/format ~a)
|
(only-in racket/format ~a)
|
||||||
(only-in racket/unsafe/ops unsafe-string-ref)
|
|
||||||
syntax/parse
|
syntax/parse
|
||||||
trivial/private/common))
|
trivial/private/common))
|
||||||
|
|
||||||
|
@ -155,7 +154,7 @@
|
||||||
(define h-rev
|
(define h-rev
|
||||||
(for/fold ([hist (for/hasheq ([c (in-list c*)]) (values c '()))])
|
(for/fold ([hist (for/hasheq ([c (in-list c*)]) (values c '()))])
|
||||||
([i (in-range L)])
|
([i (in-range L)])
|
||||||
(define char (unsafe-string-ref str i))
|
(define char (string-ref str i))
|
||||||
(cond
|
(cond
|
||||||
[(unbox escaped?)
|
[(unbox escaped?)
|
||||||
(when (or (not (eq? #\\ char))
|
(when (or (not (eq? #\\ char))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user