-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyzer.eve
583 lines (441 loc) · 11.2 KB
/
analyzer.eve
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# Eve Analyzer
## assign variables
For every variable there is a group
~~~eve disabled
search
variable = [#variable]
number = random[seed: variable]
commit
[#group number variable]
~~~
~~~eve disabled
search
variable = [#variable not(group)]
group = [#group variable]
commit
variable.group := group
~~~
Handle a constant equivalence
~~~eve disabled
search
eq = [#equality]
(a, b) = if eq.a.tag, not(eq.b.tag) then (eq.a, eq.b)
else if eq.b.tag, not(eq.a.tag) then (eq.b, eq.a)
bind
a.constant += b
~~~
Handle variable equivalence
~~~eve disabled
search
[#equality a b]
a.group != b.group
min-a = min[value: a.group.number, given: a.group.number, per: a]
min-b = min[value: b.group.number, given: b.group.number, per: b]
a-group = [#group number: min-a]
b-group = [#group number: min-b]
(new, old) = if min-a < min-b then (a-group, b-group)
else if min-b < min-a then (b-group, a-group)
var = [#variable group: old]
commit
var.group := new
~~~
## associate record-tags to both actions and scans
Any scan attached to a pattern that is looking for our record-tag is
related to that tag.
~~~
search
[#query record-tag]
[#scan entity: [register] attribute: "tag" value: record-tag block]
scan = [#scan entity: [register] block]
bind
scan.record-tag += record-tag
~~~
Any action attached to a pattern that is looking for our record-tag is
related to that tag.
~~~
search
[#query record-tag]
[#action entity: [register] attribute: "tag" value: record-tag block]
action = [#action entity: [register] block]
bind
action.record-tag += record-tag
~~~
Actions that are adding to an entity with our record tag, are also for the
same record-tag.
~~~
search
[#query record-tag]
[#scan entity: [register] record-tag block]
action = [#action entity: [register] block]
bind
action.record-tag += record-tag
~~~
The inverse is true as well, if an action is for our record tag and the entity
is used in a scan, then that scan is for this tag.
~~~
search
[#query record-tag]
[#action entity: [register] record-tag block]
scan = [#scan entity: [register] block]
bind
scan.record-tag += record-tag
~~~
## tag equivalence
~~~
search
attribute = "tag"
[#scan block entity: [register] attribute value: tag]
[#action block entity: [register] attribute value: tag2]
bind
[#tag-equivalence tag tag2]
~~~
## unprovided scans
~~~ eve disabled
search
scan = [#scan record-tag attribute]
not( action = [#action record-tag attribute]
value = if scan.value = action.value then true
else if scan.value = [#variable] then true
else if action.value = [#variable] then true )
bind
scan += #unprovided
~~~
~~~ eve disabled
search
scan = [#scan #analyzer/any attribute]
not( action = [#action attribute]
value = if scan.value = action.value then true
else if scan.value = [#variable] then true
else if action.value = [#variable] then true )
bind
scan += #unprovided
~~~
~~~ eve disabled
search
scan = [#scan #unprovided start stop record-tag attribute block]
bind @editor
[#comment scan | block start stop message: "{{attribute}} is never added to {{record-tag}} records, so this will always be empty"]
~~~
# token query
## query links
~~~
search
query = [#query token]
[#link a: to b: token]
bind
[#query-link token to distance: 1]
~~~
~~~
search
query = [#query token]
link = [#query-link token distance]
[#link a: to b: link.to]
bind
[#query-link token to distance: distance + 1]
~~~
## token -> variable
~~~
search
query = [#query token]
[#link a: to b: token]
to = [#variable register block]
token.block = block
bind
query.register += [token variable: to register block name: to.name]
~~~
We can also associate what attribute that variable is writing to if there is one
~~~
search
query = [#query register]
action = [#action attribute value: register.variable]
bind
register.attribute += attribute
~~~
## token -> scan
~~~
search
query = [#query token]
[#query-link token to]
to = [#scan start stop]
start <= token.start <= stop
bind
query.scan += to
~~~
~~~
search
[#query token scan: [#scan record-tag attribute value]]
provider = [#action record-tag attribute start stop]
bind @editor
[#comment provider | start stop kind: "warning" message: "this is providing it" ]
bind @browser
[#div text: "provided by: {{provider}}"]
~~~
~~~
search
[#query token scan: [#scan record-tag attribute]]
bind @browser
[#div text: "{{token}} scans #{{record-tag}} {{attribute}}"]
~~~
## token -> action
~~~
search
query = [#query token]
[#query-link token to]
to = [#action start stop]
start <= token.start <= stop
bind
query.action += to
~~~
~~~
search
[#query token action: [#action record-tag attribute]]
consumer = [#scan record-tag attribute start stop]
bind @editor
[#comment consumer | start stop kind: "warning" message: "This is consuming" ]
bind @browser
[#div text: "consumed by: {{consumer}}"]
~~~
~~~
search
[#query token action: [#action record-tag attribute]]
bind @browser
[#div text: "{{token}} actions #{{record-tag}} {{attribute}}"]
~~~
## token -> record
~~~
search
query = [#query]
entity = if query.scan then query.scan.entity
else if query.action then query.action.entity
record = [#record entity start stop]
bind
query <- [entity entity-register: entity.register]
~~~
## find variables related to a span
Determine the kind of span we're looking for
~~~
search
query = [#findRelated for: "span" span]
kind = if span = [#action] then "action"
else if span = [#scan] then "scan"
else if span = [#record kind] then kind
bind
query.kind := kind
~~~
If the span is an action, we need to find the variables related to both the
value and the entity
~~~
search
query = [#findRelated for: "span" span kind]
span = [tag: kind entity value]
variable = if entity = [#variable] then entity
if value = [#variable] then value
[#link a: variable b: token]
bind
query.variable += token
~~~
If the span is a record, we need to find all the actions directly related to it
~~~
search
query = [#findRelated for: "span" span]
span = [#record entity start stop kind]
scan = [tag: kind, entity]
scan.start >= start
scan.stop <= stop
scan.value = [#variable]
[#link a: scan.value b: token]
[#link a: entity b: entity-token]
bind
query.variable += entity-token
query.variable += token
~~~
if one of the variables we found is the entity for another scan/action, then we need
to add him to the list of things we want to find relateds for
~~~
search
query = [#findRelated for: "span" kind variable]
[#link a: entity b: variable]
span = [tag: kind entity]
bind
query.span += span
~~~
## findValue
~~~
search
query = [#findValue]
~~~
## findCardinality
~~~
search
query = [#findCardinality]
~~~
## find spans related to a variable
~~~
search
query = [#findRelated for: "variable" variable: token]
[#link a: variable b: token]
span = if span.entity = variable then span
if span.value = variable then span
bind
query.span += span
~~~
## recordId -> build-node
~~~
search
query = [#findSource recordId not(attribute)]
search @evaluation-session @evaluation-browser
recordId = [tag]
bind
query.cool += tag
~~~
Find out what nodes contribute to a record
~~~
search
query = [#findSource recordId not(attribute)]
search @evaluation-session @evaluation-browser
lookup[record: recordId, attribute, value, node]
bind
query.node += node
~~~
Find out what nodes contribute to a specific attribute on a record
~~~
search
query = [#findSource recordId attribute]
search @evaluation-session @evaluation-browser
lookup[record: recordId, attribute, value, node]
bind
query.node += node
~~~
We may also want to lookup what node created a complete eav
~~~
search
query = [#findSource recordId attribute value]
search @evaluation-session @evaluation-browser
lookup[record: recordId, attribute, value, node]
bind
query.node += node
~~~
## scan to block
~~~
search
query = [#findSource span: [block]]
bind
query.block += block
~~~
## nodeId -> creator (aka findSource)
~~~
search
query = [#findSource node]
action = [#action entity build-node: node block]
span = if query.attribute then action
else if record = [#record entity] then record
else action
bind
query.source += [span block start: span.start, stop: span.stop]
~~~
## build-node to creator
~~~
search
query = [#query build-node]
[#action entity build-node]
record = [#record entity]
commit
query.pattern := record
~~~
## findRecordsFromToken
Add the #query tag so that we find all the scans/actions related to the given
token
~~~
search
query = [#findRecordsFromToken]
commit
query += #query
~~~
~~~
search
query = [#findRecordsFromToken token]
[#query-link token to]
to = [#action build-node]
commit
query.build-node += build-node
~~~
~~~
search
query = [#findRecordsFromToken token]
[#query-link token to]
to = [#action build-node]
search @evaluation-session @evaluation-browser
lookup[node: build-node, record]
commit
query.record += record
~~~
## findAffector
Store what record-tag we need to compute providers and consumers for
~~~
search
query = [#findAffector recordId]
search @evaluation-session @evaluation-browser
tag = recordId.tag
bind
query += #query
query.record-tag += tag
~~~
Find affectors based on what providers and consumers exist
~~~
search
query = [#findAffector recordId attribute record-tag]
scan = [#scan entity: [register] record-tag block]
action = [#action entity: [register] block attribute]
final = if record = [#record entity: [register] start stop]
action.start >= start
action.stop <= stop then record
else action
bind
query.affector := [action: final, block]
~~~
~~~
search
query = [#findAffector recordId attribute]
//scan = [#scan entity: [register] record-tag: tag block]
//action = [#action entity: [register] attribute block ]
search @evaluation-session @evaluation-browser
recordId = [tag]
bind @browser
//[#div text: "yo {{tag}}"]
~~~
## findRootDrawers
~~~
search
query = [#findRootDrawers]
action = [#action block entity: [register] scopes: "browser"]
not([#scan block entity: [register]])
not([#action block value: [register]])
final = if record = [#record entity: [register] start stop]
action.start >= start
action.stop <= stop then record
else action
commit
query.drawer += [id: final start: final.start stop: final.stop]
~~~
## findMaybeDrawers
~~~
commit
[#drawing-tag tag: "div"]
[#drawing-tag tag: "span"]
[#drawing-tag tag: "img"]
[#drawing-tag tag: "input"]
[#drawing-tag tag: "button"]
~~~
~~~
search
query = [#findMaybeDrawers]
[#drawing-tag tag: drawing-tag]
action = [#action entity: [register] block attribute: "tag" value: drawing-tag]
not(action.scopes = "browser")
final = if record = [#record entity: [register] start stop]
action.start >= start
action.stop <= stop then record
else action
commit
query.drawer += [id: final start: final.start stop: final.stop ]
~~~