Skip to content

Commit ff451be

Browse files
committed
support tail comma
1 parent 0476c6d commit ff451be

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

pegjs/bigquery.pegjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ column_clause
346346
type: k.toLowerCase(),
347347
}
348348
}
349-
/ head: (KW_ALL / (STAR !ident_start) / STAR) tail:(__ COMMA __ column_list_item)* {
349+
/ head: (KW_ALL / (STAR !ident_start) / STAR) tail:(__ COMMA __ column_list_item)* __ COMMA? {
350350
columnList.add('select::null::(.*)');
351351
if (tail && tail.length > 0) {
352352
head[0] = {
@@ -361,7 +361,9 @@ column_clause
361361
}
362362
return head[0];
363363
}
364-
/ columns_list
364+
/ c:columns_list __ COMMA? {
365+
return c
366+
}
365367

366368
columns_list
367369
= head:column_list_item tail:(__ COMMA __ column_list_item)* {

test/bigquery.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ describe('BigQuery', () => {
285285
"SELECT * FROM UNNEST (ARRAY<STRING>['a', 'b', 'c', 'd', 'e']) AS letter ORDER BY letter ASC LIMIT 2 OFFSET 1"
286286
]
287287
},
288+
{
289+
title: 'tail comma',
290+
sql: [
291+
`SELECT season as season,
292+
academic_year as academic_year,
293+
FROM source`,
294+
'SELECT season AS season, academic_year AS academic_year FROM source'
295+
]
296+
}
288297
]
289298

290299
SQL_LIST.forEach(sqlInfo => {

0 commit comments

Comments
 (0)