From Esolang
Jump to navigation Jump to search

This is a very simple language I (Daniel Cristofani) designed accidentally. It consists only of regex substitutions with loops; it's meant for banging text files into a different shape, but is incidentally Turing-complete because Markov algorithms translate to it easily.

At the start of an egaharjb program, a file is read into egaharjb's buffer from standard input. The program manipulates the text in this buffer, and at the end the transformed text is sent to standard output.

An egaharjb program consists of statements, loops, and whitespace, A statement consists of a pattern string followed by a replacement string, both delimited by double quotes, and has the effect of replacing the first instance of the pattern in the buffer with the replacement. (Egaharjb transpiles to Perl and thus borrows Perl's regex syntax and its set of associated bells and whistles.) A loop, delimited by curly brackets, acts as a do-while (at least one pattern match was found during the last iteration); these are nestable. Statements and loops are otherwise performed sequentially.


Compute bracket depth of brainfuck program (in unary):

{"[^][]+" ""}
{"]\[" ""}
{"\[(I*)]" "I$1"}
"(I*)" "$1\n"

Transpile egaharjb to Perl:

"" "\#!/usr/local/bin/perl\n\$b=join(\"\",<STDIN>);\n\"a\"a\"a\""
    "\"a\"a\"a\"[ \t\n]+" "\"a\"a\"a\""
    "\"a\"a\"a\"\{" "for(\$f[++\$l]=1;\$f[\$l];\$f[\$l-1]||=\$f[\$l])\{\n\$f[\$l]=0;\n\"a\"a\"a\""
    "\"a\"a\"a\"\}" "\}\n\$l--;\n\"a\"a\"a\""
    "\"a\"a\"a\"\"(([^\"\\]|\\.|\\\n)*)\"[ \t\n]*\"(([^\"\\]|\\.|\\\n)*)\"" "if(\$b=~s\"$1\"$3\")\{\$f[\$l]=1;\}\n\"a\"a\"a\""
"\"a\"a\"a\"(.+)" "ERROR: Unexpected input: $1\n\n"
"\"a\"a\"a\"" "print \$b;\n"

History: I've occasionally found myself iterating regex find-and-replaces by hand. On 2020-04-14 I thought "this has to be a Linux utility", which may still be correct for all I know, but I didn't find it, so I made this. I didn't want to take a good name that someone else might want, so I used's password generator tool and picked "eGAHArjB" from a list of five because it was pronounceable. This name should be treated as case-insensitive, and the file extension could be .egah I suppose.

Here's the Perl version of that transpiler:

if($b=~s"\"a\"a\"a\"[ \t\n]+"\"a\"a\"a\""){$f[$l]=1;}
if($b=~s"\"a\"a\"a\"\"(([^\"\\]|\\.|\\\n)*)\"[ \t\n]*\"(([^\"\\]|\\.|\\\n)*)\""if(\$b=~s\"$1\"$3\")\{\$f[\$l]=1;\}\n\"a\"a\"a\""){$f[$l]=1;}
if($b=~s"\"a\"a\"a\"(.+)"ERROR: Unexpected input: $1\n\n"){$f[$l]=1;}
if($b=~s"\"a\"a\"a\""print \$b;\n"){$f[$l]=1;}
print $b;