Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cxxxr/lisp-preprocessor
Common lisp embedded template engine
https://github.com/cxxxr/lisp-preprocessor
Last synced: 4 days ago
JSON representation
Common lisp embedded template engine
- Host: GitHub
- URL: https://github.com/cxxxr/lisp-preprocessor
- Owner: cxxxr
- License: mit
- Created: 2020-01-15T16:41:41.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-08T04:20:40.000Z (over 4 years ago)
- Last Synced: 2024-12-18T00:37:28.342Z (5 days ago)
- Language: Common Lisp
- Size: 18.6 KB
- Stars: 17
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lisp Preprocessor
Common Lisp embedded template engine
## Usage
### input
```common-lisp
#includeint main(void) {
#{ :indent
(loop :for i :from 0 :below 10
:do (format t "printf(\"Loop: %d\", ~D);~%" i)) #}
return 0;
}
```### compile
`(lisp-preprocessor:run-template-into-file #p"input" #p"output")`### output
```common-lisp
#includeint main(void) {
printf("Loop: %d", 0);
printf("Loop: %d", 1);
printf("Loop: %d", 2);
printf("Loop: %d", 3);
printf("Loop: %d", 4);
printf("Loop: %d", 5);
printf("Loop: %d", 6);
printf("Loop: %d", 7);
printf("Loop: %d", 8);
printf("Loop: %d", 9);
return 0;
}
```## API
### (run-template-into-stream compiland stream &rest arguments)
### (run-template-into-string compiland &rest arguments)
### (run-template-into-file compiland file &rest arguments)
```common-lisp
(let ((compiland (compile-template "#{ (princ (string-capitalize $arg)) #}" :arguments '($arg))))
(run-template-into-string compiland "test"))
; => "Test"
```
compiland is a string or pathname, or a compiled template function.### (compile-template text &key template-begin template-begin arguments)
```common-lisp
* (compile-template "foo #{ (princ \"bar\") #} baz") ; => #
* (run-template-into-stream * *standard-output*)
foo bar baz* (compile-template "foo {{{ (princ \"bar\" }}} baz" :template-begin "{{{" :template-end "}}}")
* (run-template-into-stream * *standard-output*)
foo bar baz* (run-template-into-stream (compile-template "#{ (princ (list ? ??)) #}" :arguments '(? ??)) *standard-output* "foo" "bar")
(foo bar)
```## Syntax
```
#{ template #}
```### indent
Keep indentation of start position```
#{ :indent [offset]
...
#}
``````c
// input
int main(void) {
#{ :indent
(loop :for i :from 0 :below 10
:do (format t "printf(\"Loop: %d\", ~D);~%" i)) #}
return 0;
}// output
int main(void) {
printf("Loop: %d", 0);
printf("Loop: %d", 1);
printf("Loop: %d", 2);
printf("Loop: %d", 3);
printf("Loop: %d", 4);
printf("Loop: %d", 5);
printf("Loop: %d", 6);
printf("Loop: %d", 7);
printf("Loop: %d", 8);
printf("Loop: %d", 9);
return 0;
}
```### chop
Chop whitespace before and after the template```
#{ :chop #}
``````common-lisp
;;; input
(defun foo (#{ (format t "~{~(~A~)~^ ~}" (loop :for symbol :in '(a b c) :collect symbol)) #}
#{ :chop #}
#{ (format t " ~{~(~A~)~^ ~}" (loop :for symbol :in '(x y z) :collect symbol)) #})
(values a b c x y z));;; output
(defun foo (a b c x y z)
(values a b c x y z))
```### License
MIT