1 ;;; nyacc/lang/c99/xparser.scm - copied from parser.scm
3 ;;; Copyright (C) 2015 Matthew R. Wette
5 ;;; This program is free software: you can redistribute it and/or modify
6 ;;; it under the terms of the GNU General Public License as published by
7 ;;; the Free Software Foundation, either version 3 of the License, or
8 ;;; (at your option) any later version.
10 ;;; This program is distributed in the hope that it will be useful,
11 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;; GNU General Public License for more details.
15 ;;; You should have received a copy of the GNU General Public License
16 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (nyacc lang c99 xparser)
22 #:use-module (nyacc lex)
23 #:use-module (nyacc parse)
24 #:use-module (nyacc lang util)
25 #:use-module (nyacc lang c99 cpp)
26 #:use-module ((srfi srfi-9) #:select (define-record-type))
27 #:use-module ((sxml xpath) #:select (sxpath))
30 (include-from-path "nyacc/lang/c99/mach.d/c99xtab.scm")
31 (include-from-path "nyacc/lang/c99/body.scm")
32 (include-from-path "nyacc/lang/c99/mach.d/c99xact.scm")
34 ;; Parse given a token generator. Uses fluid @code{*info*}.
36 (let ((parser (make-lalr-parser
37 (list (cons 'len-v len-v) (cons 'pat-v pat-v)
38 (cons 'rto-v rto-v) (cons 'mtab mtab)
39 (cons 'act-v act-v)))))
40 (lambda* (lexer #:key (debug #f))
43 (lambda () (parser lexer #:debug debug))
44 (lambda (key fmt . args)
45 (report-error fmt args)
46 (pop-input) ; not sure this is right
47 (throw 'c99-error "C99 parse error"))))))
50 (let ((info (fluid-ref *info*)))
51 (raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
53 ;; @item {Procedure} parse-c99x [#:cpp-defs defs] [#:debug bool]
54 ;; This needs to be explained in some detail.
55 ;; [#:tyns '("foo_t")]
56 (define* (parse-c99x expr-string
58 (cpp-defs '()) ; CPP defines
59 (inc-help '()) ; include helper
60 (xdef? #f) ; pred to determine expand
62 (tyns '())) ; defined typenames
63 (with-input-from-string expr-string
68 (let ((info (make-cpi debug cpp-defs '(".") inc-help)))
69 (set-cpi-ptl! info (cons tyns (cpi-ptl info)))
73 (raw-parser (gen-c-lexer #:mode 'code #:xdef? xdef?)
75 (lambda (key fmt . rest)
76 (report-error fmt rest)