forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgresql.pegjs
More file actions
105 lines (94 loc) · 2.55 KB
/
Copy pathpostgresql.pegjs
File metadata and controls
105 lines (94 loc) · 2.55 KB
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
proc_expr
= select_stmt
/ proc_join
/ proc_additive_expr
/ proc_array
proc_additive_expr
= head:proc_multiplicative_expr
tail:(__ additive_operator __ proc_multiplicative_expr)* {
// => binary_expr
return createBinaryExprChain(head, tail);
}
proc_multiplicative_expr
= head:proc_primary
tail:(__ multiplicative_operator __ proc_primary)* {
// => binary_expr
return createBinaryExprChain(head, tail);
}
proc_join
= lt:var_decl __ op:join_op __ rt:var_decl __ expr:on_clause {
// => { type: 'join'; ltable: var_decl; rtable: var_decl; op: join_op; expr: on_clause; }
return {
type: 'join',
ltable: lt,
rtable: rt,
op: op,
on: expr
};
}
proc_primary
= literal
/ var_decl
/ proc_func_call
/ param
/ LPAREN __ e:proc_additive_expr __ RPAREN {
// => proc_additive_expr & { parentheses: true; }
e.parentheses = true;
return e;
}
/ n:ident_name s:(DOT __ ident_name)? {
// => { type: 'var'; prefix: null; name: number; members: []; quoted: null } | column_ref
if (!s) return {
type: 'var',
name: n,
prefix: null
}
return {
type: 'column_ref',
table: n,
column: s[2]
}
}
proc_func_name
= dt:ident_without_kw_type tail:(__ DOT __ ident_without_kw_type)? {
// => { schema?: ident_without_kw_type, name: ident_without_kw_type }
const result = { name: [dt] }
if (tail !== null) {
result.schema = dt
result.name = [tail[3]]
}
return result
}
proc_func_call
= name:proc_func_name __ LPAREN __ l:proc_primary_list? __ RPAREN {
// => { type: 'function'; name: string; args: null | { type: expr_list; value: proc_primary_list; }}
//compatible with original func_call
return {
type: 'function',
name: name,
args: {
type: 'expr_list',
value: l
}
};
}
proc_primary_list
= head:proc_primary tail:(__ COMMA __ proc_primary)* {
// => proc_primary[]
return createList(head, tail);
}
proc_array
= LBRAKE __ l:proc_primary_list __ RBRAKE {
// => { type: 'array'; value: proc_primary_list }
return { type: 'array', value: l };
}
//begin procedure extension
proc_stmts
= proc_stmt*
proc_stmt
= &{ varList = []; return true; } __ s:(assign_stmt / return_stmt) {
/* export interface proc_stmt_t { type: 'proc'; stmt: assign_stmt | return_stmt; vars: any }
=> AstStatement<proc_stmt_t>
*/
return { type: 'proc', stmt: s, vars: varList }
}