m-ender / retina

A regex-based programming language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add branches

m-ender opened this issue · comments

Sometimes you want to apply different transformations to the input. Some sort of branch for that could be useful. There could be several types of branches:

  • Use the first branch which modifies the string, ignore all the others.
  • Attach an additional regex to each branch, and use the first one where that additional regex matches. (Although this could potentially be done with the above solution by using this additional regex as a lookaround in the regex you have anyway.)
  • Apply all the branches and join the results together somehow. The joining together could be done with a normal substitution string where $n refers to the result of the n'th branch.

Retina 1.0 will have a compound conditional stage that takes a regex parameter. By default, the child stage will only be executed if the regex matches. By adding the ^ ("reverse") option, the child stage will only be executed if the regex doesn't match. The stage can also be executed based on a coin toss by giving it the random option (currently &, subject to change) instead of a regex.

It's also possible to a form of if/else by giving a regex parameter to a group stage.