Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/squawk_parser/src/generated/syntax_kind.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 24 additions & 7 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ fn literal(p: &mut Parser<'_>) -> Option<CompletedMarker> {
return None;
}
let m = p.start();
if p.eat(BYTE_STRING) {
if p.eat(UESCAPE_KW) {
p.eat(STRING);
}
}
// E021-03 string continuation syntax
// If two string literals are next to each other, and don't have a comment
// between them, then they are automatically combined.
if p.eat(STRING) {
else if p.eat(STRING) {
while !p.at(EOF) && p.eat(STRING) {}
} else {
p.bump_any();
Expand Down Expand Up @@ -362,10 +367,6 @@ fn substring_fn(p: &mut Parser<'_>) -> CompletedMarker {
if expr(p).is_none() {
p.error("expected an expression");
}
p.expect(ESCAPE_KW);
if expr(p).is_none() {
p.error("expected an expression");
}
}
_ if p.eat(COMMA) => {
// normal function call
Expand Down Expand Up @@ -1462,7 +1463,13 @@ fn opt_name(p: &mut Parser<'_>) -> Option<CompletedMarker> {
return None;
}
let m = p.start();
p.bump_any();
if p.eat(IDENT) {
if p.eat(UESCAPE_KW) {
p.expect(STRING);
}
} else {
p.bump_any();
}
Some(m.complete(p, NAME))
}

Expand Down Expand Up @@ -2156,10 +2163,14 @@ fn current_op(p: &Parser<'_>, r: &Restrictions) -> (u8, SyntaxKind, Associativit
PLUS if p.next_not_joined_op(0) => (8, PLUS, Left), // symbol
// overlaps
OVERLAPS_KW => (7, OVERLAPS_KW, Left),
// escape
ESCAPE_KW => (7, ESCAPE_KW, Left),
// like
LIKE_KW => (6, LIKE_KW, Left),
// ilike
ILIKE_KW => (6, ILIKE_KW, Left),
// not similar to
NOT_KW if !r.not_disabled && p.at(NOT_SIMILAR_TO) => (6, NOT_SIMILAR_TO, Left),
// not like
NOT_KW if !r.not_disabled && p.at(NOT_LIKE) => (6, NOT_LIKE, Left),
// not ilike
Expand Down Expand Up @@ -13727,7 +13738,13 @@ fn alter_table_action(p: &mut Parser<'_>) -> Option<SyntaxKind> {
fn opt_col_label(p: &mut Parser<'_>) -> bool {
if p.at_ts(COL_LABEL_FIRST) {
let m = p.start();
p.bump_any();
if p.eat(IDENT) {
if p.eat(UESCAPE_KW) {
p.expect(STRING);
}
} else {
p.bump_any();
}
m.complete(p, NAME);
true
} else {
Expand Down
14 changes: 14 additions & 0 deletions crates/squawk_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ impl<'t> Parser<'t> {
m.complete(self, SyntaxKind::IS_JSON_SCALAR);
return true;
}
SyntaxKind::NOT_SIMILAR_TO => {
let m = self.start();
self.bump(SyntaxKind::NOT_KW);
self.bump(SyntaxKind::SIMILAR_KW);
self.bump(SyntaxKind::TO_KW);
m.complete(self, SyntaxKind::NOT_SIMILAR_TO);
return true;
}
SyntaxKind::IS_NOT_DISTINCT_FROM => {
let m = self.start();
self.bump(SyntaxKind::IS_KW);
Expand Down Expand Up @@ -767,6 +775,12 @@ impl<'t> Parser<'t> {
}
return false;
}
SyntaxKind::NOT_SIMILAR_TO => self.at_composite3(
n,
SyntaxKind::NOT_KW,
SyntaxKind::SIMILAR_KW,
SyntaxKind::TO_KW,
),
// similar to
SyntaxKind::SIMILAR_TO => self.at_composite2(
n,
Expand Down
14 changes: 13 additions & 1 deletion crates/squawk_parser/tests/data/ok/select_operators.sql
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,17 @@ select U&'\0061\0308bc' is not nfd normalized;
-- pattern_matching
-- like
select 'foo' like 'bar';

select 'foo' like 'bar' escape '#';
-- not like
select 'foo' not like 'bar';
select 'foo' not like 'bar' escape '#';

-- ilike
select 'foo' ilike 'bar';
select 'foo' ilike 'bar' escape '#';
-- not ilike
select 'foo' not ilike 'bar';
select 'foo' not ilike 'bar' escape '#';

-- ~~
select 'a' ~~ 'b';
Expand All @@ -192,6 +200,10 @@ select 'a' !~~ 'b';

-- similar to
select 'abc' similar to 'abc';
select 'abc' similar to 'abc' escape '#';

select 'abc' not similar to 'abc';
select 'abc' not similar to 'abc' escape '#';

-- posix regex
-- string matches regex case sensitive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SELECT 'tricky' AS U&"\" UESCAPE '!';

SELECT U&'wrong: \061';
SELECT U&'wrong: \+0061';
SELECT U&'wrong: +0061' UESCAPE +;
-- SELECT U&'wrong: +0061' UESCAPE +;
SELECT U&'wrong: +0061' UESCAPE '+';

SELECT U&'wrong: \db99';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,4 @@
source: crates/squawk_parser/tests/tests.rs
input_file: crates/squawk_parser/tests/data/regression_suite/strings.sql
---
ERROR@536: missing comma
ERROR@563: missing comma
ERROR@625: missing comma
ERROR@667: missing comma
ERROR@763: missing comma
ERROR@765: expected an expression, found SEMICOLON
ERROR@798: missing comma
ERROR@1460: missing comma
ERROR@1487: missing comma
ERROR@1523: missing comma
ERROR@1565: missing comma
ERROR@1661: missing comma
ERROR@6313: missing comma
ERROR@6369: missing comma
ERROR@6621: missing comma
ERROR@6717: missing comma
ERROR@6775: missing comma
ERROR@17083: missing comma
ERROR@17136: missing comma
ERROR@17188: missing comma
ERROR@17242: missing comma
ERROR@17354: missing comma
ERROR@17403: missing comma
ERROR@17455: missing comma
ERROR@17510: missing comma
ERROR@17562: missing comma
ERROR@17617: missing comma
ERROR@17675: missing comma
ERROR@17735: missing comma
ERROR@17787: missing comma
ERROR@17841: missing comma
ERROR@17894: missing comma
ERROR@17949: missing comma
ERROR@18003: missing comma
ERROR@18060: missing comma
ERROR@18112: missing comma
ERROR@18167: missing comma
ERROR@18230: missing comma
ERROR@18302: missing comma
ERROR@18406: missing comma
ERROR@18459: missing comma
ERROR@18511: missing comma
ERROR@18565: missing comma
ERROR@18616: missing comma
ERROR@18669: missing comma
ERROR@18721: missing comma
ERROR@18775: missing comma
ERROR@18827: missing comma
ERROR@18882: missing comma

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: crates/squawk_parser/tests/tests.rs
expression: "out.join(\"\\n\")"
---
tests/snapshots/tests__regression_strings.snap:49

15 changes: 8 additions & 7 deletions crates/squawk_parser/tests/snapshots/tests__select_funcs_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,14 @@ SOURCE_FILE
WHITESPACE " "
SIMILAR_KW "similar"
WHITESPACE " "
NAME_REF
IDENT "b"
WHITESPACE " "
ESCAPE_KW "escape"
WHITESPACE " "
NAME_REF
IDENT "c"
BIN_EXPR
NAME_REF
IDENT "b"
WHITESPACE " "
ESCAPE_KW "escape"
WHITESPACE " "
NAME_REF
IDENT "c"
R_PAREN ")"
SEMICOLON ";"
WHITESPACE "\n\n"
Expand Down
Loading
Loading