|
|
@ -1,4 +1,4 @@
|
|
|
|
#lang racket/base
|
|
|
|
#lang br
|
|
|
|
|
|
|
|
|
|
|
|
(require (for-template racket/base)
|
|
|
|
(require (for-template racket/base)
|
|
|
|
racket/list
|
|
|
|
racket/list
|
|
|
@ -38,10 +38,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
;; We flatten the rules so we can use the yacc-style ruleset that parser-tools
|
|
|
|
;; We flatten the rules so we can use the yacc-style ruleset that parser-tools
|
|
|
|
;; supports.
|
|
|
|
;; supports.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#|
|
|
|
|
|
|
|
|
MB: `rules` still carries 'hide syntax property
|
|
|
|
|
|
|
|
|#
|
|
|
|
|
|
|
|
#;(report flattened-rules)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#|
|
|
|
|
|
|
|
|
MB: `flattened-rules` still carries 'hide syntax property
|
|
|
|
|
|
|
|
|#
|
|
|
|
(define flattened-rules (flatten-rules rules))
|
|
|
|
(define flattened-rules (flatten-rules rules))
|
|
|
|
|
|
|
|
#;(report flattened-rules)
|
|
|
|
|
|
|
|
|
|
|
|
(define generated-rule-codes (map flat-rule->yacc-rule flattened-rules))
|
|
|
|
(define generated-rule-codes (map flat-rule->yacc-rule flattened-rules))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#|
|
|
|
|
|
|
|
|
MB: `generated-rule-codes` loses the 'hide syntax property
|
|
|
|
|
|
|
|
|#
|
|
|
|
|
|
|
|
#;(report generated-rule-codes)
|
|
|
|
|
|
|
|
|
|
|
|
;; The first rule, by default, is the start rule.
|
|
|
|
;; The first rule, by default, is the start rule.
|
|
|
|
(define rule-ids (for/list ([a-rule (in-list rules)])
|
|
|
|
(define rule-ids (for/list ([a-rule (in-list rules)])
|
|
|
|
(rule-id a-rule)))
|
|
|
|
(rule-id a-rule)))
|
|
|
@ -163,6 +179,7 @@
|
|
|
|
;; stx :== (name (U tokens rule-stx) ...)
|
|
|
|
;; stx :== (name (U tokens rule-stx) ...)
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
(define (flat-rule->yacc-rule a-flat-rule)
|
|
|
|
(define (flat-rule->yacc-rule a-flat-rule)
|
|
|
|
|
|
|
|
#;(report a-flat-rule)
|
|
|
|
(syntax-case a-flat-rule ()
|
|
|
|
(syntax-case a-flat-rule ()
|
|
|
|
[(rule-type origin name clauses ...)
|
|
|
|
[(rule-type origin name clauses ...)
|
|
|
|
(begin
|
|
|
|
(begin
|
|
|
@ -206,6 +223,7 @@
|
|
|
|
[$X-end-pos
|
|
|
|
[$X-end-pos
|
|
|
|
(format-id translated-pattern "$~a-end-pos" pos)])
|
|
|
|
(format-id translated-pattern "$~a-end-pos" pos)])
|
|
|
|
(syntax-case primitive-pattern (id lit token inferred-id)
|
|
|
|
(syntax-case primitive-pattern (id lit token inferred-id)
|
|
|
|
|
|
|
|
|
|
|
|
;; When a rule usage is inferred, the value of $X is a syntax object
|
|
|
|
;; When a rule usage is inferred, the value of $X is a syntax object
|
|
|
|
;; whose head is the name of the inferred rule . We strip that out,
|
|
|
|
;; whose head is the name of the inferred rule . We strip that out,
|
|
|
|
;; leaving the residue to be absorbed.
|
|
|
|
;; leaving the residue to be absorbed.
|
|
|
@ -214,11 +232,13 @@
|
|
|
|
[(inferred-rule-name . rest)
|
|
|
|
[(inferred-rule-name . rest)
|
|
|
|
(syntax->list #'rest)])]
|
|
|
|
(syntax->list #'rest)])]
|
|
|
|
[(id val)
|
|
|
|
[(id val)
|
|
|
|
#`(list $X)]
|
|
|
|
#'(list $X)]
|
|
|
|
|
|
|
|
;; move the 'hide syntax property into the translated-action
|
|
|
|
|
|
|
|
;; because syntax gets datum-ized
|
|
|
|
[(lit val)
|
|
|
|
[(lit val)
|
|
|
|
#`(list (atomic-datum->syntax $X $X-start-pos $X-end-pos))]
|
|
|
|
#`(list (atomic-datum->syntax $X $X-start-pos $X-end-pos #,(syntax-property primitive-pattern 'hide)))]
|
|
|
|
[(token val)
|
|
|
|
[(token val)
|
|
|
|
#`(list (atomic-datum->syntax $X $X-start-pos $X-end-pos))]))))
|
|
|
|
#`(list (atomic-datum->syntax $X $X-start-pos $X-end-pos #,(syntax-property primitive-pattern 'hide)))]))))
|
|
|
|
|
|
|
|
|
|
|
|
(define whole-rule-loc
|
|
|
|
(define whole-rule-loc
|
|
|
|
(if (empty? translated-patterns)
|
|
|
|
(if (empty? translated-patterns)
|
|
|
|