I was looking through different regular expression engines. One of them is TRegex which is one of implemented Truffle languages, which offers linear time matching. I m not very familiar with GraalVM and Truffle and not planning to use GraalVM, so I m kind of confused. My question is, can I use an existing Truffle language implementation inside existing Java application without having to change the environment or using GraalVM (I suppose running it as that language's interpreter)?
In particular, can I use TRegex just as a regular expression library (in place of java.util.regex), e.g. by adding it as mvn dependency? Or does it run on GraalVM only?
The doc above has link to RegexLanguage class which shows sample usage, but it seems that this code has to be run within Truffle framework, perhaps while implementing another Truffle language, so it is not clear if there is a way to use it standalone. If it is possible, are there any examples available? Would performance be adequate in this case?
To answer your first question: While yes, you can run Truffle languages without the Graal compiler, performance is going to be abysmal, as Truffle heavily relies on dedicated optimizations provided by Graal.
Consequently, you can also run TRegex as a regular Java library without Graal, but performance is probably going to be worse than java.util.Regex if you do that.
If there is any demand for it, I can put together a drop-in replacement for java.util.regex containing TRegex as a standalone maven library, but to really get any benefit out of it, I'd highly recommend using it in conjunction with Graal.