-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathast_types.go
130 lines (112 loc) · 6.24 KB
/
ast_types.go
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
// ================================================================
// AST and ASTNode data structures for the Miller DSL parser
// ================================================================
package dsl
import (
"github.com/johnkerl/miller/v6/pkg/parsing/token"
)
// ----------------------------------------------------------------
type AST struct {
RootNode *ASTNode
}
// ----------------------------------------------------------------
type ASTNode struct {
Token *token.Token // Nil for tokenless/structural nodes
Type TNodeType
Children []*ASTNode
}
// ----------------------------------------------------------------
type TNodeType string
const (
NodeTypeStringLiteral TNodeType = "string literal"
NodeTypeRegex TNodeType = "regular expression" // not in the BNF -- written during CST pre-build pass
NodeTypeRegexCaseInsensitive TNodeType = "case-insensitive regular expression" // E.g. "a.*b"i -- note the trailing 'i'
NodeTypeIntLiteral TNodeType = "int literal"
NodeTypeFloatLiteral TNodeType = "float literal"
NodeTypeBoolLiteral TNodeType = "bool literal"
NodeTypeNullLiteral TNodeType = "null literal"
NodeTypeArrayLiteral TNodeType = "array literal"
NodeTypeMapLiteral TNodeType = "map literal"
NodeTypeMapLiteralKeyValuePair TNodeType = "map-literal key-value pair"
NodeTypeArrayOrMapIndexAccess TNodeType = "array or map index access"
NodeTypeArraySliceAccess TNodeType = "array-slice access"
NodeTypeArraySliceEmptyLowerIndex TNodeType = "array-slice empty lower index"
NodeTypeArraySliceEmptyUpperIndex TNodeType = "array-slice empty upper index"
NodeTypePositionalFieldName TNodeType = "positionally-indexed field name"
NodeTypePositionalFieldValue TNodeType = "positionally-indexed field value"
NodeTypeArrayOrMapPositionalNameAccess TNodeType = "positionally-indexed map key"
NodeTypeArrayOrMapPositionalValueAccess TNodeType = "positionally-indexed map value"
NodeTypeContextVariable TNodeType = "context variable"
NodeTypeConstant TNodeType = "mathematical constant"
NodeTypeEnvironmentVariable TNodeType = "environment variable"
NodeTypeDirectFieldValue TNodeType = "direct field value"
NodeTypeIndirectFieldValue TNodeType = "indirect field value"
NodeTypeFullSrec TNodeType = "full record"
NodeTypeDirectOosvarValue TNodeType = "direct oosvar value"
NodeTypeIndirectOosvarValue TNodeType = "indirect oosvar value"
NodeTypeFullOosvar TNodeType = "full oosvar"
NodeTypeLocalVariable TNodeType = "local variable"
NodeTypeTypedecl TNodeType = "type declaration"
NodeTypeStatementBlock TNodeType = "statement block"
NodeTypeAssignment TNodeType = "assignment"
NodeTypeUnset TNodeType = "unset"
NodeTypeBareBoolean TNodeType = "bare boolean"
NodeTypeFilterStatement TNodeType = "filter statement"
NodeTypeTeeStatement TNodeType = "tee statement"
NodeTypeEmit1Statement TNodeType = "emit1 statement"
NodeTypeEmitStatement TNodeType = "emit statement"
NodeTypeEmitPStatement TNodeType = "emitp statement"
NodeTypeEmitFStatement TNodeType = "emitf statement"
NodeTypeEmittableList TNodeType = "emittable list"
NodeTypeEmitKeys TNodeType = "emit keys"
NodeTypeDumpStatement TNodeType = "dump statement"
NodeTypeEdumpStatement TNodeType = "edump statement"
NodeTypePrintStatement TNodeType = "print statement"
NodeTypeEprintStatement TNodeType = "eprint statement"
NodeTypePrintnStatement TNodeType = "printn statement"
NodeTypeEprintnStatement TNodeType = "eprintn statement"
// For 'print > filename, "string"' et al.
NodeTypeRedirectWrite TNodeType = "redirect write"
NodeTypeRedirectAppend TNodeType = "redirect append"
NodeTypeRedirectPipe TNodeType = "redirect pipe"
NodeTypeRedirectTargetStdout TNodeType = "stdout redirect target"
NodeTypeRedirectTargetStderr TNodeType = "stderr redirect target"
NodeTypeRedirectTarget TNodeType = "redirect target"
// This helps various emit-variant sub-ASTs have the same shape. For
// example, in 'emit > "foo.txt", @v' and 'emit @v', the latter has a no-op
// for its redirect target.
NodeTypeNoOp TNodeType = "no-op"
// The dot operator is a little different from other operators since it's
// type-dependent: for strings/int/bools etc it's just concatenation of
// string representations, but if the left-hand side is a map, it's a
// key-lookup with an unquoted literal on the right. E.g. mymap.foo is the
// same as mymap["foo"].
NodeTypeOperator TNodeType = "operator"
NodeTypeDotOperator TNodeType = "dot operator"
NodeTypeFunctionCallsite TNodeType = "function callsite"
NodeTypeSubroutineCallsite TNodeType = "subroutine callsite"
NodeTypeBeginBlock TNodeType = "begin block"
NodeTypeEndBlock TNodeType = "end block"
NodeTypeIfChain TNodeType = "if-chain"
NodeTypeIfItem TNodeType = "if-item"
NodeTypeCondBlock TNodeType = "cond block"
NodeTypeWhileLoop TNodeType = "while loop"
NodeTypeDoWhileLoop TNodeType = "do-while`loop"
NodeTypeForLoopOneVariable TNodeType = "single-variable for-loop"
NodeTypeForLoopTwoVariable TNodeType = "double-variable for-loop"
NodeTypeForLoopMultivariable TNodeType = "multi-variable for-loop"
NodeTypeTripleForLoop TNodeType = "triple-for loop"
NodeTypeBreak TNodeType = "break"
NodeTypeContinue TNodeType = "continue"
NodeTypeNamedFunctionDefinition TNodeType = "function definition"
NodeTypeUnnamedFunctionDefinition TNodeType = "function literal"
NodeTypeSubroutineDefinition TNodeType = "subroutine definition"
NodeTypeParameterList TNodeType = "parameter list"
NodeTypeParameter TNodeType = "parameter"
NodeTypeParameterName TNodeType = "parameter name"
NodeTypeReturn TNodeType = "return"
// A special token which causes a panic when evaluated. This is for
// testing that AND/OR short-circuiting is implemented correctly: output =
// input1 || panic should NOT panic the process when input1 is true.
NodeTypePanic TNodeType = "panic token"
)