aboutsummaryrefslogtreecommitdiff
path: root/exec/java-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaLexer.g4
blob: bc508d0e5af3b70a949a01e1af63c7b68e88e2f0 (plain)
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
lexer grammar SchemaLexer;

@header {
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
}

// data types
// https://drill.apache.org/docs/supported-data-types/
INT: 'INT';
INTEGER: 'INTEGER';
BIGINT: 'BIGINT';

FLOAT: 'FLOAT';
DOUBLE: 'DOUBLE';

DEC: 'DEC';
DECIMAL: 'DECIMAL';
NUMERIC: 'NUMERIC';

BOOLEAN: 'BOOLEAN';

CHAR: 'CHAR';
CHARACTER: 'CHARACTER';
VARYING: 'VARYING';
VARCHAR: 'VARCHAR';
BINARY: 'BINARY';
VARBINARY: 'VARBINARY';

TIME: 'TIME';
DATE: 'DATE';
TIMESTAMP: 'TIMESTAMP';
INTERVAL: 'INTERVAL';

YEAR: 'YEAR';
MONTH: 'MONTH';
DAY: 'DAY';
HOUR: 'HOUR';
MINUTE: 'MINUTE';
SECOND: 'SECOND';

MAP: 'MAP';
ARRAY: 'ARRAY';

// symbols
COMMA: ',';
REVERSE_QUOTE: '`';
LEFT_PAREN: '(';
RIGHT_PAREN: ')';
LEFT_ANGLE_BRACKET: '<';
RIGHT_ANGLE_BRACKET: '>';
SINGLE_QUOTE: '\'';
DOUBLE_QUOTE: '"';
LEFT_BRACE: '{';
RIGHT_BRACE: '}';
EQUALS_SIGN: '=';

NOT: 'NOT';
NULL: 'NULL';
AS: 'AS';
FORMAT: 'FORMAT';
DEFAULT: 'DEFAULT';
PROPERTIES: 'PROPERTIES';

NUMBER: [1-9] DIGIT* | '0';
fragment DIGIT: [0-9];

// identifiers

// column name can start with any letter, dollar sign ($) or underscore (_),
// consequently can contain any letter, dollar sign ($), underscore (_) or digit
// if any other symbols are present, use QUOTED_ID
ID: ([A-Z$_]) ([A-Z$_] | DIGIT)*;

// column name should be enclosed into backticks, can contain any symbols including space
// if contains backtick, it should be escaped with backslash (`a\\`b` -> a`b)
// if contains backslash, it should be escaped as well (`a\\\\b` -> a\b)
QUOTED_ID: REVERSE_QUOTE (~[`\\] | '\\' [`\\])* REVERSE_QUOTE;
SINGLE_QUOTED_STRING: SINGLE_QUOTE (~['\\] | '\\' ['\\])* SINGLE_QUOTE;
DOUBLE_QUOTED_STRING: DOUBLE_QUOTE (~["\\] | '\\' ["\\])* DOUBLE_QUOTE;

// skip
LINE_COMMENT:  '//' ~[\r\n]* -> skip;
BLOCK_COMMENT: '/*' .*? '*/' -> skip;
SPACE: [ \n\t\r\u000C]+ -> skip;