From 0c594ea788f31c561a9d617d5c0764f99429599b Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 8 Jun 2023 23:03:54 -0500 Subject: Rewrite; rename to chicken-scratch --- chicken-heredoc.scm | 60 ----------------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100755 chicken-heredoc.scm (limited to 'chicken-heredoc.scm') diff --git a/chicken-heredoc.scm b/chicken-heredoc.scm deleted file mode 100755 index e0e55ad..0000000 --- a/chicken-heredoc.scm +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh -#| -*- scheme -*- -exec csi -ss "$0" "$@" -heredocs for chicken -idea-https://git.sr.ht/~evhan/beaker/tree/master/item/aux/generate-wiki-page.scm -|# - -(import (only (chicken irregex) - irregex-replace/all - irregex-search) - (only (chicken io) - read-string) - (only (chicken port) - make-concatenated-port) - (only (chicken random) - pseudo-random-real) - (only (chicken time) - current-seconds)) - -(define filestr - (make-parameter #f)) - -(define def-end - (make-parameter "&def-end")) - -(define (randomizer #!optional str) - (let ((base (number->string (+ (current-seconds) - (pseudo-random-real))))) - (if (and str (irregex-search base str)) - (randomizer str) - base))) - -(define-syntax def - (syntax-rules () - ((def var val) - ;; I'm pretty sure this only works in CHICKEN. - (begin (set! var val) - (def-end))))) - -(define (heredoc-expand file) - (let* ((delim (string-append "END-" (randomizer))) - (template (make-concatenated-port - (open-input-string (string-append "#<#" delim "\n")) - (open-input-file file) - (open-input-string (string-append "\n" delim "\n")))) - (expanded (open-output-string)) - (str (begin - (display (eval (read template)) expanded) - (get-output-string expanded)))) - (irregex-replace/all `(seq ,(def-end) (* "\n")) - str - ""))) - -(define (main args) - (for-each (lambda (f) - ;; Is this overkill? Maybe.... - (parameterize ((filestr (with-input-from-file f read-string))) - (parameterize ((def-end (randomizer (filestr)))) - (display (heredoc-expand f))))) - args)) -- cgit 1.4.1-21-gabe81