Tetanus
Paradigm(s) | String-rewriting |
---|---|
Designed by | User:Poolala |
Appeared in | 2022 |
Computational class | Turing complete |
Reference implementation | tetanus.py |
File extension(s) | .tet |
Tetanus is a language of regular expressions and suffering. Its name was inspired by its agonizing design and difficulty of use, similar to doing surgery with a rusty hacksaw.
Language overview
A program in Tetanus consists of a regular expression on the first line, a replacement string on the second, and a data string consisting of all the lines afterwards. If there are no lines after the second, the data string is initially blank.
Before execution, the replacement string is checked for ~
or `
characters after group references. They are recorded, then all of them are removed from the replacement string.
If the regular expression matches the data string, all matches are replaced with the replacement string. For each marked group, if the group referred to is not null, something is done: for ~
, the text captured by the group is outputted with no newline afterwards, and then for `
, a line of input is appended to the end of the data string. This is repeated until the regular expression fails to match.
Implementation notes
Python escape sequences in the replacement string are supported. The regex
Python package is used for parsing regular expressions, therefore Tetanus uses its regex flavor.
Programs
Hello, world!
^(H.+) !\1~ Hello, world!
Cat program
(Note the blank lines at the end)
^(\n)$|(\n)(.+)$ !\1`\3~`\2~
Truth-machine
^(!)$|^(!!)(0)$|^(!!)(1)$ \1\1`\2\2\3~\4\5~ !
Quine
(Note the blank line at the end)
(?s)^(?!!!)(!*)(.+) !\1\2~ (?s)^(?!!!)(!*)(.+) !\1\2~
Palindromic quine
(?s)^(?!!!)(!*)(.+?\n)(@)|^(?!!!!)(!*).+?\n(@.+) !\1\2~\3\4\5~ (?s)^(?!!!)(!*)(.+?\n)(@)|^(?!!!!)(!*).+?\n(@.+) !\1\2~\3\4\5~ @ SUP YA GOOFS SFOOG AY PUS @ ~5\4\3\~2\1\! )+.@(n\?+.)*!()!!!!?(^|)@()n\?+.()*!()!!!?(^)s?( ~5\4\3\~2\1\! )+.@(n\?+.)*!()!!!!?(^|)@()n\?+.()*!()!!!?(^)s?(
Computational class
Tetanus is Turing-complete, since it can simulate Bitwise Cyclic Tag with this program:
^([^>]+?)(\n)(.+)$|>(0)([01]*)(\n)[01]([01]*)\n*$|>(1)([01])([01]*)(\n)(1[01]*)\n*$|>(1[01])([01]*)(\n)(0[01]*)\n*$|^([01])([01]*)>(1)(\n)(1[01]*)\n*$|^([01])([01]*)>(1)(\n)(0[01]*)\n*$|([01]+)>(\n) \4\8\9\13\17\22>\1\2\3~\2~\5\6\7~\6~\10\11\12~\9~\11~\14\15\16~\15~\18\19\20\21~\17~\20~\23\24\25\26~\25~\27\28 insert BCT program here insert BCT data string here