1
- //
2
- // File.swift
3
- //
4
- //
5
- // Created by Adam Fowler on 27/05/2021.
6
- //
7
-
1
+ /// JMES expression abstract syntax tree
8
2
public indirect enum Ast : Equatable {
3
+ /// compares two nodes using a comparator
9
4
case comparison( comparator: Comparator , lhs: Ast , rhs: Ast )
5
+ /// if `predicate` evaluates to a truthy value returns result from `then`
10
6
case condition( predicate: Ast , then: Ast )
7
+ /// returns the current node
11
8
case identity
9
+ /// used by functions to dynamically evaluate argument values
12
10
case expRef( ast: Ast )
11
+ /// evaluates nodes and then flattens it one level
13
12
case flatten( node: Ast )
13
+ /// function name and a vector of function argument expressions
14
14
case function( name: String , args: [ Ast ] )
15
+ /// extracts a key value from an object
15
16
case field( name: String )
17
+ /// extracts an indexed value from an array
16
18
case index( index: Int )
19
+ /// resolves to a literal value
17
20
case literal( value: JMESVariable )
21
+ /// resolves to a list of evaluated expressions
18
22
case multiList( elements: [ Ast ] )
23
+ /// resolves to a map of key/evaluated expression pairs
19
24
case multiHash( elements: [ String : Ast ] )
25
+ /// evaluates to true/false based on expression
20
26
case not( node: Ast )
27
+ /// evalutes `lhs` and pushes each value through to `rhs`
21
28
case projection( lhs: Ast , rhs: Ast )
29
+ /// evaluates expression and if result is an object then return array of its values
22
30
case objectValues( node: Ast )
31
+ /// evaluates `lhs` and if not truthy returns, otherwise evaluates `rhs`
23
32
case and( lhs: Ast , rhs: Ast )
33
+ /// evaluates `lhs` and if truthy returns, otherwise evaluates `rhs`
24
34
case or( lhs: Ast , rhs: Ast )
35
+ /// returns a slice of an array
25
36
case slice( start: Int ? , stop: Int ? , step: Int )
37
+ /// evalutes `lhs` and then provides that value to `rhs`
26
38
case subExpr( lhs: Ast , rhs: Ast )
27
39
}
28
40
41
+ /// Comparator used in comparison AST nodes
29
42
public enum Comparator : Equatable {
30
43
case equal
31
44
case notEqual
@@ -34,6 +47,7 @@ public enum Comparator: Equatable {
34
47
case greaterThan
35
48
case greaterThanOrEqual
36
49
50
+ /// initialise `Comparator` from `Token`
37
51
init ( from token: Token ) throws {
38
52
switch token {
39
53
case . equals: self = . equal
0 commit comments