diff options
author | Case Duckworth | 2022-06-29 00:59:59 -0500 |
---|---|---|
committer | Case Duckworth | 2022-06-29 00:59:59 -0500 |
commit | 0a78720644e45bd27c4a57cbddf2d32aacb555c3 (patch) | |
tree | 29783dc9a534dbbfe172d5c84e66f5efcd9c43dc /trainfuck | |
parent | Recognize bf comments (diff) | |
download | trainfuck-0a78720644e45bd27c4a57cbddf2d32aacb555c3.tar.gz trainfuck-0a78720644e45bd27c4a57cbddf2d32aacb555c3.zip |
Probably version ... whatever the next higher one is
Diffstat (limited to 'trainfuck')
-rwxr-xr-x | trainfuck | 123 |
1 files changed, 5 insertions, 118 deletions
diff --git a/trainfuck b/trainfuck index 602fc92..22d1009 100755 --- a/trainfuck +++ b/trainfuck | |||
@@ -1,128 +1,15 @@ | |||
1 | #!/bin/awk -f | 1 | #!/bin/sh |
2 | # TRAINFUCK: CHOO CHOO MUTHAFUCKA -*- awk -*- | 2 | # TRAINFUCK: CHOO CHOO MUTHAFUCKA -*- sh -*- |
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: | 7 | ### Commentary: |
8 | 8 | ||
9 | # LANGUAGE | 9 | # shell wrapper around trainfuck.awk, which see. |
10 | |||
11 | # trainfuck is not case-sensitive | ||
12 | # -- except for ALL ABOARD and END OF THE LINE | ||
13 | # ignore everything before ALL ABOARD | ||
14 | # ignore everything after END OF THE LINE | ||
15 | # (this means you can comment between these) | ||
16 | # bf tf | ||
17 | # + chug | ||
18 | # - chugga | ||
19 | # > choo | ||
20 | # < choo choo | ||
21 | # . click OR clickety | ||
22 | # , clack | ||
23 | # [ tickets please | ||
24 | # ] your ticket please | ||
25 | # syntax does NOT WRAP across line breaks | ||
26 | # anything else is an error and DERAILS the train | ||
27 | 10 | ||
28 | ### Code: | 11 | ### Code: |
29 | BEGIN { | ||
30 | aboard = 0 | ||
31 | width = 30 | ||
32 | print "[" | ||
33 | } | ||
34 | |||
35 | /^ALL ABOARD$/ { | ||
36 | if (! header) { | ||
37 | print "]" | ||
38 | } | ||
39 | header++ | ||
40 | aboard = 1 | ||
41 | next | ||
42 | } | ||
43 | |||
44 | /^END OF THE LINE$/ { | ||
45 | aboard = 0 | ||
46 | next | ||
47 | } | ||
48 | |||
49 | aboard { | ||
50 | gsub(/[[:space:]]/, "", $0) | ||
51 | buf = buf proc(toupper($0)) | ||
52 | } | ||
53 | |||
54 | ! aboard { | ||
55 | printbuf() | ||
56 | if (header) { | ||
57 | gsub(/[-+<>.,\[\]]/, "", $0) | ||
58 | } | ||
59 | |||
60 | buf = "" | ||
61 | } | ||
62 | |||
63 | END { | ||
64 | if (DERAIL_ERR) { | ||
65 | print DERAIL_ERR | ||
66 | exit 9 | ||
67 | } | ||
68 | printbuf() | ||
69 | printf "\n" | ||
70 | } | ||
71 | |||
72 | |||
73 | function derail(err) | ||
74 | { | ||
75 | print "TRAIN DERAILED at input line", FNR | ||
76 | DERAIL_ERR = err | ||
77 | exit | ||
78 | } | ||
79 | 12 | ||
80 | function printbuf(newline) | 13 | TRAINFUCK=trainfuck.awk |
81 | { | ||
82 | for (ss = 1; ss <= length(buf); ss += width) { | ||
83 | printf "%s\n", substr(buf, ss, width) | ||
84 | } | ||
85 | } | ||
86 | 14 | ||
87 | function proc(t) | 15 | gawk -v EXE_NAME="$(basename $0)" -f "$TRAINFUCK" -- "$@" |
88 | { | ||
89 | if (! match(t, /CHUGGA|CHUG|CHOO|CLICK|CLICKETY|CLACK|TICKETSPLEASE|YOURTICKETPLEASE|$/)) { | ||
90 | derail("WTF") | ||
91 | } | ||
92 | pre = substr(t, 1, RSTART - 1) | ||
93 | tok = substr(t, RSTART, RLENGTH) | ||
94 | pst = substr(t, RSTART + RLENGTH) | ||
95 | if (tok == "CHUGGA") { # needs to be first | ||
96 | tok = "-" | ||
97 | return (pre tok proc(pst)) | ||
98 | } | ||
99 | if (tok == "CHUG") { | ||
100 | tok = "+" | ||
101 | return (pre tok proc(pst)) | ||
102 | } | ||
103 | if (tok == "CHOO") { | ||
104 | if (substr(pst, 1, 4) == "CHOO") { | ||
105 | tok = "<" | ||
106 | sub(/CHOO/, "", pst) | ||
107 | } else { | ||
108 | tok = ">" | ||
109 | } | ||
110 | return (pre tok proc(pst)) | ||
111 | } | ||
112 | if (tok == "CLICK" || tok == "CLICKETY") { | ||
113 | tok = "." | ||
114 | return (pre tok proc(pst)) | ||
115 | } | ||
116 | if (tok == "CLACK") { | ||
117 | tok = "," | ||
118 | return (pre tok proc(pst)) | ||
119 | } | ||
120 | if (tok == "TICKETSPLEASE") { | ||
121 | tok = "[" | ||
122 | return (pre tok proc(pst)) | ||
123 | } | ||
124 | if (tok == "YOURTICKETPLEASE") { | ||
125 | tok = "]" | ||
126 | return (pre tok proc(pst)) | ||
127 | } | ||
128 | } | ||