correct behavior of blank curlies

hide-top-rule-name
Matthew Butterick 7 years ago
parent 10c399bfd7
commit b99869ca40

@ -168,60 +168,62 @@
[(list all min range? max) (let* ([min (if min (string->number min) 0)] [(list all min range? max) (let* ([min (if min (string->number min) 0)]
[max (cond [max (cond
[(and range? max) (string->number max)] [(and range? max) (string->number max)]
[(and (not range?) (not max)) min] ; {3} -> {3,3} [(and (not range?) (not max)) (if (zero? min)
[else #f])]) #f ; {} -> {0,}
(cons min max))]))] min))] ; {3} -> {3,3}
[else (raise-argument-error 'grammar-parse "unknown repetition operator" $2)])) [else #f])])
(pattern-repeat (position->pos $1-start-pos) (cons min max))]))]
(position->pos $2-end-pos) [else (raise-argument-error 'grammar-parse "unknown repetition operator" $2)]))
min-repeat max-repeat $1 (pattern-repeat (position->pos $1-start-pos)
#f))] (position->pos $2-end-pos)
[(atomic-pattern) min-repeat max-repeat $1
$1]] #f))]
[(atomic-pattern)
[atomic-pattern $1]]
[(LIT)
(pattern-lit (position->pos $1-start-pos) [atomic-pattern
(position->pos $1-end-pos) [(LIT)
(substring $1 1 (sub1 (string-length $1))) (pattern-lit (position->pos $1-start-pos)
#f)] (position->pos $1-end-pos)
(substring $1 1 (sub1 (string-length $1)))
[(ID) #f)]
(if (token-id? $1)
(pattern-token (position->pos $1-start-pos) [(ID)
(position->pos $1-end-pos) (if (token-id? $1)
$1 (pattern-token (position->pos $1-start-pos)
#f) (position->pos $1-end-pos)
(pattern-id (position->pos $1-start-pos) $1
(position->pos $1-end-pos) #f)
$1 (pattern-id (position->pos $1-start-pos)
#f))] (position->pos $1-end-pos)
$1
[(LBRACKET pattern RBRACKET) #f))]
(pattern-repeat (position->pos $1-start-pos)
(position->pos $3-end-pos) [(LBRACKET pattern RBRACKET)
0 1 $2 (pattern-repeat (position->pos $1-start-pos)
#f)] (position->pos $3-end-pos)
0 1 $2
[(LPAREN pattern RPAREN) #f)]
(relocate-pattern $2 (position->pos $1-start-pos) (position->pos $3-end-pos))]
[(LPAREN pattern RPAREN)
[(HIDE atomic-pattern) (relocate-pattern $2 (position->pos $1-start-pos) (position->pos $3-end-pos))]
(relocate-pattern $2 (position->pos $1-start-pos) (position->pos $2-end-pos) 'hide)]
[(HIDE atomic-pattern)
[(SPLICE ID) (relocate-pattern $2 (position->pos $1-start-pos) (position->pos $2-end-pos) 'hide)]
;; only works for nonterminals on the right side
;; (meaningless with terminals) [(SPLICE ID)
(if (token-id? $2) ;; only works for nonterminals on the right side
(error 'brag "Can't use splice operator with terminal") ;; (meaningless with terminals)
(pattern-id (position->pos $1-start-pos) (if (token-id? $2)
(position->pos $2-end-pos) (error 'brag "Can't use splice operator with terminal")
$2 (pattern-id (position->pos $1-start-pos)
'splice))]]) (position->pos $2-end-pos)
$2
'splice))]])
(error (lambda (tok-ok? tok-name tok-value start-pos end-pos)
((current-parser-error-handler) tok-ok? tok-name tok-value (position->pos start-pos) (position->pos end-pos))))))
(error (lambda (tok-ok? tok-name tok-value start-pos end-pos)
((current-parser-error-handler) tok-ok? tok-name tok-value (position->pos start-pos) (position->pos end-pos))))))
;; relocate-pattern: pattern -> pattern ;; relocate-pattern: pattern -> pattern
;; Rewrites the pattern's start and end pos accordingly. ;; Rewrites the pattern's start and end pos accordingly.

Loading…
Cancel
Save