MCPcopy Create free account
hub / github.com/google/re2j / Regexp

Class Regexp

java/com/google/re2j/Regexp.java:21–379  ·  view source on GitHub ↗

Regular expression abstract syntax tree. Produced by parser, used by compiler. NB, this corresponds to syntax.regexp in the Go implementation; Go's regexp is called RE2 in Java.

Source from the content-addressed store, hash-verified

19 * {@code RE2} in Java.
20 */
21class Regexp {
22
23 enum Op {
24 NO_MATCH, // Matches no strings.
25 EMPTY_MATCH, // Matches empty string.
26 LITERAL, // Matches runes[] sequence
27 CHAR_CLASS, // Matches Runes interpreted as range pair list
28 ANY_CHAR_NOT_NL, // Matches any character except '\n'
29 ANY_CHAR, // Matches any character
30 BEGIN_LINE, // Matches empty string at end of line
31 END_LINE, // Matches empty string at end of line
32 BEGIN_TEXT, // Matches empty string at beginning of text
33 END_TEXT, // Matches empty string at end of text
34 WORD_BOUNDARY, // Matches word boundary `\b`
35 NO_WORD_BOUNDARY, // Matches word non-boundary `\B`
36 CAPTURE, // Capturing subexpr with index cap, optional name name
37 STAR, // Matches subs[0] zero or more times.
38 PLUS, // Matches subs[0] one or more times.
39 QUEST, // Matches subs[0] zero or one times.
40 REPEAT, // Matches subs[0] [min, max] times; max=-1 => no limit.
41 CONCAT, // Matches concatenation of subs[]
42 ALTERNATE, // Matches union of subs[]
43
44 // Pseudo ops, used internally by Parser for parsing stack:
45 LEFT_PAREN,
46 VERTICAL_BAR;
47
48 boolean isPseudo() {
49 return ordinal() >= LEFT_PAREN.ordinal();
50 }
51 }
52
53 static final Regexp[] EMPTY_SUBS = {};
54
55 Op op; // operator
56 int flags; // bitmap of parse flags
57 Regexp[] subs; // subexpressions, if any. Never null.
58 // subs[0] is used as the freelist.
59 int[] runes; // matched runes, for LITERAL, CHAR_CLASS
60 int min, max; // min, max for REPEAT
61 int cap; // capturing index, for CAPTURE
62 String name; // capturing name, for CAPTURE
63 Map<String, Integer> namedGroups = Collections.emptyMap(); // map of group name -> capturing index
64 // Do update copy ctor when adding new fields!
65
66 Regexp(Op op) {
67 this.op = op;
68 }
69
70 // Shallow copy constructor.
71 Regexp(Regexp that) {
72 this.op = that.op;
73 this.flags = that.flags;
74 this.subs = that.subs;
75 this.runes = that.runes;
76 this.min = that.min;
77 this.max = that.max;
78 this.cap = that.cap;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…