-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterQueryDemoUserActions.cs
More file actions
51 lines (44 loc) · 1.56 KB
/
FilterQueryDemoUserActions.cs
File metadata and controls
51 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
namespace FilterQueryDemo
{
public class FilterQueryDemoUserActions : FilterQueryDemoActions
{
// Stores the start-symbol value so it can be easily used for grammar processing.
private Query? _parseResult;
private readonly Dictionary<string, object> _context;
private bool? _lastResult;
public FilterQueryDemoUserActions()
{
_context = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
{
["status"] = "open",
["priority"] = 2d,
["owner"] = "sam",
["archived"] = false,
["score"] = 91.5d,
};
}
public bool EvaluateParsedQuery()
{
if (_parseResult is null)
{
throw new InvalidOperationException("No parsed query available. Call parser before evaluation.");
}
_lastResult = FilterQueryEvaluator.Evaluate(_parseResult, _context);
return _lastResult.Value;
}
// Called when the start symbol has been parsed. Contains the processed input.
public override void OnQuery(Query arg)
{
_parseResult = arg;
}
// Print the evaluated parse result if available.
public override string ToString()
{
return _lastResult is bool result
? $"Evaluation result: {result.ToString().ToLowerInvariant()}"
: "Grammar parsed successfully";
}
}
}