Skip to content

Commit 65bfff3

Browse files
author
Ben Lerner
committed
more changes
1 parent c70b6c8 commit 65bfff3

File tree

2 files changed

+230
-43
lines changed

2 files changed

+230
-43
lines changed

ebnf.rkt

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
(define (prod-link grammar name)
1111
(elemref (prod-tag grammar name) (prod-ref name)))
1212

13+
(define grammar-prod-counts (make-hash))
14+
(define (get-next-grammar-prod-tag grammar prod-name)
15+
(define grammar-prod (hash-ref! grammar-prod-counts grammar make-hash))
16+
(define prod-num (+ 1 (hash-ref grammar-prod prod-name 0)))
17+
(hash-set! grammar-prod prod-name prod-num)
18+
(if (= prod-num 1)
19+
(prod-tag grammar prod-name)
20+
(prod-tag grammar (format "~a@~a" prod-name prod-num))))
21+
1322

1423
(define (render grammar parsed)
1524
(define-values (constants prods) (partition constant? parsed))
@@ -58,6 +67,7 @@
5867
(define tok (assoc (pattern-token-val p) names))
5968
(cond
6069
[tok (lit (second tok))]
70+
[(string=? (pattern-token-val p) "...") (meta "...")]
6171
[else (unknown-lit (pattern-token-val p))])]
6272
[(pattern-lit? p)
6373
(lit (pattern-lit-val p))]
@@ -72,7 +82,7 @@
7282
(add-between
7383
(for/list [(p prods)]
7484
(parameterize ([rule-name (lhs-id-val (rule-lhs p))])
75-
(list (elemtag (prod-tag grammar (rule-name))
85+
(list (elemtag (get-next-grammar-prod-tag grammar (rule-name))
7686
(elem (prod-ref (rule-name))
7787
#:style (make-style #f (list (attributes '((class . "bnf-rule")))))))
7888
(meta ":")

0 commit comments

Comments
 (0)