public final class RegexLanguage extends com.oracle.truffle.api.TruffleLanguage<RegexLanguage.RegexContext>
This language represents classic regular expressions. By evaluating any source, you get access to
the RegexEngineBuilder. By calling this builder, you can build your custom
RegexEngine which implements your flavor of regular expressions and uses your fallback
compiler for expressions not covered. The RegexEngine accepts regular expression patterns
and flags and compiles them to RegexObjects, which you can use to match the regular
expressions against strings.
Usage example in pseudocode:
engineBuilder = <eval any source in the "regex" language>
engine = engineBuilder("Flavor=ECMAScript", optionalFallbackCompiler)
regex = engine("(a|(b))c", "i")
assert(regex.pattern == "(a|(b))c")
assert(regex.flags.ignoreCase == true)
assert(regex.groupCount == 3)
result = regex.exec("xacy", 0)
assert(result.isMatch == true)
assertEquals([result.getStart(0), result.getEnd(0)], [ 1, 3])
assertEquals([result.getStart(1), result.getEnd(1)], [ 1, 2])
assertEquals([result.getStart(2), result.getEnd(2)], [-1, -1])
result2 = regex.exec("xxx", 0)
assert(result2.isMatch == false)
// result2.getStart(...) and result2.getEnd(...) are undefined
| Modifier and Type | Class and Description |
|---|---|
static class |
RegexLanguage.RegexContext |
com.oracle.truffle.api.TruffleLanguage.ContextPolicy, com.oracle.truffle.api.TruffleLanguage.ContextReference<C>, com.oracle.truffle.api.TruffleLanguage.Env, com.oracle.truffle.api.TruffleLanguage.InlineParsingRequest, com.oracle.truffle.api.TruffleLanguage.LanguageReference<L extends com.oracle.truffle.api.TruffleLanguage>, com.oracle.truffle.api.TruffleLanguage.ParsingRequest, com.oracle.truffle.api.TruffleLanguage.Provider, com.oracle.truffle.api.TruffleLanguage.Registration| Modifier and Type | Field and Description |
|---|---|
RegexEngineBuilder |
engineBuilder |
static String |
ID |
static String |
MIME_TYPE |
static String |
NAME |
| Constructor and Description |
|---|
RegexLanguage() |
| Modifier and Type | Method and Description |
|---|---|
protected RegexLanguage.RegexContext |
createContext(com.oracle.truffle.api.TruffleLanguage.Env env) |
protected Iterable<com.oracle.truffle.api.Scope> |
findTopScopes(RegexLanguage.RegexContext context) |
static RegexLanguage.RegexContext |
getCurrentContext() |
protected boolean |
isObjectOfLanguage(Object object) |
protected boolean |
isThreadAccessAllowed(Thread thread,
boolean singleThreaded)
RegexLanguage is thread-safe - it supports parallel parsing requests as well as
parallel access to all RegexLanguageObjects. |
protected com.oracle.truffle.api.CallTarget |
parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest parsingRequest) |
protected boolean |
patchContext(RegexLanguage.RegexContext context,
com.oracle.truffle.api.TruffleLanguage.Env newEnv) |
static void |
validateRegex(RegexSource source) |
static void |
validateRegex(String pattern,
String flags) |
areOptionsCompatible, disposeContext, disposeThread, finalizeContext, findLocalScopes, findMetaObject, findSourceLocation, getCurrentContext, getCurrentLanguage, getLanguageHome, getOptionDescriptors, initializeContext, initializeMultipleContexts, initializeMultiThreading, initializeThread, isVisible, parse, toStringpublic static final String NAME
public static final String ID
public static final String MIME_TYPE
public final RegexEngineBuilder engineBuilder
public static void validateRegex(String pattern, String flags) throws RegexSyntaxException
RegexSyntaxExceptionpublic static void validateRegex(RegexSource source) throws RegexSyntaxException
RegexSyntaxExceptionprotected com.oracle.truffle.api.CallTarget parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest parsingRequest)
parse in class com.oracle.truffle.api.TruffleLanguage<RegexLanguage.RegexContext>protected RegexLanguage.RegexContext createContext(com.oracle.truffle.api.TruffleLanguage.Env env)
createContext in class com.oracle.truffle.api.TruffleLanguage<RegexLanguage.RegexContext>protected boolean patchContext(RegexLanguage.RegexContext context, com.oracle.truffle.api.TruffleLanguage.Env newEnv)
patchContext in class com.oracle.truffle.api.TruffleLanguage<RegexLanguage.RegexContext>protected Iterable<com.oracle.truffle.api.Scope> findTopScopes(RegexLanguage.RegexContext context)
findTopScopes in class com.oracle.truffle.api.TruffleLanguage<RegexLanguage.RegexContext>protected boolean isObjectOfLanguage(Object object)
isObjectOfLanguage in class com.oracle.truffle.api.TruffleLanguage<RegexLanguage.RegexContext>protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded)
RegexLanguage is thread-safe - it supports parallel parsing requests as well as
parallel access to all RegexLanguageObjects. Parallel access to
LazyCaptureGroupsResult objects may lead to duplicate
execution of code, but no wrong results.isThreadAccessAllowed in class com.oracle.truffle.api.TruffleLanguage<RegexLanguage.RegexContext>thread - the thread that accesses the context for the first time.singleThreaded - true if the access is considered single-threaded, false
if more than one thread is active at the same time.truepublic static RegexLanguage.RegexContext getCurrentContext()