about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-x[-rw-r--r--]fff.scm42
-rw-r--r--test-fff.scm23
-rw-r--r--test.fff51
3 files changed, 114 insertions, 2 deletions
diff --git a/fff.scm b/fff.scm index 6e524ad..e4409e8 100644..100755 --- a/fff.scm +++ b/fff.scm
@@ -1,5 +1,43 @@
1(use-modules (ice-9 peg) 1#!/bin/sh
2 (ice-9 match)) 2#| -*- scheme -*-
3exec guile -e main -s "$0" "$@"
4
5Flat Fuck Format
6--- a new configuration format, because who doesn't need that?
7
8Copyright (C) 2023 Case Duckworth <acdw@acdw.net>
9
10Everyone is permitted to do whatever with this software, without
11limitation. This software comes without any warranty whatsoever,
12but with two pieces of advice:
13
14- Don't hurt yourself.
15- Make good choices.
16
17Commentary:
18
19This script will convert files defined in the Flat Fuck Format (fff) into json.
20It will not convert anything back to fff. fff is explicitly made to be as
21simple as possible, and exclusively human-written. If a machine writes your
22configuration, ... use a better configuration format. Or make your program
23scriptable!
24
25FLAT FUCK FORMAT : Specification
26|#
27!#
28
29(define-module (fff)
30 #:use-module (ice-9 peg)
31 #:use-module (ice-9 match)
32 #:use-module (srfi srfi-11)
33 #:version (0 1 0)
34 #:export (fff
35 fff?
36 fff/comments?
37 fff->scm))
38
39
40;;; PEG Grammar
3 41
4(define-peg-pattern fff all 42(define-peg-pattern fff all
5 (and (* (or WHITESPACE NEWLINE)) 43 (and (* (or WHITESPACE NEWLINE))
diff --git a/test-fff.scm b/test-fff.scm new file mode 100644 index 0000000..f1cf746 --- /dev/null +++ b/test-fff.scm
@@ -0,0 +1,23 @@
1(use-modules (ice-9 format)
2 (ice-9 peg)
3 (ice-9 textual-ports)
4 (fff))
5
6(define (read-file file)
7 (call-with-input-file file get-string-all))
8
9(define (test-parse input)
10 (let loop ((str "")
11 (num 0)
12 (lst (string-split input #\newline)))
13 (cond
14 ((null? lst) (match-pattern fff str))
15 ((not (match-pattern fff str))
16 (format #t "!!!!!!!!!!!!!!!!!!!!!!!~%~s~%" lst))
17 (else
18 (format #t "~s~%~%" (peg:tree (match-pattern fff str)))
19 (when (match-pattern fff str)
20 (format #t "~s~%" (car lst)))
21 (loop (string-append str "\n" (car lst))
22 (+ num 1)
23 (cdr lst))))))
diff --git a/test.fff b/test.fff new file mode 100644 index 0000000..5df4000 --- /dev/null +++ b/test.fff
@@ -0,0 +1,51 @@
1# fff test file
2## mime-type: text/flat-as-fuck or text/plain
3
4## "naked" items
5
6naked1: value1
7naked2: value2
8
9## objects
10# objects are names followed by 2 colons then a block of items
11# a blank line ends the object.
12
13U.S. Capitals::
14Alaska: Anchorage
15New York: Albany
16
17World capitals::
18France: Paris
19Mexico: Mexico City
20
21## arrays
22# arrays are similar to objects, except the items don't have keys.
23# you can't have "naked" array items, because fff files always map to json objects.
24
25My favorite fruit::
26: apple
27: banana
28: grape
29
30Vegetables I hate::
31: mushrooms
32: corn
33
34## References
35# For structure, you can reference previously-defined objects, arrays, and items as values.
36# Prepend the thing's name with "@".
37
38Capitals::
39: @U.S. Capitals
40: @World capitals
41
42## You can put pretty much anything in the name of something or its value.
43# If you need to escape it, use a backslash.
44
45Fargo\: the movie: one of the films of all time
46You can even: escape new lines \
47 with a backslash. it'll delete all the space preceding the value \
48 on the \#next line so you can have nice hanging indents. \
49\ (If you need weird spacing ... you can do this weird backslash thing.)
50
51My twitter handle: \@iDontHaveOneLol