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

@ -170,60 +170,60 @@
[(and range? max) (string->number max)] [(and range? max) (string->number max)]
[(and (not range?) (not max)) (if (zero? min) [(and (not range?) (not max)) (if (zero? min)
#f ; {} -> {0,} #f ; {} -> {0,}
min))] ; {3} -> {3,3} min)] ; {3} -> {3,3}
[else #f])]) [else #f])])
(cons min max))]))] (cons min max))]))]
[else (raise-argument-error 'grammar-parse "unknown repetition operator" $2)])) [else (raise-argument-error 'grammar-parse "unknown repetition operator" $2)]))
(pattern-repeat (position->pos $1-start-pos) (pattern-repeat (position->pos $1-start-pos)
(position->pos $2-end-pos) (position->pos $2-end-pos)
min-repeat max-repeat $1 min-repeat max-repeat $1
#f))] #f))]
[(atomic-pattern) [(atomic-pattern)
$1]] $1]]
[atomic-pattern [atomic-pattern
[(LIT) [(LIT)
(pattern-lit (position->pos $1-start-pos) (pattern-lit (position->pos $1-start-pos)
(position->pos $1-end-pos) (position->pos $1-end-pos)
(substring $1 1 (sub1 (string-length $1))) (substring $1 1 (sub1 (string-length $1)))
#f)] #f)]
[(ID) [(ID)
(if (token-id? $1) (if (token-id? $1)
(pattern-token (position->pos $1-start-pos) (pattern-token (position->pos $1-start-pos)
(position->pos $1-end-pos) (position->pos $1-end-pos)
$1 $1
#f) #f)
(pattern-id (position->pos $1-start-pos) (pattern-id (position->pos $1-start-pos)
(position->pos $1-end-pos) (position->pos $1-end-pos)
$1 $1
#f))] #f))]
[(LBRACKET pattern RBRACKET) [(LBRACKET pattern RBRACKET)
(pattern-repeat (position->pos $1-start-pos) (pattern-repeat (position->pos $1-start-pos)
(position->pos $3-end-pos) (position->pos $3-end-pos)
0 1 $2 0 1 $2
#f)] #f)]
[(LPAREN pattern RPAREN) [(LPAREN pattern RPAREN)
(relocate-pattern $2 (position->pos $1-start-pos) (position->pos $3-end-pos))] (relocate-pattern $2 (position->pos $1-start-pos) (position->pos $3-end-pos))]
[(HIDE atomic-pattern) [(HIDE atomic-pattern)
(relocate-pattern $2 (position->pos $1-start-pos) (position->pos $2-end-pos) 'hide)] (relocate-pattern $2 (position->pos $1-start-pos) (position->pos $2-end-pos) 'hide)]
[(SPLICE ID) [(SPLICE ID)
;; only works for nonterminals on the right side ;; only works for nonterminals on the right side
;; (meaningless with terminals) ;; (meaningless with terminals)
(if (token-id? $2) (if (token-id? $2)
(error 'brag "Can't use splice operator with terminal") (error 'brag "Can't use splice operator with terminal")
(pattern-id (position->pos $1-start-pos) (pattern-id (position->pos $1-start-pos)
(position->pos $2-end-pos) (position->pos $2-end-pos)
$2 $2
'splice))]]) 'splice))]])
(error (lambda (tok-ok? tok-name tok-value start-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)))))) ((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