nyacc: have something working for in-place include

This commit is contained in:
Matt Wette 2017-01-01 19:40:27 -08:00 committed by Jan Nieuwenhuizen
parent f5d1522166
commit 7b665385c9
4 changed files with 37 additions and 33 deletions

View file

@ -1,23 +1,29 @@
2016-11-25 Matt Wette <mwette@nautilus>
2017-01-01 Matt Wette <mwette@alumni.caltech.edu>
* lang/c99/body.scm (gen-c-lexer): in code mode now expands includes
* lang/c99/pprint.scm (pretty-print-c99): added enum-dev w/o name
2016-11-25 Matt Wette <mwette@alumni.caltech.edu>
* added support for ellipsis to lang/c99/cpp.scm
2016-11-24 Matt Wette <mwette@nautilus>
2016-11-24 Matt Wette <mwette@alumni.caltech.edu>
* added (ellipsis) to lang/c99/pprint.scm
2016-04-09 Matt Wette <mwette@nautilus>
2016-04-09 Matt Wette <mwette@alumni.caltech.edu>
* bison.scm: new file providing make-lalr-machin/bison. It is
similar to make-lalr-machine but uses external bison program
instead of the default from-scratch lalr code.
2016-03-04 Matt Wette <mwette@nautilus>
2016-03-04 Matt Wette <mwette@alumni.caltech.edu>
* lalr.scm: changed grammar parser to interpret $string as
terminal. This saves typing a quote in front.
Copyright (C) 2015,2016 Matthew R. Wette
Copyright (C) 2015-2017 Matthew R. Wette
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright

View file

@ -307,26 +307,29 @@
(define (exec-cpp line)
;; Parse the line into a CPP stmt, execute it, and return it.
(let* ((stmt (read-cpp-stmt line))
(perr (lambda (file)
(throw 'parse-error "file not found: ~S" file))))
(let* ((stmt (read-cpp-stmt line)))
(case (car stmt)
((include)
(let* ((parg (cadr stmt)) (leng (string-length parg))
(file (substring parg 1 (1- leng)))
(path (find-file-in-dirl file (cpi-incs info)))
(tynd (assoc-ref (cpi-tynd info) file)))
(if tynd
(for-each add-typename tynd)
(let* ((pth (find-file-in-dirl file (cpi-incs info)))
(tree (if pth ; path exists
(or (with-input-from-file pth run-parse)
(throw 'parse-error "~A" pth))
(perr file))))
(simple-format #t "INCLUDE top?=~S\n" (at-top?))
(for-each add-define (xp1 tree)) ; add def's
;; Attach tree onto "include" statement.
(if (pair? tree) (set! stmt (append stmt (list tree))))
))))
(cond
(tynd (for-each add-typename tynd)) ; in dot-h dict
((and #t (eqv? mode 'code)) ; include flat
(if (not path) (throw 'parse-error "not found: ~S" file))
(push-input (open-input-file path))
(set! stmt #f))
(else ; include as tree
(if (not path) (throw 'parse-error "not found: ~A" path))
(let* ((tree (with-input-from-file path run-parse)))
(if (not tree) (throw 'parse-error "~A" path))
;;(simple-format #t "INCLUDE top?=~S\n" (at-top?))
(for-each add-define (xp1 tree)) ; add def's
;; Attach tree onto "include" statement.
(if (pair? tree)
(set! stmt (append stmt (list tree)))
stmt))))))
((define)
(add-define stmt))
((undef)
@ -383,7 +386,7 @@
stmt)
(else
(error "unhandled cpp stmt")))
(cons 'cpp-stmt stmt)))
(if stmt (cons 'cpp-stmt stmt) '())))
;; Composition of @code{read-cpp-line} and @code{exec-cpp}.
(define (read-cpp ch)
@ -399,7 +402,10 @@
(bol
(cond
((read-comm ch bol) => assc-$)
((read-cpp ch) => assc-$)
((read-cpp ch) =>
(lambda (res)
;; not pair means expand include file, so loop again
(if (pair? res) (assc-$ res) (iter (read-char)))))
(else (set! bol #f) (iter ch))))
((read-ident ch) =>
(lambda (name)

View file

@ -336,6 +336,9 @@
((enum-def (ident ,name) (enum-def-list . ,edl))
(sf "enum ~A " name) (ppx `(enum-def-list . ,edl)))
((enum-def (enum-def-list . ,edl))
(sf "enum ") (ppx `(enum-def-list . ,edl)))
((enum-def-list . ,defns)
(sf "{\n") (push-il)
(for-each ppx defns)

View file

@ -63,17 +63,6 @@ the file COPYING included with the this distribution.")
(set-current-input-port (car ipstk))
(fluid-set! *input-stack* (cdr ipstk))))))
;; It may be possible to reimplement with closures, using soft-ports.
;; (push-string-input ...
#|
(define (push-string-input str)
(let* ((prev (current-input-port))
(port (make-soft-port ...))
)
#f))
|#
;; === tl ==============================
;; @section Tagged Lists