diff --git a/pkgs/racket-doc/syntax/scribblings/parse/stxclasses.scrbl b/pkgs/racket-doc/syntax/scribblings/parse/stxclasses.scrbl index fadef6e92b..4e7171e9b1 100644 --- a/pkgs/racket-doc/syntax/scribblings/parse/stxclasses.scrbl +++ b/pkgs/racket-doc/syntax/scribblings/parse/stxclasses.scrbl @@ -350,6 +350,14 @@ example. Equivalent to @racket[#:and (~undo defn-or-expr ...)]. } +@specsubform[(code:line #:cut)]{ + +Eliminates backtracking choice points and commits parsing to the +current branch at the current point. + +Equivalent to @racket[#:and ~!]. +} + @;{----------} diff --git a/pkgs/racket-test/tests/stxparse/test.rkt b/pkgs/racket-test/tests/stxparse/test.rkt index 4035815604..c733f68df4 100644 --- a/pkgs/racket-test/tests/stxparse/test.rkt +++ b/pkgs/racket-test/tests/stxparse/test.rkt @@ -535,6 +535,17 @@ (check-equal? (reverse (lits)) '(a c)))) ) +;; #:cut + +(test-case "#:cut after pattern" + (check-exn #rx"correct exn" + (lambda () + (syntax-parse #'#t + [b #:cut + #:fail-when (syntax-e #'b) "correct exn" + (values)] + [_ (error "wrong exn")])))) + ;; state unwinding (let () diff --git a/racket/collects/syntax/parse/private/rep.rkt b/racket/collects/syntax/parse/private/rep.rkt index 9f8d239d5d..91468a2a2b 100644 --- a/racket/collects/syntax/parse/private/rep.rkt +++ b/racket/collects/syntax/parse/private/rep.rkt @@ -1267,6 +1267,9 @@ [(cons (list '#:undo undo-stx stmts) rest) (cons (action:undo stmts) (parse-pattern-sides rest decls))] + [(cons (list '#:cut cut-stx) rest) + (cons (action:cut) + (parse-pattern-sides rest decls))] ['() '()])) @@ -1632,7 +1635,8 @@ (list '#:and check-expression) (list '#:post check-expression) (list '#:do check-stmt-list) - (list '#:undo check-stmt-list))) + (list '#:undo check-stmt-list) + (list '#:cut))) ;; fail-directive-table (define fail-directive-table