Class RegExpTree
- java.lang.Object
-
- com.google.javascript.jscomp.regex.RegExpTree
-
- Direct Known Subclasses:
RegExpTree.Alternation
,RegExpTree.CapturingGroup
,RegExpTree.Concatenation
,RegExpTree.LookaheadAssertion
,RegExpTree.LookbehindAssertion
,RegExpTree.NamedCaptureGroup
,RegExpTree.RegExpTreeAtom
,RegExpTree.Repetition
public abstract class RegExpTree extends java.lang.Object
An AST for JavaScript regular expressions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RegExpTree.Alternation
Represents the possibilities ["foo", "bar" ] for a RegExp /foo|bar/static class
RegExpTree.Anchor
Represents an anchor, namely ^ or $.static class
RegExpTree.BackReference
Represents a reference to a previous group such as \1 or \2static class
RegExpTree.CapturingGroup
Represents a capturing group such as (asdf)static class
RegExpTree.Charset
Represents a set of possible characters structured as [a-zA-Z] or [^a-zA-Z]static class
RegExpTree.Concatenation
Represents a series of nodes chained one after another such as (?:...)[a-z]*(...)static class
RegExpTree.Empty
Represents an empty portion of a RegExp such as the middle of "||"static class
RegExpTree.LookaheadAssertion
Represents a lookahead assertion such as (?=...) or (?!...)static class
RegExpTree.LookbehindAssertion
Represents a lookbehind assertion such as(?<=...)
or(?<!...)
static class
RegExpTree.NamedBackReference
Represents a reference to a previous named groupstatic class
RegExpTree.NamedCaptureGroup
Represents a named capture groupstatic class
RegExpTree.RegExpTreeAtom
Represents a node that never has children such as an anchor or charset.static class
RegExpTree.Repetition
Represents a repeating item such as ...+, ...*, or ...{0,1}static class
RegExpTree.Text
Represents a run of non-special characters such as "foobar"static class
RegExpTree.UnicodePropertyEscape
Represents a Unicode Property Escape such as in /\p{Script=Greek}/ustatic class
RegExpTree.WordBoundary
Represents \b or \B
-
Constructor Summary
Constructors Constructor Description RegExpTree()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
appendDebugInfo(java.lang.StringBuilder sb)
protected abstract void
appendSourceCode(java.lang.StringBuilder sb)
Appends this regular expression source to the given buffer.abstract java.util.List<? extends RegExpTree>
children()
The children of this node.abstract boolean
containsAnchor()
True if the regular expression contains an anchor :^
or$
.abstract boolean
equals(java.lang.Object o)
boolean
hasCapturingGroup()
True if the regular expression contains capturing groups.abstract int
hashCode()
abstract boolean
isCaseSensitive()
True if the presence or absence of an"i"
flag would change the meaning of this regular expression.static boolean
matchesWholeInput(RegExpTree t, java.lang.String flags)
True if, but not necessarily always when the, given regular expression must match the whole input or none of it.abstract int
numCapturingGroups()
The number of capturing groups.static RegExpTree
parseRegExp(java.lang.String pattern, java.lang.String flags)
Parses a regular expression to an AST.abstract RegExpTree
simplify(java.lang.String flags)
Returns a simpler regular expression that is semantically the same assuming the given flags.java.lang.String
toString()
-
-
-
Method Detail
-
simplify
public abstract RegExpTree simplify(java.lang.String flags)
Returns a simpler regular expression that is semantically the same assuming the given flags.- Parameters:
flags
- Regular expression flags, e.g."igm"
.
-
isCaseSensitive
public abstract boolean isCaseSensitive()
True if the presence or absence of an"i"
flag would change the meaning of this regular expression.
-
containsAnchor
public abstract boolean containsAnchor()
True if the regular expression contains an anchor :^
or$
.
-
hasCapturingGroup
public final boolean hasCapturingGroup()
True if the regular expression contains capturing groups.
-
numCapturingGroups
public abstract int numCapturingGroups()
The number of capturing groups.
-
children
public abstract java.util.List<? extends RegExpTree> children()
The children of this node.
-
appendSourceCode
protected abstract void appendSourceCode(java.lang.StringBuilder sb)
Appends this regular expression source to the given buffer.
-
appendDebugInfo
protected abstract void appendDebugInfo(java.lang.StringBuilder sb)
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public abstract boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public abstract int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
parseRegExp
public static RegExpTree parseRegExp(java.lang.String pattern, java.lang.String flags)
Parses a regular expression to an AST.- Parameters:
pattern
- Thefoo
From/foo/i
.flags
- Thei
From/foo/i
.
-
matchesWholeInput
public static boolean matchesWholeInput(RegExpTree t, java.lang.String flags)
True if, but not necessarily always when the, given regular expression must match the whole input or none of it.
-
-