Skip to content

Commit 2ae45dc

Browse files
committed
BREAKING! Move IntervalUnit and IntervalUnitRange inside AllDataTypeNodes
1 parent fc3f9e6 commit 2ae45dc

File tree

5 files changed

+58
-63
lines changed

5 files changed

+58
-63
lines changed

src/cst/DataType.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BaseNode, Empty, Keyword } from "./Base";
22
import { ColumnConstraint } from "./Constraint";
33
import { ColumnDefinition } from "./CreateTable";
44
import { EntityName, Expr, Identifier, ListExpr, ParenExpr } from "./Expr";
5-
import { IntervalUnit, IntervalUnitRange, NumberLiteral } from "./Literal";
5+
import { NumberLiteral } from "./Literal";
66

77
export type AllDataTypeNodes =
88
| DataTypeName
@@ -16,7 +16,9 @@ export type AllDataTypeNodes =
1616
| GenericTypeParams
1717
| ArrayTypeParam
1818
| StructTypeParam
19-
| ArrayBounds;
19+
| ArrayBounds
20+
| IntervalUnit
21+
| IntervalUnitRange;
2022

2123
export type DataType =
2224
// in PostgreSQL only builtin data types will be parsed DataTypeName,
@@ -77,6 +79,54 @@ export interface IntervalDataType extends BaseNode {
7779
unit?: IntervalUnit | IntervalUnitRange;
7880
}
7981

82+
export interface IntervalUnitRange extends BaseNode {
83+
type: "interval_unit_range";
84+
fromUnit: IntervalUnit;
85+
toKw: Keyword<"TO">;
86+
toUnit: IntervalUnit;
87+
}
88+
89+
export interface IntervalUnit extends BaseNode {
90+
type: "interval_unit";
91+
unitKw: Keyword<
92+
| "CENTURY"
93+
| "DAY_HOUR"
94+
| "DAY_MICROSECOND"
95+
| "DAY_MINUTE"
96+
| "DAY_SECOND"
97+
| "DAY"
98+
| "DECADE"
99+
| "DOW"
100+
| "DOY"
101+
| "EPOCH"
102+
| "HOUR_MICROSECOND"
103+
| "HOUR_MINUTE"
104+
| "HOUR_SECOND"
105+
| "HOUR"
106+
| "ISODOW"
107+
| "ISOYEAR"
108+
| "JULIAN"
109+
| "MICROSECOND"
110+
| "MICROSECONDS"
111+
| "MILLENNIUM"
112+
| "MILLISECONDS"
113+
| "MINUTE_MICROSECOND"
114+
| "MINUTE_SECOND"
115+
| "MINUTE"
116+
| "MONTH"
117+
| "QUARTER"
118+
| "SECOND_MICROSECOND"
119+
| "SECOND"
120+
| "TIMEZONE_HOUR"
121+
| "TIMEZONE_MINUTE"
122+
| "TIMEZONE"
123+
| "WEEK"
124+
| "YEAR_MONTH"
125+
| "YEAR"
126+
>;
127+
precision?: ParenExpr<NumberLiteral>;
128+
}
129+
80130
// BigQuery
81131
export interface GenericTypeParams extends BaseNode {
82132
type: "generic_type_params";

src/cst/Expr.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { AllColumns, BaseNode, Empty, Keyword } from "./Base";
2-
import { DataType } from "./DataType";
3-
import {
4-
AllLiteralNodes,
5-
IntervalUnit,
6-
Literal,
7-
StringLiteral,
8-
} from "./Literal";
2+
import { DataType, IntervalUnit } from "./DataType";
3+
import { Literal, StringLiteral } from "./Literal";
94
import { Node, Program, TriggerEventExpr } from "./Node";
105
import {
116
LimitClause,
@@ -38,8 +33,7 @@ export type AllExprNodes =
3833
| FullTextMatchArgs
3934
| ArraySubscript
4035
| ArraySubscriptSpecifier
41-
| ArraySliceSpecifier
42-
| AllLiteralNodes;
36+
| ArraySliceSpecifier;
4337

4438
export type Expr =
4539
| ListExpr

src/cst/Literal.ts

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { BaseNode, Keyword } from "./Base";
2+
import { IntervalUnit, IntervalUnitRange } from "./DataType";
23
import { ParenExpr } from "./Expr";
34

4-
export type AllLiteralNodes = Literal | IntervalUnit | IntervalUnitRange;
5-
65
export type Literal =
76
| StringLiteral
87
| NumberLiteral
@@ -110,51 +109,3 @@ export interface IntervalLiteral extends BaseNode {
110109
value: StringLiteral | NumberLiteral;
111110
unit?: IntervalUnit | IntervalUnitRange;
112111
}
113-
114-
export interface IntervalUnitRange extends BaseNode {
115-
type: "interval_unit_range";
116-
fromUnit: IntervalUnit;
117-
toKw: Keyword<"TO">;
118-
toUnit: IntervalUnit;
119-
}
120-
121-
export interface IntervalUnit extends BaseNode {
122-
type: "interval_unit";
123-
unitKw: Keyword<
124-
| "CENTURY"
125-
| "DAY_HOUR"
126-
| "DAY_MICROSECOND"
127-
| "DAY_MINUTE"
128-
| "DAY_SECOND"
129-
| "DAY"
130-
| "DECADE"
131-
| "DOW"
132-
| "DOY"
133-
| "EPOCH"
134-
| "HOUR_MICROSECOND"
135-
| "HOUR_MINUTE"
136-
| "HOUR_SECOND"
137-
| "HOUR"
138-
| "ISODOW"
139-
| "ISOYEAR"
140-
| "JULIAN"
141-
| "MICROSECOND"
142-
| "MICROSECONDS"
143-
| "MILLENNIUM"
144-
| "MILLISECONDS"
145-
| "MINUTE_MICROSECOND"
146-
| "MINUTE_SECOND"
147-
| "MINUTE"
148-
| "MONTH"
149-
| "QUARTER"
150-
| "SECOND_MICROSECOND"
151-
| "SECOND"
152-
| "TIMEZONE_HOUR"
153-
| "TIMEZONE_MINUTE"
154-
| "TIMEZONE"
155-
| "WEEK"
156-
| "YEAR_MONTH"
157-
| "YEAR"
158-
>;
159-
precision?: ParenExpr<NumberLiteral>;
160-
}

src/showNode/data_type.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export const dataTypeMap: FullTransformMap<string, AllDataTypeNodes> = {
1111
time_data_type: (node) =>
1212
show([node.timeKw, node.precision, node.timeZoneKw]),
1313
interval_data_type: (node) => show([node.intervalKw, node.unit]),
14+
interval_unit_range: (node) => show([node.fromUnit, node.toKw, node.toUnit]),
15+
interval_unit: (node) => show([node.unitKw, node.precision]),
1416
generic_type_params: (node) => show(["<", node.params, ">"]),
1517
array_type_param: (node) => show([node.dataType, node.constraints]),
1618
struct_type_param: (node) =>

src/showNode/expr.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ export const exprMap: FullTransformMap<string, AllExprNodes> = {
7272
bignumeric_literal: (node) => show([node.bignumericKw, node.string]),
7373
interval_literal: (node) =>
7474
show([node.intervalKw, node.precision, node.value, node.unit]),
75-
interval_unit_range: (node) => show([node.fromUnit, node.toKw, node.toUnit]),
76-
interval_unit: (node) => show([node.unitKw, node.precision]),
7775

7876
// Basic language elements
7977
identifier: (node) => node.text,

0 commit comments

Comments
 (0)