dev-subparser
Matthew Butterick 6 years ago
parent 385954d59f
commit 532d21423c

@ -81,6 +81,7 @@
(cons eof token-EOF) (cons eof token-EOF)
(cons 'TOKEN-TYPE TOKEN-TYPE-CONSTRUCTOR) ...))) (cons 'TOKEN-TYPE TOKEN-TYPE-CONSTRUCTOR) ...)))
(module mrp racket/base
(define-syntax (MAKE-RULE-PARSER rule-id-stx) (define-syntax (MAKE-RULE-PARSER rule-id-stx)
(syntax-case rule-id-stx () (syntax-case rule-id-stx ()
[(_ start-rule) [(_ start-rule)
@ -89,7 +90,7 @@
;; The cfg-parser depends on the start-rule provided in (start ...) to have the same ;; The cfg-parser depends on the start-rule provided in (start ...) to have the same
;; context as the rest of this body. Hence RECOLORED-START-RULE ;; context as the rest of this body. Hence RECOLORED-START-RULE
(with-syntax ([RECOLORED-START-RULE (datum->syntax #'RULES-STX (syntax-e #'start-rule))]) (with-syntax ([RECOLORED-START-RULE (datum->syntax #'RULES-STX (syntax-e #'start-rule))])
#'(let ([THE-GRAMMAR (cfg-parser (tokens enumerated-tokens) #`(let ([THE-GRAMMAR (cfg-parser (tokens enumerated-tokens)
(src-pos) (src-pos)
(start RECOLORED-START-RULE) (start RECOLORED-START-RULE)
(end EOF) (end EOF)
@ -115,11 +116,17 @@
[(_ not-a-rule-id) [(_ not-a-rule-id)
(raise-syntax-error #f (raise-syntax-error #f
(format "Rule ~a is not defined in the grammar" (syntax-e #'not-a-rule-id)) (format "Rule ~a is not defined in the grammar" (syntax-e #'not-a-rule-id))
rule-id-stx)])) rule-id-stx)])))
(module RULE-ID racket/base
(require (submod ".." mrp))
(define p (MAKE-RULE-PARSER RULE-ID))
(provide p)) ...
(define PARSE-RULE-ID (define PARSE-RULE-ID
(procedure-rename (procedure-rename
(let ([func-p (delay (MAKE-RULE-PARSER RULE-ID))]) (let ([func-p (delay (dynamic-require '(submod #,(syntax-source rules-stx) RULE-ID) 'p))])
(λ args (apply (force func-p) args))) (λ args (apply (force func-p) args)))
'PARSE-RULE-ID)) ... 'PARSE-RULE-ID)) ...
(define (PARSE-RULE-ID-TO-DATUM x) (define (PARSE-RULE-ID-TO-DATUM x)

@ -0,0 +1,21 @@
#lang racket
(module mac racket
(provide m)
(println 'wasting-time)
(define-syntax-rule (m arg) arg))
(module mod racket
(require (submod ".." mac))
(define (modm arg) (m arg))
(provide modm))
(require rackunit)
(define f (let ([func-p (delay (dynamic-require '(submod "proof-of-concept.rkt" mod) 'modm))])
(λ (x) ((force func-p) x))))
f
(f 100)
(f 100)
Loading…
Cancel
Save