From 68990d02573faa555ee42919d5809de03f1268a0 Mon Sep 17 00:00:00 2001 From: Andy Keep Date: Sun, 18 Oct 2020 09:35:15 -0700 Subject: [PATCH] Allow nanopass parsers without run-time dependency Removed np-parse-fail-token as a run-time dependency by making it a macro. The whole parser really needs to be revisited, but this should make it possible to generate compilers with intermediate language parser that do not have a run-time dependency on the nanopass framework. nanopass/parser.ss, nanopass/helpers.ss, nanopass/implementation-helpers.chezscheme.sls, nanopass/implementation-helpers.ikarus.ss, nanopass/implementation-helpers.ironscheme.sls, nanopass/implementation-helpers.vicare.sls# Please enter the commit message for your changes. Lines starting --- LOG | 10 ++++++++++ nanopass/helpers.ss | 3 --- nanopass/implementation-helpers.chezscheme.sls | 6 ------ nanopass/implementation-helpers.ikarus.ss | 6 ------ nanopass/implementation-helpers.ironscheme.sls | 7 ------- nanopass/implementation-helpers.vicare.sls | 6 ------ nanopass/parser.ss | 9 +++++++++ 7 files changed, 19 insertions(+), 28 deletions(-) diff --git a/LOG b/LOG index f771872..16d5224 100644 --- a/LOG +++ b/LOG @@ -820,3 +820,13 @@ LATEST nano-syntax-dispatch) library. With this change the pattern no longer needs to be quoted in the output of define-parser. nanopass/nano-syntax-dispatch.ss, nanopass/parser.ss +2020-10-18 - + * Removed np-parse-fail-token as a run-time dependency by making it a macro. + The whole parser really needs to be revisited, but this should make it + possible to generate compilers with intermediate language parser that do + not have a run-time dependency on the nanopass framework. + nanopass/parser.ss, nanopass/helpers.ss, + nanopass/implementation-helpers.chezscheme.sls, + nanopass/implementation-helpers.ikarus.ss, + nanopass/implementation-helpers.ironscheme.sls, + nanopass/implementation-helpers.vicare.sls diff --git a/nanopass/helpers.ss b/nanopass/helpers.ss index 71f8a98..0bcd10e 100644 --- a/nanopass/helpers.ss +++ b/nanopass/helpers.ss @@ -58,9 +58,6 @@ ;; the base record, so that we can use gensym syntax define-nanopass-record - ;; failure token so that we can know when parsing fails with a gensym - np-parse-fail-token - ;; handy syntactic stuff with-implicit with-r6rs-quasiquote with-extended-quasiquote extended-quasiquote with-auto-unquote diff --git a/nanopass/implementation-helpers.chezscheme.sls b/nanopass/implementation-helpers.chezscheme.sls index 2592aeb..259d031 100644 --- a/nanopass/implementation-helpers.chezscheme.sls +++ b/nanopass/implementation-helpers.chezscheme.sls @@ -49,9 +49,6 @@ ;; the base record, so that we can use gensym syntax define-nanopass-record - ;; failure token so that we can know when parsing fails with a gensym - np-parse-fail-token - ;; handy syntactic stuff with-implicit @@ -75,9 +72,6 @@ (nongenerative #{nanopass-record d47f8omgluol6otrw1yvu5-0}) (fields (immutable tag nanopass-record-tag))))]))) - ;; another gensym listed into this library - (define np-parse-fail-token '#{np-parse-fail-token dlkcd4b37swscag1dvmuiz-13}) - ;; the following should get moved into Chez Scheme proper (and generally ;; cleaned up with appropriate new Chez Scheme primitives for support) (define regensym diff --git a/nanopass/implementation-helpers.ikarus.ss b/nanopass/implementation-helpers.ikarus.ss index e972748..385c1cd 100644 --- a/nanopass/implementation-helpers.ikarus.ss +++ b/nanopass/implementation-helpers.ikarus.ss @@ -49,9 +49,6 @@ ;; the base record, so that we can use gensym syntax define-nanopass-record - ;; failure token so that we can know when parsing fails with a gensym - np-parse-fail-token - ;; handy syntactic stuff with-implicit @@ -80,9 +77,6 @@ (nongenerative #{nanopass-record d47f8omgluol6otrw1yvu5-0}) (fields (immutable tag nanopass-record-tag))))]))) - ;; another gensym listed into this library - (define np-parse-fail-token '#{np-parse-fail-token dlkcd4b37swscag1dvmuiz-13}) - (define-syntax eq-hashtable-set! (identifier-syntax hashtable-set!)) (define-syntax eq-hashtable-ref (identifier-syntax hashtable-ref)) diff --git a/nanopass/implementation-helpers.ironscheme.sls b/nanopass/implementation-helpers.ironscheme.sls index 79b3e38..f22a059 100644 --- a/nanopass/implementation-helpers.ironscheme.sls +++ b/nanopass/implementation-helpers.ironscheme.sls @@ -49,9 +49,6 @@ ;; the base record, so that we can use gensym syntax define-nanopass-record - ;; failure token so that we can know when parsing fails with a gensym - np-parse-fail-token - ;; handy syntactic stuff with-implicit @@ -89,10 +86,6 @@ (nongenerative nanopass-record-d47f8omgluol6otrw1yvu5-0) (fields (immutable tag nanopass-record-tag))))]))) - ;; another gensym listed into this library - ;; what is this used for? - (define np-parse-fail-token 'np-parse-fail-token-dlkcd4b37swscag1dvmuiz-13) - (define-syntax eq-hashtable-set! (identifier-syntax hashtable-set!)) (define-syntax eq-hashtable-ref (identifier-syntax hashtable-ref)) diff --git a/nanopass/implementation-helpers.vicare.sls b/nanopass/implementation-helpers.vicare.sls index a2d3886..c8a53ca 100644 --- a/nanopass/implementation-helpers.vicare.sls +++ b/nanopass/implementation-helpers.vicare.sls @@ -48,9 +48,6 @@ ;; the base record, so that we can use gensym syntax define-nanopass-record - ;; failure token so that we can know when parsing fails with a gensym - np-parse-fail-token - ;; handy syntactic stuff with-implicit @@ -84,9 +81,6 @@ (nongenerative #{nanopass-record d47f8omgluol6otrw1yvu5-0}) (fields (immutable tag nanopass-record-tag))))]))) - ;; another gensym listed into this library - (define np-parse-fail-token '#{np-parse-fail-token dlkcd4b37swscag1dvmuiz-13}) - (define-syntax eq-hashtable-set! (identifier-syntax hashtable-set!)) (define-syntax eq-hashtable-ref (identifier-syntax hashtable-ref)) diff --git a/nanopass/parser.ss b/nanopass/parser.ss index 038b3f2..fe07857 100644 --- a/nanopass/parser.ss +++ b/nanopass/parser.ss @@ -8,6 +8,15 @@ (nanopass syntaxconvert) (nanopass nano-syntax-dispatch)) + (define-syntax np-parse-fail-token + (let ([sym (datum->syntax #'* (gensym "np-parse-fail-token"))]) + (make-variable-transformer + (lambda (x) + (syntax-case x () + [id (identifier? #'id) (with-syntax ([sym sym]) #''sym)] + [(set! _ e) (syntax-violation 'np-parse-fail-token "misplaced use of keyword" x)] + [(_ e ...) (syntax-violation 'np-parse-fail-token "misplaced use of keyword" x)]))))) + (define-syntax parse-or (syntax-rules (on-error) [(_ (on-error ?err0)) ?err0]