about summary refs log tree commit diff stats
path: root/trainfuck
diff options
context:
space:
mode:
authorCase Duckworth2022-06-28 20:46:15 -0500
committerCase Duckworth2022-06-28 20:46:15 -0500
commitec7af295fece72c1baa03e273792fb7dad419241 (patch)
treeaa37d448cddab8237c2781502fef6a302e00a652 /trainfuck
parentCorrect readme (diff)
downloadtrainfuck-ec7af295fece72c1baa03e273792fb7dad419241.tar.gz
trainfuck-ec7af295fece72c1baa03e273792fb7dad419241.zip
Recognize bf comments
Diffstat (limited to 'trainfuck')
-rwxr-xr-xtrainfuck33
1 files changed, 31 insertions, 2 deletions
diff --git a/trainfuck b/trainfuck index 6715987..602fc92 100755 --- a/trainfuck +++ b/trainfuck
@@ -3,8 +3,11 @@
3# Author: Case Duckworth <acdw@acdw.net> 3# Author: Case Duckworth <acdw@acdw.net>
4# License: WTFPL 4# License: WTFPL
5# Version: #9 5# Version: #9
6# 6
7### Commentary:
8
7# LANGUAGE 9# LANGUAGE
10
8# trainfuck is not case-sensitive 11# trainfuck is not case-sensitive
9# -- except for ALL ABOARD and END OF THE LINE 12# -- except for ALL ABOARD and END OF THE LINE
10# ignore everything before ALL ABOARD 13# ignore everything before ALL ABOARD
@@ -21,11 +24,19 @@
21# ] your ticket please 24# ] your ticket please
22# syntax does NOT WRAP across line breaks 25# syntax does NOT WRAP across line breaks
23# anything else is an error and DERAILS the train 26# anything else is an error and DERAILS the train
27
28### Code:
24BEGIN { 29BEGIN {
25 aboard = 0 30 aboard = 0
31 width = 30
32 print "["
26} 33}
27 34
28/^ALL ABOARD$/ { 35/^ALL ABOARD$/ {
36 if (! header) {
37 print "]"
38 }
39 header++
29 aboard = 1 40 aboard = 1
30 next 41 next
31} 42}
@@ -37,7 +48,16 @@ BEGIN {
37 48
38aboard { 49aboard {
39 gsub(/[[:space:]]/, "", $0) 50 gsub(/[[:space:]]/, "", $0)
40 print proc(toupper($0)) 51 buf = buf proc(toupper($0))
52}
53
54! aboard {
55 printbuf()
56 if (header) {
57 gsub(/[-+<>.,\[\]]/, "", $0)
58 }
59 print
60 buf = ""
41} 61}
42 62
43END { 63END {
@@ -45,6 +65,8 @@ END {
45 print DERAIL_ERR 65 print DERAIL_ERR
46 exit 9 66 exit 9
47 } 67 }
68 printbuf()
69 printf "\n"
48} 70}
49 71
50 72
@@ -55,6 +77,13 @@ function derail(err)
55 exit 77 exit
56} 78}
57 79
80function printbuf(newline)
81{
82 for (ss = 1; ss <= length(buf); ss += width) {
83 printf "%s\n", substr(buf, ss, width)
84 }
85}
86
58function proc(t) 87function proc(t)
59{ 88{
60 if (! match(t, /CHUGGA|CHUG|CHOO|CLICK|CLICKETY|CLACK|TICKETSPLEASE|YOURTICKETPLEASE|$/)) { 89 if (! match(t, /CHUGGA|CHUG|CHOO|CLICK|CLICKETY|CLACK|TICKETSPLEASE|YOURTICKETPLEASE|$/)) {