|
|
|
@ -96,14 +96,16 @@
|
|
|
|
|
;; repeat
|
|
|
|
|
(check-equal? (map syntax->datum
|
|
|
|
|
(flatten-rule #'(rule rule-2+ (repeat 0 #f (id rule-2)))))
|
|
|
|
|
'((prim-rule repeat rule-2+
|
|
|
|
|
[(inferred-id rule-2+ repeat) (id rule-2)]
|
|
|
|
|
[])))
|
|
|
|
|
'((prim-rule maybe rule-2+ ((inferred-id %rule1 repeat)) ())
|
|
|
|
|
(inferred-prim-rule repeat %rule1
|
|
|
|
|
((inferred-id %rule1 repeat) (id rule-2))
|
|
|
|
|
((id rule-2)))))
|
|
|
|
|
(check-equal? (map syntax->datum
|
|
|
|
|
(flatten-rule #'(rule rule-2+ (repeat 0 #f (seq (lit "+") (id rule-2))))))
|
|
|
|
|
'((prim-rule repeat rule-2+
|
|
|
|
|
[(inferred-id rule-2+ repeat) (lit "+") (id rule-2)]
|
|
|
|
|
[])))
|
|
|
|
|
'((prim-rule maybe rule-2+ ((inferred-id %rule2 repeat)) ())
|
|
|
|
|
(inferred-prim-rule repeat %rule2
|
|
|
|
|
((inferred-id %rule2 repeat) (lit "+") (id rule-2))
|
|
|
|
|
((lit "+") (id rule-2)))))
|
|
|
|
|
|
|
|
|
|
(check-equal? (map syntax->datum
|
|
|
|
|
(flatten-rule #'(rule rule-2+ (repeat 1 #f (id rule-2)))))
|
|
|
|
@ -174,8 +176,11 @@
|
|
|
|
|
(check-equal? (map syntax->datum
|
|
|
|
|
(flatten-rule #'(rule expr (seq (id term) (repeat 0 #f (seq (lit "+") (id term)))))
|
|
|
|
|
#:fresh-name (make-fresh-name)))
|
|
|
|
|
'((prim-rule seq expr [(id term) (inferred-id r1 repeat)])
|
|
|
|
|
(inferred-prim-rule repeat r1 [(inferred-id r1 repeat) (lit "+") (id term)] [])))
|
|
|
|
|
'((prim-rule seq expr ((id term) (inferred-id r1 repeat)))
|
|
|
|
|
(prim-rule maybe r1 ((inferred-id r2 repeat)) ())
|
|
|
|
|
(inferred-prim-rule repeat r2
|
|
|
|
|
((inferred-id r2 repeat) (lit "+") (id term))
|
|
|
|
|
((lit "+") (id term)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; larger example: simple arithmetic
|
|
|
|
@ -186,8 +191,14 @@
|
|
|
|
|
(rule factor (token INT))))
|
|
|
|
|
#:fresh-name (make-fresh-name)))
|
|
|
|
|
|
|
|
|
|
'((prim-rule seq expr [(id term) (inferred-id r1 repeat)])
|
|
|
|
|
(inferred-prim-rule repeat r1 [(inferred-id r1 repeat) (lit "+") (id term)] [])
|
|
|
|
|
(prim-rule seq term [(id factor) (inferred-id r2 repeat)])
|
|
|
|
|
(inferred-prim-rule repeat r2 [(inferred-id r2 repeat) (lit "*") (id factor)] [])
|
|
|
|
|
(prim-rule token factor [(token INT)])))
|
|
|
|
|
'((prim-rule seq expr ((id term) (inferred-id r1 repeat)))
|
|
|
|
|
(prim-rule maybe r1 ((inferred-id r2 repeat)) ())
|
|
|
|
|
(inferred-prim-rule repeat r2
|
|
|
|
|
((inferred-id r2 repeat) (lit "+") (id term))
|
|
|
|
|
((lit "+") (id term)))
|
|
|
|
|
(prim-rule seq term ((id factor) (inferred-id r3 repeat)))
|
|
|
|
|
(prim-rule maybe r3 ((inferred-id r4 repeat)) ())
|
|
|
|
|
(inferred-prim-rule repeat r4
|
|
|
|
|
((inferred-id r4 repeat) (lit "*") (id factor))
|
|
|
|
|
((lit "*") (id factor)))
|
|
|
|
|
(prim-rule token factor ((token INT)))))
|
|
|
|
|