;; nyacc/lang/c99/c99-04.test		-*- scheme -*-
;;
;; Copyright (C) 2017 Matthew R. Wette
;; 
;; Copying and distribution of this file, with or without modification,
;; are permitted in any medium without royalty provided the copyright
;; notice and this notice are preserved.  This file is offered as-is,
;; without any warranty.

;; test C99 parser in decl mode

(define-module (c99-04)
  #:use-module (nyacc lang c99 parser)
  #:use-module (nyacc lang c99 util1)
  #:use-module (test-suite lib))

(define incs '("exam.d"))

(define (parse-string str)
  (with-input-from-string str
    (lambda ()
      (parse-c99 #:inc-dirs incs #:mode 'decl #:inc-help c99-std-help))))

(define (parse-file file)
  (with-input-from-file file
    (lambda ()
      (parse-c99 #:inc-dirs incs #:mode 'decl))))

;; parser test
(with-test-prefix "nyacc/c99-04, decl mode"

  ;; parse with include file
  (pass-if "remove CPP control, leave include"
    (equal?
     (parse-file "exam.d/ex14.c")
     '(trans-unit
       (cpp-stmt
	(include
	 (@ (path "exam.d/ex14.h"))
	 "\"ex14.h\""
	 (trans-unit
          (decl (decl-spec-list
		 (stor-spec (typedef))
		 (type-spec (fixed-type "int")))
                (init-declr-list (init-declr (ident "eval_t")))))))
       (cpp-stmt (define (name "ABC") (repl "")))
       (decl (decl-spec-list (type-spec (typename "eval_t")))
	     (init-declr-list (init-declr (ident "x"))))
       (comment " used by c99-04.test "))))
  )

;; --- last line ---
