diff --git a/brag/brag/brag.scrbl b/brag/brag/brag.scrbl index 1efbfc6..523feb6 100755 --- a/brag/brag/brag.scrbl +++ b/brag/brag/brag.scrbl @@ -1053,5 +1053,9 @@ characters.} A string that is bounded by @racket[open] and @racket[close]. Matching is non-greedy (meaning, it stops at the first occurence of @racket[close]). The resulting lexeme includes @racket[open] and @racket[close]. To remove them, see @racket[trim-ends].} +@defform[(from/stop-before open close)]{ + +Like @racket[from/to], a string that is bounded by @racket[open] and @racket[close], except that @racket[close] is not included in the resulting lexeme. Matching is non-greedy (meaning, it stops at the first occurence of @racket[close]).} + @close-eval[my-eval] diff --git a/brag/brag/support.rkt b/brag/brag/support.rkt index 77e3a61..bb52cd0 100755 --- a/brag/brag/support.rkt +++ b/brag/brag/support.rkt @@ -92,8 +92,16 @@ (λ(stx) (syntax-case stx () [(_ OPEN CLOSE) + ;; (:seq any-string CLOSE any-string) pattern makes it non-greedy #'(:seq OPEN (complement (:seq any-string CLOSE any-string)) CLOSE)]))) +(provide from/stop-before) +(define-lex-trans from/stop-before + (λ(stx) + (syntax-case stx () + [(_ OPEN CLOSE) + #'(:seq OPEN (:* (:~ CLOSE)))]))) + (provide uc+lc) (define-lex-trans uc+lc (λ(stx)