Fix bug in expander

When using `make-rule-parser` for any rule that is not the start
rule, and applying the resulting parser while giving it a source-path
it would just use the entire grammar from the start rule.
pull/28/head
Markus Pfeiffer 3 years ago
parent d3405dd0ab
commit 8d7546f228
No known key found for this signature in database
GPG Key ID: 9E429BDC79806DC1

@ -78,29 +78,32 @@
(member (syntax-e #'start-rule) 'RULE-IDS)) (member (syntax-e #'start-rule) 'RULE-IDS))
;; 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) [PARSE-NAME (datum->syntax #'RULES-STX (string->symbol (format "~a-rule-parser" 'start-rule)))])
(src-pos) #'(let* ([THE-GRAMMAR (cfg-parser (tokens enumerated-tokens)
(start RECOLORED-START-RULE) (src-pos)
(end EOF) (start RECOLORED-START-RULE)
(error THE-ERROR-HANDLER) (end EOF)
(grammar . GENERATED-RULE-CODES))]) (error THE-ERROR-HANDLER)
(grammar . GENERATED-RULE-CODES))]
[THE-BODY (lambda (tokenizer)
(define next-token
(make-permissive-tokenizer tokenizer all-tokens-hash/mutable))
;; little post-processor to support cuts on top rule name
(define parse-tree-stx (THE-GRAMMAR next-token))
(define top-rule-name-stx (syntax-case parse-tree-stx ()
[(TRN . REST) #'TRN]
[_ (error 'malformed-parse-tree)]))
(if (eq? (syntax-property top-rule-name-stx 'hide-or-splice?) 'hide)
;; use `remove-rule-name` so we get the same housekeeping
(remove-rule-name parse-tree-stx)
parse-tree-stx))])
(procedure-rename (procedure-rename
(case-lambda [(tokenizer) (case-lambda [(tokenizer)
(define next-token (THE-BODY tokenizer)]
(make-permissive-tokenizer tokenizer all-tokens-hash/mutable))
;; little post-processor to support cuts on top rule name
(define parse-tree-stx (THE-GRAMMAR next-token))
(define top-rule-name-stx (syntax-case parse-tree-stx ()
[(TRN . REST) #'TRN]
[_ (error 'malformed-parse-tree)]))
(if (eq? (syntax-property top-rule-name-stx 'hide-or-splice?) 'hide)
;; use `remove-rule-name` so we get the same housekeeping
(remove-rule-name parse-tree-stx)
parse-tree-stx)]
[(source tokenizer) [(source tokenizer)
(parameterize ([current-source source]) (parameterize ([current-source source])
(PARSE tokenizer))]) (THE-BODY tokenizer))])
(string->symbol (format "~a-rule-parser" 'start-rule)))))] (string->symbol (format "~a-rule-parser" 'start-rule)))))]
[(_ not-a-rule-id) [(_ not-a-rule-id)
(raise-syntax-error #f (raise-syntax-error #f

Loading…
Cancel
Save