summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--antiformatter/LICENSE25
-rw-r--r--antiformatter/README.md38
-rw-r--r--antiformatter/antifmt.rkt27
-rw-r--r--antiformatter/src/formatter.rkt52
-rw-r--r--antiformatter/src/info.rkt6
-rw-r--r--antiformatter/src/test.rkt11
6 files changed, 159 insertions, 0 deletions
diff --git a/antiformatter/LICENSE b/antiformatter/LICENSE
new file mode 100644
index 0000000..e836428
--- /dev/null
+++ b/antiformatter/LICENSE
@@ -0,0 +1,25 @@
+the fuck around and find out license v0.1
+
+copyright (c) 2023 JJ <https://j-james.me>
+
+permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "software"), to deal
+in the software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the software, and to permit persons to whom the software is
+furnished to do so, subject to the following conditions:
+
+the above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the software.
+
+the software shall be used for Good, not Evil. the original author of the
+software retains the sole and exclusive right to determine which uses are Good
+and which uses are Evil. (making the lives of TAs harder is Good.)
+
+the software is provided "as is", without warranty of any kind, express or
+implied, including but not limited to the warranties of merchantability,
+fitness for a particular purpose and noninfringement. in no event shall the
+authors or copyright holders be liable for any claim, damages or other
+liability, whether in an action of contract, tort or otherwise, arising from,
+out of or in connection with the software or the use or other dealings in the
+software.
diff --git a/antiformatter/README.md b/antiformatter/README.md
new file mode 100644
index 0000000..1eac8b1
--- /dev/null
+++ b/antiformatter/README.md
@@ -0,0 +1,38 @@
+# antiformatter: attempting to make the worst possible passable racket code
+
+usage: `racket antifmt.rkt <file>`
+
+regular racket code. boring to read, easy on the eyes. booooooo
+```rkt
+(define (mangle sexp)
+ (if (not (list? sexp)) (error 'mangle "not an s-exp")
+ (if (empty? sexp) ""
+ (let ((paren (random-paren)))
+ (string-append
+ (first paren)
+ (mangle-params sexp)
+ (random-newline)
+ (last paren))))))
+```
+
+anti-formatted racket code. exciting! an adventure to understand! still compiles (usually)
+```rkt
+[define [mangle sexp
+
+] [if (not [list? sexp
+] ) [error {quote mangle } "not an s-exp"
+] (if {empty? sexp
+
+} "" [let {{paren {random-paren
+}
+}
+} [string-append {first paren } (mangle-params sexp
+
+) {random-newline } [last paren ] ]
+]
+
+)
+
+]
+]
+```
diff --git a/antiformatter/antifmt.rkt b/antiformatter/antifmt.rkt
new file mode 100644
index 0000000..d9f93af
--- /dev/null
+++ b/antiformatter/antifmt.rkt
@@ -0,0 +1,27 @@
+#lang racket
+
+(require racket/cmdline)
+(require "src/formatter.rkt")
+
+; (define mangle-parenthesis? (make-parameter #t))
+; (define mangle-newlines? (make-parameter #t))
+
+(command-line
+ #:program "antifmt"
+ #:once-each
+ [("-p" "--mangle-parens")
+ "Toggle mangling of parenthesis: on by default"
+ (mangle-parens? #f)]
+ [("-i" "--mangle-indents")
+ "Toggle mangling of indentation: off by default"
+ (mangle-indents? #t)]
+ [("-n" "--mangle-newlines")
+ "Toggle mangling of newlines: on by default"
+ (mangle-newlines? #f)]
+ #:args (loc)
+ (display
+ (string-append ; what the fuck
+ (mangle (parameterize ([read-accept-lang #t] [read-accept-reader #t])
+ (sequence->list (in-producer read eof
+ (open-input-file loc)))))
+ "\n")))
diff --git a/antiformatter/src/formatter.rkt b/antiformatter/src/formatter.rkt
new file mode 100644
index 0000000..770251f
--- /dev/null
+++ b/antiformatter/src/formatter.rkt
@@ -0,0 +1,52 @@
+#lang racket
+
+(require racket/cmdline)
+(provide mangle mangle-parens? mangle-indents? mangle-newlines?)
+
+(define (random-paren)
+ (match (random 0 3)
+ (0 (list "(" ")"))
+ (1 (list "[" "]"))
+ (2 (list "{" "}"))))
+
+(define (random-newline)
+ (make-string (random 0 3) #\newline))
+
+(define (random-indentation at-least)
+ (make-string (+ at-least (random 0 3)) #\space))
+
+(define indent 0)
+(define mangle-parens? (make-parameter #t))
+(define mangle-indents? (make-parameter #f))
+(define mangle-newlines? (make-parameter #t))
+
+; horrid hack
+(define (mangle sexp)
+ (string-append "#lang racket \n"
+ (mangle-sexp (rest (first (rest (rest (rest (first sexp)))))))))
+
+(define (mangle-sexp sexp)
+ (set! indent (+ indent 2))
+ (if (not (list? sexp)) (error 'mangle "not an s-exp")
+ (if (empty? sexp) ""
+ (let ((paren (random-paren)))
+ (string-append
+ (if (mangle-indents?) (random-indentation indent) "")
+ (if (mangle-parens?) (first paren) ")")
+ (mangle-params sexp)
+ (if (mangle-newlines?) (random-newline) "")
+ (if (mangle-indents?) (random-indentation indent) "")
+ (if (mangle-parens?) (last paren) ")"))))))
+
+(define (mangle-params sexp)
+ (set! indent (max (- indent 2) 0))
+ (if (not (list? sexp)) (~a sexp)
+ (if (empty? sexp) ""
+ (let ((param (first sexp)))
+ (string-join (list
+ (if (list? param)
+ (mangle-sexp param)
+ (if (string? param)
+ (string-append "\"" (~a param) "\"")
+ (~a param)))
+ (mangle-params (rest sexp))))))))
diff --git a/antiformatter/src/info.rkt b/antiformatter/src/info.rkt
new file mode 100644
index 0000000..b4c6f0b
--- /dev/null
+++ b/antiformatter/src/info.rkt
@@ -0,0 +1,6 @@
+#lang info
+
+(define name "antifmt")
+(define pkg-desc "attempting to make the worst possible passable racket code")
+(define pkg-authors '(apropos))
+(define license '(FAFOL))
diff --git a/antiformatter/src/test.rkt b/antiformatter/src/test.rkt
new file mode 100644
index 0000000..57e6367
--- /dev/null
+++ b/antiformatter/src/test.rkt
@@ -0,0 +1,11 @@
+#lang racket
+
+(define (mangle sexp)
+ (if (not (list? sexp)) (error 'mangle "not an s-exp")
+ (if (empty? sexp) ""
+ (let ((paren (random-paren)))
+ (string-append
+ (first paren)
+ (mangle-params sexp)
+ (random-newline)
+ (last paren))))))