4 types derived from RegexQuery
Microsoft.CodeAnalysis.Workspaces (4)
PatternMatching\RegexQuery.cs (4)
41
public sealed class All(ImmutableArray<RegexQuery> children) :
RegexQuery
51
public sealed class Any(ImmutableArray<RegexQuery> children) :
RegexQuery
64
public sealed class Literal :
RegexQuery
82
public sealed class None :
RegexQuery
208 references to RegexQuery
IdeCoreBenchmarks (4)
NavigateToRegexPreFilterBenchmarks.cs (4)
24
private
RegexQuery
_simpleQuery = null!;
25
private
RegexQuery
_alternationQuery = null!;
26
private
RegexQuery
_complexQuery = null!;
27
private
RegexQuery
_noMatchQuery = null!;
Microsoft.CodeAnalysis.Features (37)
NavigateTo\AbstractNavigateToSearchService.InProcess.cs (2)
50
/// the pattern contains regex metacharacters. Also compiles a <see cref="
RegexQuery
"/> for
68
var
regexQuery = container is null
NavigateTo\RegexQueryCompiler.cs (34)
15
/// Compiles a regex pattern string into a <see cref="
RegexQuery
"/> tree that can be evaluated
24
/// quantifiers) produce <see cref="
RegexQuery
.None"/>, which means "I can't tell — don't reject
25
/// on my account." If the entire compiled tree is <see cref="
RegexQuery
.None"/> (e.g. for <c>.*</c>),
26
/// <see cref="
RegexQuery
.HasLiterals"/> is <see langword="false"/> and the caller skips pre-filtering
33
/// <see cref="
RegexQuery
"/> tree. Returns <see langword="null"/> if the pattern is not
36
public static
RegexQuery
? Compile(string pattern)
47
/// Compiles an already-parsed regex AST into an optimized <see cref="
RegexQuery
"/> tree.
53
/// When non-null, the returned tree is guaranteed to contain only <see cref="
RegexQuery
.All"/>,
54
/// <see cref="
RegexQuery
.Any"/>, and <see cref="
RegexQuery
.Literal"/> nodes — no
55
/// <see cref="
RegexQuery
.None"/> nodes survive optimization (see
56
/// <see cref="
RegexQuery
.Optimize"/>). Callers can rely on this when traversing the tree.
58
public static
RegexQuery
? Compile(RegexTree tree)
60
var
raw = CompileNode(tree.Root.Expression);
61
var
optimized =
RegexQuery
.Optimize(raw);
65
private static
RegexQuery
CompileNode(RegexNode node)
74
RegexWildcardNode =>
RegexQuery
.None.Instance,
87
RegexZeroOrMoreQuantifierNode =>
RegexQuery
.None.Instance,
88
RegexZeroOrOneQuantifierNode =>
RegexQuery
.None.Instance,
106
_ =>
RegexQuery
.None.Instance,
110
private static
RegexQuery
CompileAlternation(RegexAlternationNode alternation)
115
var children = new FixedSizeArrayBuilder<
RegexQuery
>(alternation.SequenceList.Length);
119
return new
RegexQuery
.Any(children.MoveToImmutable());
122
private static
RegexQuery
CompileSequence(RegexSequenceNode sequence)
127
var children = new FixedSizeArrayBuilder<
RegexQuery
>(sequence.Children.Length);
131
return new
RegexQuery
.All(children.MoveToImmutable());
134
private static
RegexQuery
CompileText(RegexTextNode text)
152
return
RegexQuery
.None.Instance;
154
return new
RegexQuery
.Literal(builder.ToString());
157
private static
RegexQuery
CompileSimpleEscape(RegexSimpleEscapeNode _)
161
return
RegexQuery
.None.Instance;
164
private static
RegexQuery
CompileNumericQuantifier(RegexExpressionNode expression, EmbeddedSyntaxToken<RegexKind> firstNumberToken)
172
return
RegexQuery
.None.Instance;
NavigateTo\SearchPatternInfo.cs (1)
17
RegexQuery
? RegexQuery)
Microsoft.CodeAnalysis.Features.UnitTests (113)
NavigateTo\RegexQueryCompilerTests.cs (113)
19
var
query = RegexQueryCompiler.Compile("ReadLine");
20
var literal = Assert.IsType<
RegexQuery
.Literal>(query);
28
var
query = RegexQueryCompiler.Compile("(Read|Write)Line");
29
var all = Assert.IsType<
RegexQuery
.All>(query);
32
var any = Assert.IsType<
RegexQuery
.Any>(all.Children[0]);
34
Assert.Equal("read", Assert.IsType<
RegexQuery
.Literal>(any.Children[0]).Text);
35
Assert.Equal("write", Assert.IsType<
RegexQuery
.Literal>(any.Children[1]).Text);
37
Assert.Equal("line", Assert.IsType<
RegexQuery
.Literal>(all.Children[1]).Text);
44
var
query = RegexQueryCompiler.Compile("Goo.*Bar");
45
var all = Assert.IsType<
RegexQuery
.All>(query);
47
Assert.Equal("goo", Assert.IsType<
RegexQuery
.Literal>(all.Children[0]).Text);
48
Assert.Equal("bar", Assert.IsType<
RegexQuery
.Literal>(all.Children[1]).Text);
55
var
query = RegexQueryCompiler.Compile("Goo+");
63
var
query = RegexQueryCompiler.Compile(@"Goo\.Bar");
72
var
query = RegexQueryCompiler.Compile(@"\[Test\]");
81
var
query = RegexQueryCompiler.Compile("(?:Read|Write)");
82
var any = Assert.IsType<
RegexQuery
.Any>(query);
84
Assert.Equal("read", Assert.IsType<
RegexQuery
.Literal>(any.Children[0]).Text);
85
Assert.Equal("write", Assert.IsType<
RegexQuery
.Literal>(any.Children[1]).Text);
92
var
query = RegexQueryCompiler.Compile("(Go){3}");
94
Assert.Equal("go", Assert.IsType<
RegexQuery
.Literal>(query).Text);
101
var
query = RegexQueryCompiler.Compile("(Go){1,}");
103
Assert.Equal("go", Assert.IsType<
RegexQuery
.Literal>(query).Text);
110
var
query = RegexQueryCompiler.Compile("(Go){1,5}");
112
Assert.Equal("go", Assert.IsType<
RegexQuery
.Literal>(query).Text);
174
var inner = new
RegexQuery
.All([new
RegexQuery
.Literal("aa"), new
RegexQuery
.Literal("bb")]);
175
var outer = new
RegexQuery
.All([inner, new
RegexQuery
.Literal("cc")]);
177
var
optimized =
RegexQuery
.Optimize(outer);
178
var all = Assert.IsType<
RegexQuery
.All>(optimized);
180
Assert.Equal("aa", Assert.IsType<
RegexQuery
.Literal>(all.Children[0]).Text);
181
Assert.Equal("bb", Assert.IsType<
RegexQuery
.Literal>(all.Children[1]).Text);
182
Assert.Equal("cc", Assert.IsType<
RegexQuery
.Literal>(all.Children[2]).Text);
188
var inner = new
RegexQuery
.Any([new
RegexQuery
.Literal("aa"), new
RegexQuery
.Literal("bb")]);
189
var outer = new
RegexQuery
.Any([inner, new
RegexQuery
.Literal("cc")]);
191
var
optimized =
RegexQuery
.Optimize(outer);
192
var any = Assert.IsType<
RegexQuery
.Any>(optimized);
199
var query = new
RegexQuery
.All([
200
new
RegexQuery
.Literal("aa"),
201
RegexQuery
.None.Instance,
202
new
RegexQuery
.Literal("bb"),
205
var
optimized =
RegexQuery
.Optimize(query);
206
var all = Assert.IsType<
RegexQuery
.All>(optimized);
208
Assert.Equal("aa", Assert.IsType<
RegexQuery
.Literal>(all.Children[0]).Text);
209
Assert.Equal("bb", Assert.IsType<
RegexQuery
.Literal>(all.Children[1]).Text);
215
var query = new
RegexQuery
.Any([
216
new
RegexQuery
.Literal("aa"),
217
RegexQuery
.None.Instance,
220
var
optimized =
RegexQuery
.Optimize(query);
221
Assert.IsType<
RegexQuery
.None>(optimized);
227
var query = new
RegexQuery
.All([new
RegexQuery
.Literal("aa")]);
228
var
optimized =
RegexQuery
.Optimize(query);
229
Assert.Equal("aa", Assert.IsType<
RegexQuery
.Literal>(optimized).Text);
235
var query = new
RegexQuery
.Any([new
RegexQuery
.Literal("aa")]);
236
var
optimized =
RegexQuery
.Optimize(query);
237
Assert.Equal("aa", Assert.IsType<
RegexQuery
.Literal>(optimized).Text);
243
var query = new
RegexQuery
.All([
RegexQuery
.None.Instance,
RegexQuery
.None.Instance]);
244
var
optimized =
RegexQuery
.Optimize(query);
245
Assert.IsType<
RegexQuery
.None>(optimized);
271
Assert.True(new
RegexQuery
.Literal("goo").HasLiterals);
277
Assert.False(
RegexQuery
.None.Instance.HasLiterals);
283
var query = new
RegexQuery
.All([new
RegexQuery
.Literal("goo"),
RegexQuery
.None.Instance]);
290
var query = new
RegexQuery
.Any([new
RegexQuery
.Literal("goo"), new
RegexQuery
.Literal("bar")]);
297
var query = new
RegexQuery
.All([
RegexQuery
.None.Instance]);
308
var
query = RegexQueryCompiler.Compile("(Read|Write)Line")!;
311
var all = Assert.IsType<
RegexQuery
.All>(query);
313
Assert.IsType<
RegexQuery
.Any>(all.Children[0]);
314
Assert.IsType<
RegexQuery
.Literal>(all.Children[1]);
322
var
query = RegexQueryCompiler.Compile("Read(Line)?")!;
324
Assert.Equal("read", Assert.IsType<
RegexQuery
.Literal>(query).Text);
331
var
query = RegexQueryCompiler.Compile("Goo.*Bar")!;
332
var all = Assert.IsType<
RegexQuery
.All>(query);
334
Assert.Equal("goo", Assert.IsType<
RegexQuery
.Literal>(all.Children[0]).Text);
335
Assert.Equal("bar", Assert.IsType<
RegexQuery
.Literal>(all.Children[1]).Text);
342
var
query = RegexQueryCompiler.Compile("Goo.+Bar")!;
343
var all = Assert.IsType<
RegexQuery
.All>(query);
345
Assert.Equal("goo", Assert.IsType<
RegexQuery
.Literal>(all.Children[0]).Text);
346
Assert.Equal("bar", Assert.IsType<
RegexQuery
.Literal>(all.Children[1]).Text);
353
var
query = RegexQueryCompiler.Compile("(Get|Set)(Value|Item)s?")!;
356
var all = Assert.IsType<
RegexQuery
.All>(query);
359
var first = Assert.IsType<
RegexQuery
.Any>(all.Children[0]);
360
Assert.Equal("get", Assert.IsType<
RegexQuery
.Literal>(first.Children[0]).Text);
361
Assert.Equal("set", Assert.IsType<
RegexQuery
.Literal>(first.Children[1]).Text);
363
var second = Assert.IsType<
RegexQuery
.Any>(all.Children[1]);
364
Assert.Equal("value", Assert.IsType<
RegexQuery
.Literal>(second.Children[0]).Text);
365
Assert.Equal("item", Assert.IsType<
RegexQuery
.Literal>(second.Children[1]).Text);
376
var
query = RegexQueryCompiler.Compile("^Goo$")!;
377
Assert.Equal("goo", Assert.IsType<
RegexQuery
.Literal>(query).Text);
384
var
query = RegexQueryCompiler.Compile("Read.Line")!;
385
var all = Assert.IsType<
RegexQuery
.All>(query);
387
Assert.Equal("read", Assert.IsType<
RegexQuery
.Literal>(all.Children[0]).Text);
388
Assert.Equal("line", Assert.IsType<
RegexQuery
.Literal>(all.Children[1]).Text);
Microsoft.CodeAnalysis.Workspaces (24)
FindSymbols\TopLevelSyntaxTree\NavigateToSearchIndex.cs (3)
40
/// Evaluates a compiled <see cref="PatternMatching.
RegexQuery
"/> against this document's indexed
43
public bool RegexQueryCheckPasses(PatternMatching.
RegexQuery
query)
84
public bool RegexQueryCheckPasses(PatternMatching.
RegexQuery
query)
FindSymbols\TopLevelSyntaxTree\NavigateToSearchIndex.NavigateToSearchInfo.cs (7)
795
/// Evaluates a <see cref="
RegexQuery
"/> tree against this document's indexed bigrams and trigrams.
799
public bool RegexQueryCheckPasses(PatternMatching.
RegexQuery
query)
803
case PatternMatching.
RegexQuery
.All all:
804
foreach (
var
child in all.Children)
812
case PatternMatching.
RegexQuery
.Any any:
813
foreach (
var
child in any.Children)
821
case PatternMatching.
RegexQuery
.Literal literal:
PatternMatching\RegexQuery.cs (14)
41
public sealed class All(ImmutableArray<
RegexQuery
> children) : RegexQuery
43
public readonly ImmutableArray<
RegexQuery
> Children = children;
51
public sealed class Any(ImmutableArray<
RegexQuery
> children) : RegexQuery
53
public readonly ImmutableArray<
RegexQuery
> Children = children;
105
public static
RegexQuery
Optimize(
RegexQuery
query)
114
static
RegexQuery
OptimizeAll(All all)
116
using var _ = Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder<
RegexQuery
>.GetInstance(out var children);
118
foreach (
var
child in all.Children)
120
var
optimized = Optimize(child);
145
static
RegexQuery
OptimizeAny(Any any)
147
using var _ = Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder<
RegexQuery
>.GetInstance(out var children);
149
foreach (
var
child in any.Children)
151
var
optimized = Optimize(child);
Microsoft.CodeAnalysis.Workspaces.UnitTests (30)
FindSymbols\RegexPreFilterTests.cs (30)
39
var query = new
RegexQuery
.Literal("readline");
47
var query = new
RegexQuery
.Literal("read");
55
var query = new
RegexQuery
.All([
56
new
RegexQuery
.Literal("read"),
57
new
RegexQuery
.Literal("line"),
66
var query = new
RegexQuery
.Any([
67
new
RegexQuery
.Literal("read"),
68
new
RegexQuery
.Literal("write"),
80
var query = new
RegexQuery
.Literal("readline");
88
var query = new
RegexQuery
.All([
89
new
RegexQuery
.Any([
90
new
RegexQuery
.Literal("read"),
91
new
RegexQuery
.Literal("write"),
93
new
RegexQuery
.Literal("line"),
103
var query = new
RegexQuery
.All([
104
new
RegexQuery
.Literal("goo"),
105
new
RegexQuery
.Literal("bar"),
118
var query = new
RegexQuery
.Literal("xyz");
126
var query = new
RegexQuery
.All([
127
new
RegexQuery
.Literal("read"),
128
new
RegexQuery
.Literal("xyz"),
137
var query = new
RegexQuery
.Any([
138
new
RegexQuery
.Literal("xyz"),
139
new
RegexQuery
.Literal("qwerty"),
148
var query = new
RegexQuery
.Literal("goo");
156
var query = new
RegexQuery
.Literal("abc");
177
var query = new
RegexQuery
.Literal("bargoo");
190
var query = new
RegexQuery
.Literal("ooba");
201
var query = new
RegexQuery
.Literal("defabc");
212
var query = new
RegexQuery
.Literal("γδ");