diff options
author | Fernando Borretti <eudoxiahp@gmail.com> | 2024-02-06 07:20:29 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-06 07:20:29 +1100 |
commit | aa6efcbfe77d619ec92fbb83216bab5b0db3ea8c (patch) | |
tree | ae7c2e797f8e0862f7b27bcd44367d6e2a50fba7 | |
parent | c1f419564a21c878ab62a54c2c45ee07d2968242 (diff) | |
parent | 3791014c9de97a06d04464e070385a5cdd91b294 (diff) |
Merge pull request #21 from caffe3/fix-no-expand
Fix missing --no-expand impl
-rw-r--r-- | src/cmacro.lisp | 16 | ||||
-rw-r--r-- | src/macroexpand.lisp | 3 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/cmacro.lisp b/src/cmacro.lisp index 12985a2..a70e055 100644 --- a/src/cmacro.lisp +++ b/src/cmacro.lisp @@ -2,7 +2,8 @@ (defpackage cmacro (:use :cl :anaphora) (:import-from :cmacro.macroexpand - :macroexpand-pathname) + :macroexpand-pathname + :macronoexpand-pathname) (:import-from :cmacro.printer :print-ast) (:export :main)) @@ -49,13 +50,15 @@ ;; It's a file (first sub-args)))))) -(defun process-file (pathname) - (print-ast (macroexpand-pathname pathname))) +(defun process-file (no-expand pathname) + (if no-expand + (print-ast (macronoexpand-pathname pathname)) + (print-ast (macroexpand-pathname pathname)))) (defparameter +help+ "Usage: cmc [file]* [option]* - -o, --output Path to the output file + -o,--output Path to the output file -n,--no-expand Don't macroexpand, but remove macro definitions -h,--help Print this text") @@ -64,6 +67,7 @@ (files (cdr args) (list "-n" "--no-expand")))) (output-file (get-opt-value args "-o" "--output")) + (no-expand (get-binary-opt args "-n" "--no-expand")) (helpp (get-binary-opt args "-h" "--help"))) (when helpp (format t "~A~%" +help+) @@ -78,10 +82,10 @@ :if-does-not-exist :create :if-exists :supersede) (loop for file in files do - (write-string (process-file file) + (write-string (process-file no-expand file) stream))) ;; Write to stdout (progn (loop for file in files do - (write-string (process-file file))))) + (write-string (process-file no-expand file))))) (terpri))) diff --git a/src/macroexpand.lisp b/src/macroexpand.lisp index c810551..903aad6 100644 --- a/src/macroexpand.lisp +++ b/src/macroexpand.lisp @@ -92,3 +92,6 @@ (defun macroexpand-pathname (pathname) (macroexpand-result (extract-macros (parse-pathname pathname)))) + +(defun macronoexpand-pathname (pathname) + (result-ast (extract-macros (parse-pathname pathname)))) |