From d7d4e2c94adc91d8bcc5647174d74514aa23df12 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 21 Mar 2023 09:44:56 -0500 Subject: Add header and change perms --- fff.scm | 42 ++++++++++++++++++++++++++++++++++++++++-- test-fff.scm | 23 +++++++++++++++++++++++ test.fff | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 2 deletions(-) mode change 100644 => 100755 fff.scm create mode 100644 test-fff.scm create mode 100644 test.fff diff --git a/fff.scm b/fff.scm old mode 100644 new mode 100755 index 6e524ad..e4409e8 --- a/fff.scm +++ b/fff.scm @@ -1,5 +1,43 @@ -(use-modules (ice-9 peg) - (ice-9 match)) +#!/bin/sh +#| -*- scheme -*- +exec guile -e main -s "$0" "$@" + +Flat Fuck Format +--- a new configuration format, because who doesn't need that? + +Copyright (C) 2023 Case Duckworth + +Everyone is permitted to do whatever with this software, without +limitation. This software comes without any warranty whatsoever, +but with two pieces of advice: + +- Don't hurt yourself. +- Make good choices. + +Commentary: + +This script will convert files defined in the Flat Fuck Format (fff) into json. +It will not convert anything back to fff. fff is explicitly made to be as +simple as possible, and exclusively human-written. If a machine writes your +configuration, ... use a better configuration format. Or make your program +scriptable! + +FLAT FUCK FORMAT : Specification +|# +!# + +(define-module (fff) + #:use-module (ice-9 peg) + #:use-module (ice-9 match) + #:use-module (srfi srfi-11) + #:version (0 1 0) + #:export (fff + fff? + fff/comments? + fff->scm)) + + +;;; PEG Grammar (define-peg-pattern fff all (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 @@ +(use-modules (ice-9 format) + (ice-9 peg) + (ice-9 textual-ports) + (fff)) + +(define (read-file file) + (call-with-input-file file get-string-all)) + +(define (test-parse input) + (let loop ((str "") + (num 0) + (lst (string-split input #\newline))) + (cond + ((null? lst) (match-pattern fff str)) + ((not (match-pattern fff str)) + (format #t "!!!!!!!!!!!!!!!!!!!!!!!~%~s~%" lst)) + (else + (format #t "~s~%~%" (peg:tree (match-pattern fff str))) + (when (match-pattern fff str) + (format #t "~s~%" (car lst))) + (loop (string-append str "\n" (car lst)) + (+ num 1) + (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 @@ +# fff test file +## mime-type: text/flat-as-fuck or text/plain + +## "naked" items + +naked1: value1 +naked2: value2 + +## objects +# objects are names followed by 2 colons then a block of items +# a blank line ends the object. + +U.S. Capitals:: +Alaska: Anchorage +New York: Albany + +World capitals:: +France: Paris +Mexico: Mexico City + +## arrays +# arrays are similar to objects, except the items don't have keys. +# you can't have "naked" array items, because fff files always map to json objects. + +My favorite fruit:: +: apple +: banana +: grape + +Vegetables I hate:: +: mushrooms +: corn + +## References +# For structure, you can reference previously-defined objects, arrays, and items as values. +# Prepend the thing's name with "@". + +Capitals:: +: @U.S. Capitals +: @World capitals + +## You can put pretty much anything in the name of something or its value. +# If you need to escape it, use a backslash. + +Fargo\: the movie: one of the films of all time +You can even: escape new lines \ + with a backslash. it'll delete all the space preceding the value \ + on the \#next line so you can have nice hanging indents. \ +\ (If you need weird spacing ... you can do this weird backslash thing.) + +My twitter handle: \@iDontHaveOneLol -- cgit 1.4.1-21-gabe81