-
Notifications
You must be signed in to change notification settings - Fork 1
/
SubstraitType.g4
209 lines (181 loc) · 4.37 KB
/
SubstraitType.g4
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
grammar SubstraitType;
//
fragment A : [aA];
fragment B : [bB];
fragment C : [cC];
fragment D : [dD];
fragment E : [eE];
fragment F : [fF];
fragment G : [gG];
fragment H : [hH];
fragment I : [iI];
fragment J : [jJ];
fragment K : [kK];
fragment L : [lL];
fragment M : [mM];
fragment N : [nN];
fragment O : [oO];
fragment P : [pP];
fragment Q : [qQ];
fragment R : [rR];
fragment S : [sS];
fragment T : [tT];
fragment U : [uU];
fragment V : [vV];
fragment W : [wW];
fragment X : [xX];
fragment Y : [yY];
fragment Z : [zZ];
If : I F;
Then : T H E N;
Else : E L S E;
// TYPES
Boolean : B O O L E A N;
I8 : I '8';
I16 : I '16';
I32 : I '32';
I64 : I '64';
FP32 : F P '32';
FP64 : F P '64';
String : S T R I N G;
Binary : B I N A R Y;
Timestamp: T I M E S T A M P;
TimestampTZ: T I M E S T A M P '_' T Z;
Date : D A T E;
Time : T I M E;
IntervalYear: I N T E R V A L '_' Y E A R;
IntervalDay: I N T E R V A L '_' D A Y;
IntervalCompound: I N T E R V A L '_' C O M P O U N D;
UUID : U U I D;
Decimal : D E C I M A L;
PrecisionTimestamp: P R E C I S I O N '_' T I M E S T A M P;
PrecisionTimestampTZ: P R E C I S I O N '_' T I M E S T A M P '_' T Z;
FixedChar: F I X E D C H A R;
VarChar : V A R C H A R;
FixedBinary: F I X E D B I N A R Y;
Struct : S T R U C T;
NStruct : N S T R U C T;
List : L I S T;
Map : M A P;
ANY : A N Y;
UserDefined: U '!';
// OPERATIONS
And : A N D;
Or : O R;
Assign : ':=';
// COMPARE
Eq : '=';
NotEquals: '!=';
Gte : '>=';
Lte : '<=';
Gt : '>';
Lt : '<';
Bang : '!';
// MATH
Plus : '+';
Minus : '-';
Asterisk : '*';
ForwardSlash : '/';
Percent : '%';
// ORGANIZE
OBracket : '[';
CBracket : ']';
OParen : '(';
CParen : ')';
SColon : ';';
Comma : ',';
QMark : '?';
Colon : ':';
SingleQuote: '\'';
Number
: '-'? Int
;
Identifier
: ('a'..'z' | 'A'..'Z' | '_' | '$') ('a'..'z' | 'A'..'Z' | '_' | '$' | Digit)*
;
LineComment
: '//' ~[\r\n]* -> channel(HIDDEN)
;
BlockComment
: ( '/*'
( '/'* BlockComment
| ~[/*]
| '/'+ ~[/*]
| '*'+ ~[/*]
)*
'*'*
'*/'
) -> channel(HIDDEN)
;
Whitespace
: [ \t]+ -> channel(HIDDEN)
;
Newline
: ( '\r' '\n'?
| '\n'
)
;
fragment Int
: '1'..'9' Digit*
| '0'
;
fragment Digit
: '0'..'9'
;
start: expr EOF;
scalarType
: Boolean #Boolean
| I8 #i8
| I16 #i16
| I32 #i32
| I64 #i64
| FP32 #fp32
| FP64 #fp64
| String #string
| Binary #binary
| Timestamp #timestamp
| TimestampTZ #timestampTz
| Date #date
| Time #time
| IntervalYear #intervalYear
| UUID #uuid
| UserDefined Identifier #userDefined
;
parameterizedType
: FixedChar isnull='?'? Lt len=numericParameter Gt #fixedChar
| VarChar isnull='?'? Lt len=numericParameter Gt #varChar
| FixedBinary isnull='?'? Lt len=numericParameter Gt #fixedBinary
| Decimal isnull='?'? Lt precision=numericParameter Comma scale=numericParameter Gt #decimal
| IntervalDay isnull='?'? Lt precision=numericParameter Gt #intervalDay
| IntervalCompound isnull='?'? Lt precision=numericParameter Gt #intervalCompound
| PrecisionTimestamp isnull='?'? Lt precision=numericParameter Gt #precisionTimestamp
| PrecisionTimestampTZ isnull='?'? Lt precision=numericParameter Gt #precisionTimestampTZ
| Struct isnull='?'? Lt expr (Comma expr)* Gt #struct
| NStruct isnull='?'? Lt Identifier expr (Comma Identifier expr)* Gt #nStruct
| List isnull='?'? Lt expr Gt #list
| Map isnull='?'? Lt key=expr Comma value=expr Gt #map
;
numericParameter
: Number #numericLiteral
| Identifier #numericParameterName
| expr #numericExpression
;
anyType: ANY;
type
: scalarType isnull='?'?
| parameterizedType
| anyType isnull='?'?
;
// : (OParen innerExpr CParen | innerExpr)
expr
: OParen expr CParen #ParenExpression
| Identifier Eq expr Newline+ (Identifier Eq expr Newline+)* finalType=type Newline* #MultilineDefinition
| type #TypeLiteral
| number=Number #LiteralNumber
| identifier=Identifier isnull='?'? #TypeParam
| Identifier OParen (expr (Comma expr)*)? CParen #FunctionCall
| left=expr op=(And | Or | Plus | Minus | Lt | Gt | Eq | NotEquals | Lte | Gte | Asterisk | ForwardSlash) right=expr #BinaryExpr
| If ifExpr=expr Then thenExpr=expr Else elseExpr=expr #IfExpr
| (Bang) expr #NotExpr
| ifExpr=expr QMark thenExpr=expr Colon elseExpr=expr #Ternary
;