Created
January 27, 2018 21:15
-
-
Save cheery/d3030435b47eefa0481adaa8b0697e3d to your computer and use it in GitHub Desktop.
Preparsing of AXIOM spad files with the original preparser.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; This program uses Axiom's preprocessor to resolve the | |
; indentation layout in .spad files. | |
; They become easier to parse by other systems. | |
; HOW TO USE: | |
; Rewrite these variables in this file to match paths in your system. | |
(setq destination-dir "algebra.preparse/") | |
(setq source-dir "mnt/ubuntu/src/algebra/*.spad") | |
; Start Axiom | |
; Write in )lisp (load "preparse-spad-files.cl") | |
; The documentation in the book volume 9 made it easy to | |
; determine which functions to call in order to achieve this. | |
(defun preparse-and-output (in-path out-path) | |
; Booting up the spad reader.. I'm not sure if it's necessary though, | |
; but it seemed to need this. | |
(init-boot/spad-reader) | |
(setq in-stream (open in-path)) | |
(setq out-stream (open out-path | |
:direction :output | |
:if-exists :supersede)) | |
(initialize-preparse in-stream) | |
(setq boot-line-stack (preparse in-stream)) | |
; The boot-line-stack is a list of lines with linenumbers on them. | |
; This inserts empty lines to keep the line numbers | |
; consistent with original spad files. | |
(setq ll 0) | |
(loop for (lno . line) in boot-line-stack do | |
(loop while (< ll lno) do | |
(terpri out-stream) | |
(incf ll)) | |
(write-string line out-stream)) | |
(terpri out-stream) | |
(shut in-stream) | |
(shut out-stream) | |
nil) | |
; If you want to use this, I am certain you don't want to | |
; go through every file one at a time yourself. | |
(ensure-directories-exist destination-dir) | |
(loop for in-path in (directory source-dir) do | |
(preparse-and-output | |
in-path | |
(merge-pathnames destination-dir (file-namestring in-path)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment