-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
41 lines (32 loc) · 809 Bytes
/
parser.py
File metadata and controls
41 lines (32 loc) · 809 Bytes
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
from lark import Lark
type_syntax = '''data_type: primitive_type
| array_type
| map_type
| row_type
!primitive_type: "tinyint"
| "smallint"
| "integer"
| "bigint"
| "boolean"
| "real"
| "double"
| "date"
| "time"
| "timestamp"
| "varchar"
| "char"
| "varbinary"
| "json"
| DECIMAL
array_type: "array(" data_type ")"
map_type: "map(" data_type ", " data_type ")"
| "map(" data_type "," data_type ")"
row_type: "row(" (CNAME " " data_type ", ")* CNAME" "data_type")"
| "row(" (CNAME " " data_type ",")* CNAME" "data_type")"
DECIMAL: "decimal("INT","INT")"
INT: /[0-9]+/
CNAME: /[^\s`]+/ // column name: any non-whitespace char or anything between "`"
| /`[^`]*`/
'''
type_parser = Lark(type_syntax, start='data_type')
# from lark.tree import pydot__tree_to_png