Added #:cut pattern directive

This commit is contained in:
Milo Turner 2018-02-23 11:43:17 -05:00 committed by Ryan Culpepper
parent 112aa6eb07
commit 275d7974cd
3 changed files with 24 additions and 1 deletions

View File

@ -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 ~!].
}
@;{----------}

View File

@ -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 ()

View File

@ -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