take account of hide property in rule flattening (fixes #8)

pull/10/head
Matthew Butterick 7 years ago
parent cf505f2995
commit c85b0e5cc9

@ -133,8 +133,22 @@
;; Given a pattern, return a key appropriate for a hash.
;;
;; In the `ragg` days this used `syntax->datum` only.
;; The problem is that with cuts & splices in the mix, it creates ambiguity:
;; e.g., the pattern (/"," foo)* and ("," foo)* differ only in the 'hide syntax property
;; so `syntax->datum` does not capture their differences.
;; That means they produced the same hash key,
;; which meant they produced the same inferred pattern. Which is wrong.
;; So we adjust the key to take account of the 'hide property
;; by "lifting" it into the datum with cons.
;; Then the pattern-inference process treats them separately.
(define (pattern->hash-key a-pat)
(syntax->datum a-pat))
(let loop ([x a-pat])
(let ([maybe-stx-list (syntax->list x)])
(if maybe-stx-list
(cons (syntax-property x 'hide) (map loop maybe-stx-list))
(syntax->datum x)))))
;; Returns true if the pattern looks primitive

@ -0,0 +1,4 @@
#lang brag
top : expr (/"," expr)*
expr : "x" | list
list : "(" expr ("," expr)* ")"

@ -0,0 +1,9 @@
#lang racket/base
(require brag/examples/cutter
brag/support
rackunit)
;; related to rule-flattening problem
(check-equal?
(parse-to-datum (list "(" "x" "," "x" ")"))
'(top (expr (list "(" (expr "x") "," (expr "x") ")"))))
Loading…
Cancel
Save