From 0a78720644e45bd27c4a57cbddf2d32aacb555c3 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 29 Jun 2022 00:59:59 -0500 Subject: Probably version ... whatever the next higher one is --- trainfuck | 123 +++----------------------------------------------------------- 1 file changed, 5 insertions(+), 118 deletions(-) (limited to 'trainfuck') diff --git a/trainfuck b/trainfuck index 602fc92..22d1009 100755 --- a/trainfuck +++ b/trainfuck @@ -1,128 +1,15 @@ -#!/bin/awk -f -# TRAINFUCK: CHOO CHOO MUTHAFUCKA -*- awk -*- +#!/bin/sh +# TRAINFUCK: CHOO CHOO MUTHAFUCKA -*- sh -*- # Author: Case Duckworth # License: WTFPL # Version: #9 ### Commentary: -# LANGUAGE - -# trainfuck is not case-sensitive -# -- except for ALL ABOARD and END OF THE LINE -# ignore everything before ALL ABOARD -# ignore everything after END OF THE LINE -# (this means you can comment between these) -# bf tf -# + chug -# - chugga -# > choo -# < choo choo -# . click OR clickety -# , clack -# [ tickets please -# ] your ticket please -# syntax does NOT WRAP across line breaks -# anything else is an error and DERAILS the train +# shell wrapper around trainfuck.awk, which see. ### Code: -BEGIN { - aboard = 0 - width = 30 - print "[" -} - -/^ALL ABOARD$/ { - if (! header) { - print "]" - } - header++ - aboard = 1 - next -} - -/^END OF THE LINE$/ { - aboard = 0 - next -} - -aboard { - gsub(/[[:space:]]/, "", $0) - buf = buf proc(toupper($0)) -} - -! aboard { - printbuf() - if (header) { - gsub(/[-+<>.,\[\]]/, "", $0) - } - print - buf = "" -} - -END { - if (DERAIL_ERR) { - print DERAIL_ERR - exit 9 - } - printbuf() - printf "\n" -} - - -function derail(err) -{ - print "TRAIN DERAILED at input line", FNR - DERAIL_ERR = err - exit -} -function printbuf(newline) -{ - for (ss = 1; ss <= length(buf); ss += width) { - printf "%s\n", substr(buf, ss, width) - } -} +TRAINFUCK=trainfuck.awk -function proc(t) -{ - if (! match(t, /CHUGGA|CHUG|CHOO|CLICK|CLICKETY|CLACK|TICKETSPLEASE|YOURTICKETPLEASE|$/)) { - derail("WTF") - } - pre = substr(t, 1, RSTART - 1) - tok = substr(t, RSTART, RLENGTH) - pst = substr(t, RSTART + RLENGTH) - if (tok == "CHUGGA") { # needs to be first - tok = "-" - return (pre tok proc(pst)) - } - if (tok == "CHUG") { - tok = "+" - return (pre tok proc(pst)) - } - if (tok == "CHOO") { - if (substr(pst, 1, 4) == "CHOO") { - tok = "<" - sub(/CHOO/, "", pst) - } else { - tok = ">" - } - return (pre tok proc(pst)) - } - if (tok == "CLICK" || tok == "CLICKETY") { - tok = "." - return (pre tok proc(pst)) - } - if (tok == "CLACK") { - tok = "," - return (pre tok proc(pst)) - } - if (tok == "TICKETSPLEASE") { - tok = "[" - return (pre tok proc(pst)) - } - if (tok == "YOURTICKETPLEASE") { - tok = "]" - return (pre tok proc(pst)) - } -} +gawk -v EXE_NAME="$(basename $0)" -f "$TRAINFUCK" -- "$@" -- cgit 1.4.1-21-gabe81