about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2023-07-02 14:32:26 -0500
committerCase Duckworth2023-07-02 14:32:26 -0500
commit22c3f2da96853b3b1a36efe6766cf643545848b7 (patch)
tree3a24f9dfebae9b56fdcab9c2567cbb6e9cc14e86
parentAdd dependencies section (diff)
downloadchicken-scratch-22c3f2da96853b3b1a36efe6766cf643545848b7.tar.gz
chicken-scratch-22c3f2da96853b3b1a36efe6766cf643545848b7.zip
Add scratchdown main
-rw-r--r--.gitignore1
-rwxr-xr-xchicken-scratch.mod.scm10
-rwxr-xr-xchicken-scratch.scm2
-rw-r--r--makefile8
-rwxr-xr-xscratchdown.scm55
5 files changed, 70 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore index 8b6a74a..5b41b96 100644 --- a/.gitignore +++ b/.gitignore
@@ -1,4 +1,5 @@
1chicken-scratch 1chicken-scratch
2scratchdown
2*.link 3*.link
3*.so 4*.so
4*.o 5*.o
diff --git a/chicken-scratch.mod.scm b/chicken-scratch.mod.scm index e47ad67..0ba704e 100755 --- a/chicken-scratch.mod.scm +++ b/chicken-scratch.mod.scm
@@ -27,8 +27,7 @@
27(module chicken-scratch 27(module chicken-scratch
28 (expand-string 28 (expand-string
29 expand-port 29 expand-port
30 def 30 def %def/replacer)
31 %def/replacer)
32 31
33 (import scheme 32 (import scheme
34 (chicken base) 33 (chicken base)
@@ -50,13 +49,16 @@
50 (let* ((delim (random-string-not-in str)) 49 (let* ((delim (random-string-not-in str))
51 (template (make-concatenated-port 50 (template (make-concatenated-port
52 (open-input-string (string-append "#<#" delim "\n")) 51 (open-input-string (string-append "#<#" delim "\n"))
53 (open-input-string (irregex-replace "^#!.*\n" str "")) 52 (open-input-string "#(import chicken-scratch)")
53 (open-input-string str)
54 (open-input-string (string-append "\n" delim "\n")))) 54 (open-input-string (string-append "\n" delim "\n"))))
55 (expanded (open-output-string)) 55 (expanded (open-output-string))
56 (output (begin 56 (output (begin
57 (display (eval (read template)) expanded) 57 (display (eval (read template)) expanded)
58 (get-output-string expanded)))) 58 (get-output-string expanded))))
59 (irregex-replace/all `(seq ,(%def/replacer) (* "\n")) 59 (irregex-replace/all `(: (or "#<unspecified>"
60 ,(%def/replacer))
61 (* whitespace))
60 output 62 output
61 "")))) 63 ""))))
62 64
diff --git a/chicken-scratch.scm b/chicken-scratch.scm index 6d06fb6..307aa8d 100755 --- a/chicken-scratch.scm +++ b/chicken-scratch.scm
@@ -11,6 +11,8 @@ License: BSD-3. See COPYING for details.
11 (chicken process-context)) 11 (chicken process-context))
12 12
13(define (main args) 13(define (main args)
14 ;; XXX: handle standard input piping
15 ;; XXX: Must have an #(import chicken-scratch at the beginning)
14 (for-each (lambda (file) 16 (for-each (lambda (file)
15 (when (file-exists? file) 17 (when (file-exists? file)
16 (display (with-input-from-file file expand-port)) 18 (display (with-input-from-file file expand-port))
diff --git a/makefile b/makefile index ffa747a..7587a65 100644 --- a/makefile +++ b/makefile
@@ -9,9 +9,12 @@ SOURCES = chicken-scratch.scm chicken-scratch.mod.scm
9chicken-scratch: $(SOURCES) 9chicken-scratch: $(SOURCES)
10 chicken-install -n 10 chicken-install -n
11 11
12scratchdown: scratchdown.scm chicken-scratch
13 csc $<
14
12.PHONY: install 15.PHONY: install
13install: chicken-scratch 16install: chicken-scratch scratchdown
14 install -Dt $(PREFIX)/bin $< 17 install -Dt $(PREFIX)/bin $^
15 18
16.PHONY: chicken-install 19.PHONY: chicken-install
17chicken-install: chicken-scratch 20chicken-install: chicken-scratch
@@ -20,3 +23,4 @@ chicken-install: chicken-scratch
20.PHONY: clean 23.PHONY: clean
21clean: 24clean:
22 rm -f *.link *.so *.o *.build.sh *.import.scm *.install.sh 25 rm -f *.link *.so *.o *.build.sh *.import.scm *.install.sh
26 rm -f chicken-scratch scratchdown
diff --git a/scratchdown.scm b/scratchdown.scm new file mode 100755 index 0000000..2775e3f --- /dev/null +++ b/scratchdown.scm
@@ -0,0 +1,55 @@
1#!/bin/sh
2#| -*- scheme -*-
3exec csi -s "$0" "$@"
4SCRATCHDOWN --- Combine markdown and chicken-scratch
5|#
6
7(import (chicken io)
8 (chicken irregex)
9 (chicken process-context)
10 (chicken-scratch)
11 (html-parser)
12 (lowdown)
13 (sxml-transforms)
14 (utf8))
15
16(define (expand* text)
17 (expand-string
18 (irregex-replace/all '(or (: #\# #\# (look-ahead (or #\{ #\()))
19 (: #\# (look-ahead (~ #\{ #\()))
20 (: #\# eos))
21 text
22 "##")))
23
24#;(define (list-of-strings? xs)
25 (cond
26 ((null? xs) #t)
27 ((not (string? (car xs))) #f)
28 (else (list-of-strings? (cdr xs)))))
29
30#;(define (expand-text x)
31 (print x)
32 (cond
33 ((symbol? x) x)
34 ((string? x)
35 (expand* x))
36 ((list-of-strings? x)
37 (expand* (apply string-append x)))
38 ((list-of-strings? (cdr x))
39 (cons (car x)
40 (expand-text (cdr x))))
41 ((list? x)
42 (map expand-text x))
43 (else x)))
44
45(define (read-and-expand file)
46 (let* ((text (with-input-from-file file read-string))
47 (expd (irregex-replace "^#!.*\n" (expand* text) ""))
48 #;(sexp (markdown->sxml expd))
49 )
50 (markdown->html expd)))
51
52(define (main args)
53 (for-each read-and-expand args))
54
55(main (command-line-arguments))