DennisMitchell / jellylanguage

Jelly is a recreational programming language inspired by J.
MIT License
863 stars 45 forks source link

Syntax for regex operations #89

Open lynn opened 4 years ago

lynn commented 4 years ago

56 suggests some new atoms that perform regex operations, but perhaps it'd be better to introduce a new kind of "string start" that syntactically starts a regex, with its own set of terminators that each corresponds to a regex operation.

This would be a good use for (, which doesn't have meaning yet.

For example, #56 proposes

œF: Regex Findall: Find all instances of regex x in string y; return a list of matches

And “[a-z]”œF is 9 bytes, but something like ([a-z]Ḟ is only 7. (Here would be the regex terminator for “findall”).

Instead of “[a-z]+”UÐR, we'd write U([a-z]+Ṙ. So is a regex terminator that makes the result act as a quick.

It also makes sense to introduce all kinds of “macros” within the regex syntax. For example, could be short for [a-z], and ¹ for \1. And of course, Ɗ makes a (...) group out of the previous three regex tokens.