From ec7af295fece72c1baa03e273792fb7dad419241 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 28 Jun 2022 20:46:15 -0500 Subject: Recognize bf comments --- trainfuck | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'trainfuck') diff --git a/trainfuck b/trainfuck index 6715987..602fc92 100755 --- a/trainfuck +++ b/trainfuck @@ -3,8 +3,11 @@ # 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 @@ -21,11 +24,19 @@ # ] your ticket please # syntax does NOT WRAP across line breaks # anything else is an error and DERAILS the train + +### Code: BEGIN { aboard = 0 + width = 30 + print "[" } /^ALL ABOARD$/ { + if (! header) { + print "]" + } + header++ aboard = 1 next } @@ -37,7 +48,16 @@ BEGIN { aboard { gsub(/[[:space:]]/, "", $0) - print proc(toupper($0)) + buf = buf proc(toupper($0)) +} + +! aboard { + printbuf() + if (header) { + gsub(/[-+<>.,\[\]]/, "", $0) + } + print + buf = "" } END { @@ -45,6 +65,8 @@ END { print DERAIL_ERR exit 9 } + printbuf() + printf "\n" } @@ -55,6 +77,13 @@ function derail(err) exit } +function printbuf(newline) +{ + for (ss = 1; ss <= length(buf); ss += width) { + printf "%s\n", substr(buf, ss, width) + } +} + function proc(t) { if (! match(t, /CHUGGA|CHUG|CHOO|CLICK|CLICKETY|CLACK|TICKETSPLEASE|YOURTICKETPLEASE|$/)) { -- cgit 1.4.1-21-gabe81