Skip to content

Commit d763cbc

Browse files
committed
cope with a possible ambiguity while parsing binding form patterns
closes #171
1 parent 3e069f3 commit d763cbc

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

redex-lib/redex/private/binding-forms-compiler.rkt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,13 @@
297297
[rest-of-body ;; no imports or ...s
298298
(process-under #'rest-of-body #f #f)]))]
299299

300-
[atomic-pattern (values (syntax-e #'atomic-pattern) #'atomic-pattern)])))
300+
[atomic-pattern
301+
(begin
302+
(when (equal? (syntax-e #'atomic-pattern) 'in-hole)
303+
(raise-syntax-error 'define-language
304+
"`in-hole` is illegal in a binding specification"
305+
#'atomic-pattern))
306+
(values (syntax-e #'atomic-pattern) #'atomic-pattern))])))
301307

302308
(define import-names (names-imported-in-with-depths bspec-body form-name s-body))
303309
(define export-names (names-mentioned-in-beta-with-depths export-beta form-name s-body))

redex-lib/redex/private/binding-forms.rkt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,12 @@ to traverse the whole value at once, rather than one binding form at a time.
236236
(match match-res
237237
[#f (loop rest)]
238238
;; "bindings" is what the rest of Redex calls what we call "red-match"
239-
[`(,m)
239+
[(cons m _)
240+
;; we ignore the rest position because there should be no way to get
241+
;; information there that isn't redundant with what's in the first
242+
;; position. I belive the only way to even get a tail is to have an
243+
;; ambiguous match via context decomposition, but even then the bindings
244+
;; should all be the same, so we can safely take the first one. I hope.
240245
(when (binding-forms-opened?)
241246
(set-box! (binding-forms-opened?) #t))
242247
(fn (splay-all-...binds (bindings-table (mtch-bindings m)) bspec)

redex-test/redex/tests/binding-forms-test.rkt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,3 +757,18 @@
757757
(λ (x_1) e #:refers-to x_1))
758758
(check-equal? (term (substitute (x y) x y) #:lang L)
759759
(term (y y))))
760+
761+
762+
(let ()
763+
(define-language L
764+
(e ::= (ζ (hide-hole E)))
765+
(x ::= variable-not-otherwise-mentioned)
766+
(E ::= hole (in-hole (natural E) E))
767+
#:binding-forms
768+
(ξ x e_1 #:refers-to x))
769+
770+
(check-true (pair?
771+
(redex-match
772+
L
773+
(ξ x e)
774+
(term (ξ x (ζ (1 (2 hole)))))))))

0 commit comments

Comments
 (0)