syntax/parse: add dynamic check for null ellipsis-head match

Otherwise, nullable ellipsis-head patterns could cause infinite loop.
This commit is contained in:
Ryan Culpepper 2016-05-16 00:46:57 -04:00
parent 669460da34
commit fb5c1310d8
2 changed files with 8 additions and 2 deletions

View File

@ -984,8 +984,9 @@ Conventions:
(for/list ([id (in-list ids)]) (bound-id-table-ref table id)))])
(with-syntax ([(id ...) ids]
[(alt-id ...) alt-ids])
#`(let ([alt-id (rep:combine repc (attribute id) alt-id)] ...)
k))))
#`(let ([alt-id (rep:combine repc (attribute id) alt-id)] ...
[diff (ps-difference pr pr*)])
(if (zero? diff) (error/null-eh-match) k)))))
(syntax-case #'repc ()
[#f #`(parse:H x cx x* cx* pr* head pr es k*)]
[_ #`(parse:H x cx x* cx* pr* head pr es

View File

@ -60,6 +60,7 @@
datum->syntax/with-clause
check/force-syntax-list^depth
check-literal*
error/null-eh-match
begin-for-syntax/once
name->too-few/once
@ -216,6 +217,10 @@
(and used-phase (- used-phase mod-phase)))
ctx id)))
;; error/null-eh-match : -> (escapes)
(define (error/null-eh-match)
(error 'syntax-parse "an ellipsis-head pattern matched an empty sequence"))
;; (begin-for-syntax/once expr/phase1 ...)
;; evaluates in pass 2 of module/intdefs expansion
(define-syntax (begin-for-syntax/once stx)