esolang

Gecko

One global string, and every statement is a regex that rewrites it.

Silver, 2019 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: hello universe

The idea

Silver made Gecko in 2019 to make programming in regexes as pleasant as it could reasonably be. There is one value, a string. A statement finds a regex in it and puts a substitution in its place, with \1 for the first group. Around that come three statements that take other statements as arguments, and blocks that have names and can call themselves. The specification shows it is Turing complete with a brainfuck interpreter written in Gecko.

The machine

StatementDoes
"re" -> "text"Replace the first match of the regex with the text
-> "text"Set the whole string
.On the left .*, on the right \0, the whole match
\0 to \9, \@A group of the match; a line of input
if "re" T FRun T if the regex matches, F if not
while "re" TRun T as long as the regex matches
map "re" T "text"Run T on each group, then substitute
{ ... }, name: { ... }A block of statements; a block with a name

A map is the only place a statement works on something other than the global string. The specification does not say how a program prints. In this implementation the string starts empty and is printed once the program ends.

Example

The block example.

The block example. Each call wraps the whole string twice, first in b and then in c.

Expected: cbcbabcbc

A map runs . -> "[\0]" on each group before the substitution swaps them. In this implementation the string comes from input.

Expected: [world][hello]

Unary addition with a while. The plus moves left one 1 at a time until no 1 is in front of it.

Expected: 11111

Patterns it teaches

Further

String-rewriting paradigm

Write your own in Run Convert a program from Gecko

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: gecko.

Command line

shib run gecko -e '-> "aaxbb"
while "a.*b"
  "a(.*)b" -> "\1"'
shib manual gecko

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/gecko.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org