Inject

From Esolang
Jump to navigation Jump to search

Inject is an esolang by User:PythonshellDebugwindow. It is named after its first command.

Syntax

Label

A label is declared by writing a semicolon the label's name, which must be composed exclusively of letters, numbers, and/or underscores, and must be at least one character long. The first time a certain label is written, it begins a label-block; the second time, it ends a label block; any more times will result in a syntax error. For example, in the following code:

labelA;
lorem
ipsum
labelA;

the red lines are in labelA's label-block (the start and end of the block are not considered to be a part of the label-block they delimit). Labels can overlap:

labelA;
lorem
labelB;
ipsum
labelA;
dolor
labelB;

In the above code, labelA's label-block is coloured red, labelB's is blue, and lines in both their label-blocks are purple.

Note: the semicolon at the end of a label is not a part of its name.

Commands

Label arguments (represented by X and Y) do not end with semicolons.

Inject

Syntax: inject X=S/R

Replaces the label-block of the label X with R according to the regex S; S cannot contain slashes, but R can. Regexes must be able to use at least the following features:

  • Boolean "or"s (x|y)
  • Wildcards (.)
  • Grouping ((x))
  • Kleene stars (x*)
  • Kleene pluses (x+)
  • Question marks (one or none) (x?)

Implementations can optionally support more than these basic features.

Send

Syntax: send X

Writes the contents of the label-block of the label X to STDOUT.

Readto

Syntax: readto X

Reads a line from STDIN and overwrites the contents of the label-block of the label X to the input received.

Skip

Syntax: skip

If the next line is a label, and if it begins (not ends) a label-block, don't run the code in its label's label-block. Otherwise, if the instruction pointer is in at least one label-block, then go back to the beginning label of the innermost label-block. If neither of these conditions is true, then exit the program.

Skipif

Syntax: skipif X

Same as skip, but only executes if the label-block of the label X has at least one line in it.

Skipq

Syntax: skipq X Y

Same as skip, but only executes if the label-blocks of the labels X and Y are equal.

Examples

Hello, world!

send data
skip
data;
Hello, world!
data;

Truth-machine

readto data
loop;
send data
skipq data 0
loop;
skip
data;
data;
0;
0
0;

Cat program

loop;
readto data
send data
skipif data
loop;
data;
data;