-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.ungram
61 lines (51 loc) · 1.84 KB
/
query.ungram
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
52
53
54
55
56
57
58
59
60
61
// Un-Grammar for the tracing query filter language.
// https://rust-analyzer.github.io/blog/2020/10/24/introducing-ungrammar.html
//
// This does not specify parsing rules (ambiguities, precedence, etc).
// It is solely a human artifact intended as a communcation tool.
//
// Legend:
//
// // -- comment
// Name = -- non-terminal definition
// 'ident' -- token (terminal)
// A B -- sequence
// A | B -- alternation
// A* -- zero or more repetition
// A? -- zero or one repetition
// (A) -- same as A
// label:A -- suggested name for field of AST node
// This grammar as-is has problems differentiating the filtering of events and
// of spans themselves; this comes from only thinking about filtering the output
// of fmtlayer and not the data model itself. As such, it needs rethinking and
// a proper redesign.
Filter = queries:(Directive (',' Directive)*)* ,?
Directive = '(' query:Query ')' ('=' level:LevelFilter)?
LevelFilter = 'OFF' | 'ERROR' | 'WARN' | 'INFO' | 'DEBUG' | 'TRACE'
Query =
| select:Select
| union:(Query '|' Query)
| intersect:(Query '&' Query)
| difference:(Query? '-' Query)
| '(' query:Query? ')' ('=' level:LevelFilter)?
Select =
| target:Name
| target:Name? span:Span
| target:Name? event:Event
Span = '?' name:Name fields:Fields? (('>' child:Span) | descendant:Span)?
Event = fields:Fields
Fields = '{' (Field ',')* Field? '}'
Field =
| name:Name
| name:Name '=' fields:Fields
| name:Name '=' value:String
| name:Name cmp:('=','<','<=','>','>=') value:Number
| name:Name '=' value:('true' | 'false')
Name = '/([^[:punct:][:space:]]|[_:])+/' | String
String = '/(#*)".*?"\1/'
Number = '/[0-9]+(\.[0-9]+)?([eE][0-9]+)?/'
_Whitespace = '/[[:space:]]+/'
// [[:punct:]
// !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
// [[:space:]]
// \t\n\v\f\r\x20