Skip to content

Commit 0660d10

Browse files
committed
parser: fix parsing paths named operator
rel: #635
1 parent be00563 commit 0660d10

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

crates/squawk_parser/src/grammar.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,12 @@ fn opt_name(p: &mut Parser<'_>) -> Option<CompletedMarker> {
15521552
fn path_segment(p: &mut Parser<'_>, kind: SyntaxKind) {
15531553
let m = p.start();
15541554
// TODO: does this need to be flagged?
1555-
if current_operator(p).is_some() {
1555+
// Might want to disallow operators in some paths.
1556+
// Like `create table +()` doesn't make sense.
1557+
if !p.at(OPERATOR_KW) && current_operator(p).is_some() {
1558+
// check for operator kw so we can parse things like:
1559+
// create table operator();
1560+
15561561
// skip
15571562
} else if p.at_ts(COL_LABEL_FIRST) {
15581563
let m = p.start();

crates/squawk_parser/tests/data/ok/create_table.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,7 @@ create table t (
351351
d int storage main,
352352
e int storage default
353353
);
354+
355+
create table operator (
356+
x int
357+
);

crates/squawk_parser/tests/snapshots/tests__create_table_ok.snap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,4 +3379,30 @@ SOURCE_FILE
33793379
WHITESPACE "\n"
33803380
R_PAREN ")"
33813381
SEMICOLON ";"
3382+
WHITESPACE "\n\n"
3383+
CREATE_TABLE
3384+
CREATE_KW "create"
3385+
WHITESPACE " "
3386+
TABLE_KW "table"
3387+
WHITESPACE " "
3388+
PATH
3389+
PATH_SEGMENT
3390+
NAME
3391+
OPERATOR_KW "operator"
3392+
WHITESPACE " "
3393+
TABLE_ARG_LIST
3394+
L_PAREN "("
3395+
WHITESPACE "\n "
3396+
COLUMN
3397+
NAME
3398+
IDENT "x"
3399+
WHITESPACE " "
3400+
PATH_TYPE
3401+
PATH
3402+
PATH_SEGMENT
3403+
NAME_REF
3404+
INT_KW "int"
3405+
WHITESPACE "\n"
3406+
R_PAREN ")"
3407+
SEMICOLON ";"
33823408
WHITESPACE "\n"

0 commit comments

Comments
 (0)