public final class PythonRegexParser extends Object implements RegexValidator, RegexParser
The implementation strives to be as close as possible to the behavior of the regex parser that ships with Python 3.7, down to the wording of the error messages.
| Modifier and Type | Field and Description |
|---|---|
static String |
WORD_BOUNDARY |
static Pattern |
WORD_CHARS_PATTERN |
static String |
WORD_NON_BOUNDARY |
| Modifier and Type | Method and Description |
|---|---|
static RegexParser |
createParser(RegexLanguage language,
RegexSource source,
CompilationBuffer compilationBuffer,
PythonREMode mode) |
static RegexValidator |
createValidator(RegexSource source,
PythonREMode mode) |
AbstractRegexObject |
getFlags()
Returns a
TruffleObject representing the compilation flags which were set for the
regular expression. |
AbstractRegexObject |
getNamedCaptureGroups()
Returns a map from the names of capture groups to their indices.
|
static int |
lookupCharacterByName(String characterName) |
RegexAST |
parse()
Runs the parser and produces an AST.
|
void |
validate()
Checks the regular expression for syntax errors without building an AST.
|
public static final Pattern WORD_CHARS_PATTERN
public static final String WORD_BOUNDARY
public static final String WORD_NON_BOUNDARY
public static RegexValidator createValidator(RegexSource source, PythonREMode mode) throws RegexSyntaxException
RegexSyntaxExceptionpublic static RegexParser createParser(RegexLanguage language, RegexSource source, CompilationBuffer compilationBuffer, PythonREMode mode) throws RegexSyntaxException
RegexSyntaxExceptionpublic AbstractRegexObject getNamedCaptureGroups()
RegexParserRegexParser.parse().getNamedCaptureGroups in interface RegexParserpublic AbstractRegexObject getFlags()
RegexParserTruffleObject representing the compilation flags which were set for the
regular expression. The returned object responds to 'READ' messages on names which correspond
to the names of the flags as used in the language from which the flavor originates. This
method has to be called after calling RegexParser.parse().getFlags in interface RegexParserpublic void validate()
throws RegexSyntaxException
RegexValidatorvalidate in interface RegexValidatorRegexSyntaxException - when the pattern or the flags are not well-formedpublic RegexAST parse() throws RegexSyntaxException, UnsupportedRegexException
RegexParserparse in interface RegexParserRegexSyntaxException - when the pattern or the flags are not well-formedUnsupportedRegexException - when the pattern cannot be translated to an equivalent
ECMAScript patternpublic static int lookupCharacterByName(String characterName)