Skip to content

Commit 664f794

Browse files
authored
Merge branch 'master' into types/export-ast-node-types
2 parents ad078aa + 93df74a commit 664f794

26 files changed

Lines changed: 310 additions & 47 deletions

pegjs/athena.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ set_list
14961496
* 'col1 = (col2 > 3)'
14971497
*/
14981498
set_item
1499-
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:additive_expr {
1499+
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:expr {
15001500
return { column: c, value: v, table: tbl && tbl[0] };
15011501
}
15021502
/ tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ KW_VALUES __ LPAREN __ v:column_ref __ RPAREN {

pegjs/bigquery.pegjs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@
195195
columnList.clear()
196196
columns.forEach(col => columnList.add(col))
197197
}
198+
199+
function getSurroundFromLiteralType(literal) {
200+
switch (literal.type) {
201+
case 'double_quote_string':
202+
return '"'
203+
case 'single_quote_string':
204+
return "'"
205+
case 'backticks_quote_string':
206+
return '`'
207+
default:
208+
return ''
209+
}
210+
}
198211

199212
const cmpPrefixMap = {
200213
'+': true,
@@ -552,7 +565,7 @@ set_list
552565
* 'col1 = (col2 > 3)'
553566
*/
554567
set_item
555-
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:additive_expr {
568+
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:expr {
556569
return { column: c, value: v, table: tbl && tbl[0] };
557570
}
558571
/ tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ KW_VALUES __ LPAREN __ v:column_ref __ RPAREN {
@@ -1926,21 +1939,23 @@ join_op
19261939
/ k:KW_INNER? __ KW_JOIN { return k ? `${k[0].toUpperCase()} JOIN` : 'JOIN'; }
19271940

19281941
table_name
1929-
= db:ident_without_kw schema:(__ DOT __ ident_without_kw) tail:(__ DOT __ ident_without_kw) {
1930-
const obj = { db: null, table: db };
1942+
= db:ident_without_kw_type schema:(__ DOT __ ident_without_kw_type) tail:(__ DOT __ ident_without_kw_type) {
1943+
const obj = { db: null, table: db.value };
19311944
if (tail !== null) {
1932-
obj.db = db;
1933-
obj.catalog = db;
1934-
obj.schema = schema[3];
1935-
obj.table = tail[3];
1945+
obj.db = db.value;
1946+
obj.catalog = db.value;
1947+
obj.schema = schema[3].value;
1948+
obj.table = tail[3].value;
1949+
obj.surround = { table: getSurroundFromLiteralType(tail[3]), db: getSurroundFromLiteralType(db), schema: getSurroundFromLiteralType(schema[3]) };
19361950
}
19371951
return obj;
19381952
}
1939-
/ dt:ident_without_kw tail:(__ DOT __ ident_without_kw)? {
1940-
const obj = { db: null, table: dt };
1953+
/ dt:ident_without_kw_type tail:(__ DOT __ ident_without_kw_type)? {
1954+
const obj = { db: null, table: dt.value, surround: { table: getSurroundFromLiteralType(dt) } };
19411955
if (tail !== null) {
1942-
obj.db = dt;
1943-
obj.table = tail[3];
1956+
obj.db = dt.value;
1957+
obj.table = tail[3].value;
1958+
obj.surround = { table: getSurroundFromLiteralType(tail[3]), db: getSurroundFromLiteralType(dt) };
19441959
}
19451960
return obj;
19461961
}

pegjs/db2.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ set_list
14521452
* 'col1 = (col2 > 3)'
14531453
*/
14541454
set_item
1455-
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:additive_expr {
1455+
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:expr {
14561456
return { column: c, value: v, table: tbl && tbl[0] };
14571457
}
14581458
/ tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ KW_VALUES __ LPAREN __ v:column_ref __ RPAREN {

pegjs/flinksql.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,7 @@ set_list
21772177
* 'col1 = (col2 > 3)'
21782178
*/
21792179
set_item
2180-
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:additive_expr {
2180+
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:expr {
21812181
// => { column: ident; value: additive_expr; table?: ident;}
21822182
return { column: c, value: v, table: tbl && tbl[0] };
21832183
}

pegjs/hive.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ set_list
14371437
* 'col1 = (col2 > 3)'
14381438
*/
14391439
set_item
1440-
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:additive_expr {
1440+
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:expr {
14411441
return { column: c, value: v, table: tbl && tbl[0] };
14421442
}
14431443
/ tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ KW_VALUES __ LPAREN __ v:column_ref __ RPAREN {

pegjs/mariadb.pegjs

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ cmd_stmt
252252
/ grant_stmt
253253
/ explain_stmt
254254
/ transaction_stmt
255+
/ load_data_stmt
255256

256257
create_stmt
257258
= create_table_stmt
@@ -1808,6 +1809,70 @@ transaction_stmt
18081809
}
18091810
}
18101811

1812+
load_data_field
1813+
= k:('FIELDS'i / 'COLUMNS'i) __ t:('TERMINATED'i __ 'BY'i __ ident_without_kw_type)? __ en:(('OPTIONALLY'i)? __ 'ENCLOSED'i __ 'BY'i __ ident_without_kw_type)? __ es:('ESCAPED'i __ 'BY'i __ ident_without_kw_type)? {
1814+
if (t) t[4].prefix = 'TERMINATED BY'
1815+
if (en) en[6].prefix = `${en[0] && en[0].toUpperCase() === 'OPTIONALLY' ? 'OPTIONALLY ' : ''}ENCLOSED BY`
1816+
if (es) es[4].prefix = 'ESCAPED BY'
1817+
return {
1818+
keyword: k,
1819+
terminated: t && t[4],
1820+
enclosed: en && en[6],
1821+
escaped: es && es[4]
1822+
}
1823+
}
1824+
1825+
load_data_line_starting
1826+
= k:('STARTING'i / 'TERMINATED'i) __ 'BY'i __ s:ident_without_kw_type {
1827+
s.prefix = `${k.toUpperCase()} BY`
1828+
return {
1829+
type: k.toLowerCase(),
1830+
[k.toLowerCase()]: s
1831+
}
1832+
}
1833+
load_data_line
1834+
= k:'LINES'i __ s:load_data_line_starting? __ t:load_data_line_starting? {
1835+
if (s && t && s.type === t.type) throw new Error('LINES cannot be specified twice')
1836+
if (s) Reflect.deleteProperty(s, 'type')
1837+
if (t) Reflect.deleteProperty(t, 'type')
1838+
return {
1839+
keyword: k,
1840+
...(s || {}),
1841+
...(t || {})
1842+
}
1843+
}
1844+
1845+
load_data_stmt
1846+
= 'LOAD'i __ 'DATA'i __ lc:('LOW_PRIORITY'i / 'CONCURRENT'i)? __ lo:('LOCAL'i)? __
1847+
'INFILE'i __ file:ident_without_kw_type __ ri:replace_insert? __
1848+
'INTO'i __ 'TABLE'i __ table:table_name __
1849+
pa:insert_partition? __
1850+
cs:(create_option_character_set_kw __ ident_without_kw_type)? __
1851+
fields:load_data_field? __
1852+
lines:load_data_line? __
1853+
ig:(KW_IGNORE __ literal_numeric __ ('LINES'i / 'ROWS'i))? __
1854+
co:column_clause? __
1855+
set:(KW_SET __ set_list)? {
1856+
return {
1857+
type: 'load_data',
1858+
mode: lc,
1859+
local: lo,
1860+
file: file,
1861+
replace_ignore: ri,
1862+
table: table,
1863+
partition: pa,
1864+
character_set: cs,
1865+
fields: fields,
1866+
lines: lines,
1867+
ignore: ig && {
1868+
count: ig[2],
1869+
suffix: ig[4]
1870+
},
1871+
column: co,
1872+
set: set && set[2]
1873+
}
1874+
}
1875+
18111876
lock_type
18121877
= "READ"i __ s:("LOCAL"i)? {
18131878
return {
@@ -2544,7 +2609,7 @@ set_list
25442609
* 'col1 = (col2 > 3)'
25452610
*/
25462611
set_item
2547-
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:additive_expr {
2612+
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:expr {
25482613
return { column: c, value: v, table: tbl && tbl[0] };
25492614
}
25502615
/ tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ KW_VALUES __ LPAREN __ v:column_ref __ RPAREN {
@@ -3092,7 +3157,7 @@ double_quoted_ident
30923157
}
30933158

30943159
single_quoted_ident
3095-
= "'" chars:[^']+ "'" {
3160+
= "'" chars:[^']* "'" {
30963161
return {
30973162
type: 'single_quote_string',
30983163
value: chars.join('')

pegjs/mysql.pegjs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ cmd_stmt
447447
/ grant_stmt
448448
/ explain_stmt
449449
/ transaction_stmt
450+
/ load_data_stmt
450451

451452
create_stmt
452453
= create_table_stmt
@@ -2091,6 +2092,69 @@ transaction_stmt
20912092
}
20922093
}
20932094

2095+
load_data_field
2096+
= k:('FIELDS'i / 'COLUMNS'i) __ t:('TERMINATED'i __ 'BY'i __ ident_without_kw_type)? __ en:(('OPTIONALLY'i)? __ 'ENCLOSED'i __ 'BY'i __ ident_without_kw_type)? __ es:('ESCAPED'i __ 'BY'i __ ident_without_kw_type)? {
2097+
if (t) t[4].prefix = 'TERMINATED BY'
2098+
if (en) en[6].prefix = `${en[0] && en[0].toUpperCase() === 'OPTIONALLY' ? 'OPTIONALLY ' : ''}ENCLOSED BY`
2099+
if (es) es[4].prefix = 'ESCAPED BY'
2100+
return {
2101+
keyword: k,
2102+
terminated: t && t[4],
2103+
enclosed: en && en[6],
2104+
escaped: es && es[4]
2105+
}
2106+
}
2107+
2108+
load_data_line_starting
2109+
= k:('STARTING'i / 'TERMINATED'i) __ 'BY'i __ s:ident_without_kw_type {
2110+
s.prefix = `${k.toUpperCase()} BY`
2111+
return {
2112+
type: k.toLowerCase(),
2113+
[k.toLowerCase()]: s
2114+
}
2115+
}
2116+
load_data_line
2117+
= k:'LINES'i __ s:load_data_line_starting? __ t:load_data_line_starting? {
2118+
if (s && t && s.type === t.type) throw new Error('LINES cannot be specified twice')
2119+
if (s) Reflect.deleteProperty(s, 'type')
2120+
if (t) Reflect.deleteProperty(t, 'type')
2121+
return {
2122+
keyword: k,
2123+
...(s || {}),
2124+
...(t || {})
2125+
}
2126+
}
2127+
2128+
load_data_stmt
2129+
= 'LOAD'i __ 'DATA'i __ lc:('LOW_PRIORITY'i / 'CONCURRENT'i)? __ lo:('LOCAL'i)? __
2130+
'INFILE'i __ file:ident_without_kw_type __ ri:replace_insert? __
2131+
'INTO'i __ 'TABLE'i __ table:table_name __
2132+
pa:insert_partition? __
2133+
cs:(create_option_character_set_kw __ ident_without_kw_type)? __
2134+
fields:load_data_field? __
2135+
lines:load_data_line? __
2136+
ig:(KW_IGNORE __ literal_numeric __ ('LINES'i / 'ROWS'i))? __
2137+
co:column_clause? __
2138+
set:(KW_SET __ set_list)? {
2139+
return {
2140+
type: 'load_data',
2141+
mode: lc,
2142+
local: lo,
2143+
file: file,
2144+
replace_ignore: ri,
2145+
table: table,
2146+
partition: pa,
2147+
character_set: cs,
2148+
fields: fields,
2149+
lines: lines,
2150+
ignore: ig && {
2151+
count: ig[2],
2152+
suffix: ig[4]
2153+
},
2154+
column: co,
2155+
set: set && set[2]
2156+
}
2157+
}
20942158
priv_type_table
20952159
= p:(KW_ALL / KW_ALTER / KW_CREATE __ 'VIEW'i / KW_CREATE / KW_DELETE / KW_DROP / 'GRANT'i __ 'OPTION'i / KW_INDEX / KW_INSERT / KW_REFERENCES / KW_SELECT / KW_SHOW __ KW_VIEW / KW_TRIGGER / KW_UPDATE) {
20962160
return {
@@ -2814,7 +2878,7 @@ set_list
28142878
* 'col1 = (col2 > 3)'
28152879
*/
28162880
set_item
2817-
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:additive_expr {
2881+
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:expr {
28182882
return { column: c, value: v, table: tbl && tbl[0] };
28192883
}
28202884
/ tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ KW_VALUES __ LPAREN __ v:column_ref __ RPAREN {
@@ -3372,7 +3436,7 @@ double_quoted_ident
33723436
}
33733437

33743438
single_quoted_ident
3375-
= "'" chars:[^']+ "'" {
3439+
= "'" chars:[^']* "'" {
33763440
return {
33773441
type: 'single_quote_string',
33783442
value: chars.join('')

pegjs/noql.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,7 +3404,7 @@ set_list
34043404
* 'col1 = (col2 > 3)'
34053405
*/
34063406
set_item
3407-
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:additive_expr {
3407+
= tbl:(ident __ DOT)? __ c:column_without_kw __ '=' __ v:expr {
34083408
// => { column: ident; value: additive_expr; table?: ident;}
34093409
return { column: c, value: v, table: tbl && tbl[0] };
34103410
}
@@ -3955,9 +3955,9 @@ jsonb_expr
39553955

39563956
string_constants_escape
39573957
= 'E'i"'" __ n:single_char* __ "'" {
3958-
// => { type: 'origin'; value: string; }
3958+
// => { type: 'default'; value: string; }
39593959
return {
3960-
type: 'origin',
3960+
type: 'default',
39613961
value: `E'${n.join('')}'`
39623962
}
39633963
}

pegjs/postgresql.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,7 +4095,7 @@ set_list
40954095
* 'col1 = (col2 > 3)'
40964096
*/
40974097
set_item
4098-
= c:column_ref_array_index __ '=' __ v:additive_expr {
4098+
= c:column_ref_array_index __ '=' __ v:expr {
40994099
// => { column: ident; value: additive_expr; table?: ident;}
41004100
return { ...c, value: v };
41014101
}
@@ -4651,9 +4651,9 @@ jsonb_expr
46514651

46524652
string_constants_escape
46534653
= 'E'i"'" __ n:single_char* __ "'" {
4654-
// => { type: 'origin'; value: string; }
4654+
// => { type: 'default'; value: string; }
46554655
return {
4656-
type: 'origin',
4656+
type: 'default',
46574657
value: `E'${n.join('')}'`
46584658
}
46594659
}

pegjs/redshift.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,7 +3432,7 @@ set_list
34323432
* 'col1 = (col2 > 3)'
34333433
*/
34343434
set_item
3435-
= tbl:(ident __ DOT)? __ c:column_without_kw_type __ '=' __ v:additive_expr {
3435+
= tbl:(ident __ DOT)? __ c:column_without_kw_type __ '=' __ v:expr {
34363436
// => { column: ident; value: additive_expr; table?: ident;}
34373437
return { column: { expr: c }, value: v, table: tbl && tbl[0] };
34383438
}
@@ -3986,9 +3986,9 @@ jsonb_expr
39863986

39873987
string_constants_escape
39883988
= 'E'i"'" __ n:single_char* __ "'" {
3989-
// => { type: 'origin'; value: string; }
3989+
// => { type: 'default'; value: string; }
39903990
return {
3991-
type: 'origin',
3991+
type: 'default',
39923992
value: `E'${n.join('')}'`
39933993
}
39943994
}

0 commit comments

Comments
 (0)