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 --- examples/helloworld.trainfuck | 31 ++++--------------------------- trainfuck | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/examples/helloworld.trainfuck b/examples/helloworld.trainfuck index da6baf8..1f68f11 100644 --- a/examples/helloworld.trainfuck +++ b/examples/helloworld.trainfuck @@ -1,16 +1,16 @@ TRAINFUCK BABEEE CHOO CHOO MUTHERFUCKER -This example adapted from https://enclick wikipediaclick org/wiki/Brainfuck +This example adapted from https://en.wikipedia.org/wiki/Brainfuck This program prints "Hello World!" and a newline to the screen, its -length is 106 active command charactersclick [It is not the shortestclick ] +length is 106 active command characters. The program doesn't start until we have ALL ABOARD on a line by itself, so -we've got one better than an initial comment loopclick +we've got one better than an initial comment loop. This file was handwritten, but soon(TM) we'll have a fucktrain command, -that'll translate to trainfuck from brainfuckclick +that'll translate to trainfuck from brainfuck. ALL ABOARD chug chug chug chug chug chug chug chug @@ -149,27 +149,4 @@ END OF THE LINE ALL ABOARD choo chug chug click -END OF THE LINE - And finally a newline from Cell #6. - Of course, non-commented it's like this: -ALL ABOARD -tickets please chugga your ticket please choo choo -tickets please chugga your ticket please choo choo -tickets please chugga your ticket please choo choo -tickets please chugga your ticket please choo choo -tickets please chugga your ticket please choo choo -tickets please chugga your ticket please choo choo -END OF THE LINE -(first, you gotta zero out those cells) -ALL ABOARD -chug chug chug chug chug chug chug chug tickets please choo chug chug chug chug tickets please choo chug chug choo chug chug chug choo chug chug chug choo chug choo choo -choo choo -choo choo -choo choo -chugga your ticket please choo chug choo chug choo chugga choo -choo chug tickets please choo choo your ticket please choo choo chugga your ticket please choo -choo clickety choo chugga chugga chugga clickety chug chug chug chug chug chug chug clickety clickety chug chug chug clickety choo -choo clickety choo choo -chugga clickety choo choo clickety chug chug chug clickety chugga chugga chugga chugga chugga chugga clickety chugga chugga chugga chugga chugga chugga chugga chugga clickety choo -choo chug clickety choo chug chug clickety END OF THE LINE 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