Egaharjb
Find and replace with regexes, in loops that run until nothing matches.
Daniel Cristofani, 2020 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Daniel Cristofani made Egaharjb in April 2020 for banging text files into a different shape, after doing the same regex find and replace by hand again and again. He took the name from five random passwords, because eGAHArjB was the one he could pronounce.
Read the story
A program reads its whole input into a buffer, changes it with substitutions and prints what is left. It translates to Perl and borrows Perl's regexes. The specification says it is Turing complete by accident, because Markov algorithms translate into it easily.
The machine
| Form | Does |
|---|---|
"pattern" "replacement" | Replace the first match in the buffer |
{ ... } | Run the inside again while it matched anything in its last pass |
Space, tab and line feed separate statements, and loops nest. The pattern is a Perl regex and the replacement a Perl string, so $1 puts back the first group and \n is a line feed. This implementation runs them on JavaScript's regex engine, read the way Perl reads them. Perl variables inside the strings, case escapes such as \U and POSIX classes such as [:alpha:] are left out.
Example
A loop that swaps ba until there is none left sorts the letters.
A loop that swaps ba until there is none left sorts the letters.
The bracket depth program measures how deep the loops of a brainfuck program go. It throws away everything but brackets, joins loops that stand side by side by deleting ][, then turns the innermost [] into I again and again.
The other program translates Egaharjb into Perl. It puts a marker at the front, then a loop moves the marker through the program and writes one line of Perl for each statement and bracket it passes. Given its own text it writes the Perl version the specification prints, line for line. It gets one statement.
Patterns it teaches
- String rewriting: the whole program is replacements on one text.
- Turing completeness: reached by accident, through Markov algorithms.
Further
See also
String-rewriting paradigm
Write your own in Run Convert a program from Egaharjb
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: egaharjb.
Command line
shib run egaharjb -e '{"[^][]+" ""}
{"]\[" ""}
{"\[(I*)]" "I$1"}
"(I*)" "$1\n"' --input '++[>++[>+<-]<-]>>.'shib manual egaharjbSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/egaharjb.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org