-
Notifications
You must be signed in to change notification settings - Fork 175
/
ast.py
90 lines (46 loc) · 2.08 KB
/
ast.py
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
# AST nodes have this structure:
# {"type": <node type>", children: [], "value": ""}
def comparator(name, first, second):
return {'type': 'comparator', 'children': [first, second], 'value': name}
def current_node():
return {'type': 'current', 'children': []}
def expref(expression):
return {'type': 'expref', 'children': [expression]}
def function_expression(name, args):
return {'type': 'function_expression', 'children': args, 'value': name}
def field(name):
return {"type": "field", "children": [], "value": name}
def filter_projection(left, right, comparator):
return {'type': 'filter_projection', 'children': [left, right, comparator]}
def flatten(node):
return {'type': 'flatten', 'children': [node]}
def identity():
return {"type": "identity", 'children': []}
def index(index):
return {"type": "index", "value": index, "children": []}
def index_expression(children):
return {"type": "index_expression", 'children': children}
def key_val_pair(key_name, node):
return {"type": "key_val_pair", 'children': [node], "value": key_name}
def literal(literal_value):
return {'type': 'literal', 'value': literal_value, 'children': []}
def multi_select_dict(nodes):
return {"type": "multi_select_dict", "children": nodes}
def multi_select_list(nodes):
return {"type": "multi_select_list", "children": nodes}
def or_expression(left, right):
return {"type": "or_expression", "children": [left, right]}
def and_expression(left, right):
return {"type": "and_expression", "children": [left, right]}
def not_expression(expr):
return {"type": "not_expression", "children": [expr]}
def pipe(left, right):
return {'type': 'pipe', 'children': [left, right]}
def projection(left, right):
return {'type': 'projection', 'children': [left, right]}
def subexpression(children):
return {"type": "subexpression", 'children': children}
def slice(start, end, step):
return {"type": "slice", "children": [start, end, step]}
def value_projection(left, right):
return {'type': 'value_projection', 'children': [left, right]}