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
3 changes: 1 addition & 2 deletions crates/squawk_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ impl Cursor<'_> {
'"' if allows_double => {
self.bump();
let terminated = self.double_quoted_string();
let kind = mk_kind(terminated);
TokenKind::Literal { kind }
TokenKind::QuotedIdent { terminated }
}
_ => self.ident_or_unknown_prefix(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ expression: "lex(r#\"\nU&\"d\\0061t\\+000061\"\n\nU&\"\\0441\\043B\\043E\\043D\"
---
[
"\n" @ Whitespace,
"U&\"d\\0061t\\+000061\"" @ Literal { kind: UnicodeEscStr { terminated: true } },
"U&\"d\\0061t\\+000061\"" @ QuotedIdent { terminated: true },
"\n\n" @ Whitespace,
"U&\"\\0441\\043B\\043E\\043D\"" @ Literal { kind: UnicodeEscStr { terminated: true } },
"U&\"\\0441\\043B\\043E\\043D\"" @ QuotedIdent { terminated: true },
"\n\n" @ Whitespace,
"u&'\\0441\\043B'" @ Literal { kind: UnicodeEscStr { terminated: true } },
"\n\n" @ Whitespace,
"U&\"d!0061t!+000061\"" @ Literal { kind: UnicodeEscStr { terminated: true } },
"U&\"d!0061t!+000061\"" @ QuotedIdent { terminated: true },
" " @ Whitespace,
"UESCAPE" @ Ident,
" " @ Whitespace,
Expand Down
19 changes: 14 additions & 5 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,8 @@ fn name_ref_(p: &mut Parser<'_>) -> Option<CompletedMarker> {
NAME_REF
};
let cm = m.complete(p, if p.at(STRING) { kind } else { NAME_REF });
// A path followed by a string is a type cast so we insert a CAST_EXPR

// A type name followed by a string is a type cast so we insert a CAST_EXPR
// preceding it to wrap the previously parsed data.
// e.g., `select numeric '12312'`
if opt_string_literal(p).is_some() {
Expand Down Expand Up @@ -2808,7 +2809,6 @@ fn data_source(p: &mut Parser<'_>) {
opt_alias(p);
}
_ if p.at_ts(FROM_ITEM_KEYWORDS_FIRST) => from_item_name(p),

_ => {
p.error("expected table reference");
}
Expand Down Expand Up @@ -11308,7 +11308,7 @@ fn vacuum(p: &mut Parser<'_>) -> CompletedMarker {
// table_name [ ( column_name [, ...] ) ]
fn opt_relation_list(p: &mut Parser<'_>) {
while !p.at(EOF) {
if opt_path_name_ref(p).is_none() {
if opt_relation_name(p).is_none() {
break;
}
opt_column_list(p);
Expand Down Expand Up @@ -12990,6 +12990,12 @@ const NON_RESERVED_WORD: TokenSet = TokenSet::new(&[IDENT])
.union(TYPE_FUNC_NAME_KEYWORDS);

fn relation_name(p: &mut Parser<'_>) {
if opt_relation_name(p).is_none() {
p.error("expected relation name");
}
}

fn opt_relation_name(p: &mut Parser<'_>) -> Option<CompletedMarker> {
let m = p.start();
if p.eat(ONLY_KW) {
let trailing_paren = p.eat(L_PAREN);
Expand All @@ -12999,10 +13005,13 @@ fn relation_name(p: &mut Parser<'_>) {
p.expect(R_PAREN);
}
} else {
path_name_ref(p);
if opt_path_name_ref(p).is_none() {
m.abandon(p);
return None;
};
p.eat(STAR);
}
m.complete(p, RELATION_NAME);
Some(m.complete(p, RELATION_NAME))
}

// ALTER TABLE [ IF EXISTS ] [ ONLY ] name [ * ]
Expand Down
16 changes: 8 additions & 8 deletions crates/squawk_parser/tests/data/regression_suite/strings.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ SELECT 'first line'
' - third line'
AS "Three lines to one";

-- illegal string continuation syntax
SELECT 'first line'
' - next line' /* this comment is not allowed here */
' - third line'
AS "Illegal comment within continuation";
-- -- illegal string continuation syntax
-- SELECT 'first line'
-- ' - next line' /* this comment is not allowed here */
-- ' - third line'
-- AS "Illegal comment within continuation";

-- Unicode escapes
SET standard_conforming_strings TO on;
Expand Down Expand Up @@ -812,16 +812,16 @@ select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\'

set standard_conforming_strings = off;

select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
-- select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;

set escape_string_warning = off;
set standard_conforming_strings = on;

select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
-- select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;

set standard_conforming_strings = off;

select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
-- select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;

reset standard_conforming_strings;

Expand Down
70 changes: 35 additions & 35 deletions crates/squawk_parser/tests/data/regression_suite/triggers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,24 @@ UPDATE some_t SET some_col = TRUE;
DROP TABLE some_t;

-- bogus cases
CREATE TRIGGER error_upd_and_col BEFORE UPDATE OR UPDATE OF a ON main_table
FOR EACH ROW EXECUTE PROCEDURE trigger_func('error_upd_and_col');
CREATE TRIGGER error_upd_a_a BEFORE UPDATE OF a, a ON main_table
FOR EACH ROW EXECUTE PROCEDURE trigger_func('error_upd_a_a');
CREATE TRIGGER error_ins_a BEFORE INSERT OF a ON main_table
FOR EACH ROW EXECUTE PROCEDURE trigger_func('error_ins_a');
CREATE TRIGGER error_ins_when BEFORE INSERT OR UPDATE ON main_table
FOR EACH ROW WHEN (OLD.a <> NEW.a)
EXECUTE PROCEDURE trigger_func('error_ins_old');
CREATE TRIGGER error_del_when BEFORE DELETE OR UPDATE ON main_table
FOR EACH ROW WHEN (OLD.a <> NEW.a)
EXECUTE PROCEDURE trigger_func('error_del_new');
CREATE TRIGGER error_del_when BEFORE INSERT OR UPDATE ON main_table
FOR EACH ROW WHEN (NEW.tableoid <> 0)
EXECUTE PROCEDURE trigger_func('error_when_sys_column');
CREATE TRIGGER error_stmt_when BEFORE UPDATE OF a ON main_table
FOR EACH STATEMENT WHEN (OLD.* IS DISTINCT FROM NEW.*)
EXECUTE PROCEDURE trigger_func('error_stmt_when');
-- CREATE TRIGGER error_upd_and_col BEFORE UPDATE OR UPDATE OF a ON main_table
-- FOR EACH ROW EXECUTE PROCEDURE trigger_func('error_upd_and_col');
-- CREATE TRIGGER error_upd_a_a BEFORE UPDATE OF a, a ON main_table
-- FOR EACH ROW EXECUTE PROCEDURE trigger_func('error_upd_a_a');
-- CREATE TRIGGER error_ins_a BEFORE INSERT OF a ON main_table
-- FOR EACH ROW EXECUTE PROCEDURE trigger_func('error_ins_a');
-- CREATE TRIGGER error_ins_when BEFORE INSERT OR UPDATE ON main_table
-- FOR EACH ROW WHEN (OLD.a <> NEW.a)
-- EXECUTE PROCEDURE trigger_func('error_ins_old');
-- CREATE TRIGGER error_del_when BEFORE DELETE OR UPDATE ON main_table
-- FOR EACH ROW WHEN (OLD.a <> NEW.a)
-- EXECUTE PROCEDURE trigger_func('error_del_new');
-- CREATE TRIGGER error_del_when BEFORE INSERT OR UPDATE ON main_table
-- FOR EACH ROW WHEN (NEW.tableoid <> 0)
-- EXECUTE PROCEDURE trigger_func('error_when_sys_column');
-- CREATE TRIGGER error_stmt_when BEFORE UPDATE OF a ON main_table
-- FOR EACH STATEMENT WHEN (OLD.* IS DISTINCT FROM NEW.*)
-- EXECUTE PROCEDURE trigger_func('error_stmt_when');

-- check dependency restrictions
ALTER TABLE main_table DROP COLUMN b;
Expand Down Expand Up @@ -1335,12 +1335,12 @@ delete from parted_stmt_trig;

-- insert via copy on the parent
copy parted_stmt_trig(a) from stdin;
1
2
-- 1
-- 2

-- insert via copy on the first partition
copy parted_stmt_trig1(a) from stdin;
1
-- 1

-- Disabling a trigger in the parent table should disable children triggers too
alter table parted_stmt_trig disable trigger trig_ins_after_parent;
Expand Down Expand Up @@ -1882,9 +1882,9 @@ delete from child3;

-- copy into parent sees parent-format tuples
copy parent (a, b) from stdin;
AAA 42
BBB 42
CCC 42
-- AAA 42
-- BBB 42
-- CCC 42

-- DML affecting parent sees tuples collected from children even if
-- there is no transition table trigger on the children
Expand All @@ -1902,9 +1902,9 @@ delete from parent;
-- copy into parent sees tuples collected from children even if there
-- is no transition-table trigger on the children
copy parent (a, b) from stdin;
AAA 42
BBB 42
CCC 42
-- AAA 42
-- BBB 42
-- CCC 42

-- insert into parent with a before trigger on a child tuple before
-- insertion, and we capture the newly modified row in parent format
Expand All @@ -1926,9 +1926,9 @@ insert into parent values ('AAA', 42), ('BBB', 42), ('CCC', 66);

-- copy, parent trigger sees post-modification parent-format tuple
copy parent (a, b) from stdin;
AAA 42
BBB 42
CCC 234
-- AAA 42
-- BBB 42
-- CCC 234

drop table child1, child2, child3, parent;
drop function intercept_insert();
Expand Down Expand Up @@ -2091,15 +2091,15 @@ delete from child3;
-- copy into parent sees parent-format tuples (no rerouting, so these
-- are really inserted into the parent)
copy parent (a, b) from stdin;
AAA 42
BBB 42
CCC 42
-- AAA 42
-- BBB 42
-- CCC 42

-- same behavior for copy if there is an index (interesting because rows are
-- captured by a different code path in copyfrom.c if there are indexes)
create index on parent(b);
copy parent (a, b) from stdin;
DDD 42
-- DDD 42

-- DML affecting parent sees tuples collected from children even if
-- there is no transition table trigger on the children
Expand Down Expand Up @@ -2628,7 +2628,7 @@ select tgrelid::regclass, tgname,
(select tgname from pg_trigger tr where tr.oid = pg_trigger.tgparentid) parent_tgname
from pg_trigger where tgrelid in (select relid from pg_partition_tree('grandparent'))
order by tgname, tgrelid::regclass::text COLLATE "C";
alter trigger a on only grandparent rename to b; -- ONLY not supported
-- alter trigger a on only grandparent rename to b; -- ONLY not supported
alter trigger b on middle rename to c; -- can't rename trigger on partition
create trigger c after insert on middle
for each row execute procedure f();
Expand Down
12 changes: 6 additions & 6 deletions crates/squawk_parser/tests/data/regression_suite/tsearch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,12 @@ SELECT ts_headline('english',
--Rewrite sub system

CREATE TABLE test_tsquery (txtkeyword TEXT, txtsample TEXT);
'New York' new <-> york | big <-> apple | nyc
Moscow moskva | moscow
'Sanct Peter' Peterburg | peter | 'Sanct Peterburg'
foo & bar & qq foo & (bar | qq) & city
1 & (2 <-> 3) 2 <-> 4
5 <-> 6 5 <-> 7
-- 'New York' new <-> york | big <-> apple | nyc
-- Moscow moskva | moscow
-- 'Sanct Peter' Peterburg | peter | 'Sanct Peterburg'
-- foo & bar & qq foo & (bar | qq) & city
-- 1 & (2 <-> 3) 2 <-> 4
-- 5 <-> 6 5 <-> 7

ALTER TABLE test_tsquery ADD COLUMN keyword tsquery;
UPDATE test_tsquery SET keyword = to_tsquery('english', txtkeyword);
Expand Down
48 changes: 26 additions & 22 deletions crates/squawk_parser/tests/snapshots/tests__analyze_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,28 @@ SOURCE_FILE
WHITESPACE " "
VERBOSE_KW "verbose"
WHITESPACE " "
PATH
RELATION_NAME
PATH
PATH
PATH_SEGMENT
NAME_REF
IDENT "foo"
DOT "."
PATH_SEGMENT
NAME_REF
IDENT "foo"
DOT "."
PATH_SEGMENT
NAME_REF
IDENT "bar"
IDENT "bar"
COMMA ","
WHITESPACE " "
PATH
RELATION_NAME
PATH
PATH
PATH_SEGMENT
NAME_REF
IDENT "foo"
DOT "."
PATH_SEGMENT
NAME_REF
IDENT "foo"
DOT "."
PATH_SEGMENT
NAME_REF
IDENT "bar"
IDENT "bar"
COLUMN_LIST
L_PAREN "("
COLUMN
Expand All @@ -58,10 +60,11 @@ SOURCE_FILE
R_PAREN ")"
COMMA ","
WHITESPACE " "
PATH
PATH_SEGMENT
NAME_REF
IDENT "foo"
RELATION_NAME
PATH
PATH_SEGMENT
NAME_REF
IDENT "foo"
SEMICOLON ";"
WHITESPACE "\n\n"
COMMENT "-- full_parens"
Expand All @@ -85,15 +88,16 @@ SOURCE_FILE
INT_NUMBER "10"
R_PAREN ")"
WHITESPACE " "
PATH
RELATION_NAME
PATH
PATH
PATH_SEGMENT
NAME_REF
IDENT "foo"
DOT "."
PATH_SEGMENT
NAME_REF
IDENT "foo"
DOT "."
PATH_SEGMENT
NAME_REF
IDENT "bar"
IDENT "bar"
COLUMN_LIST
L_PAREN "("
COLUMN
Expand Down
13 changes: 7 additions & 6 deletions crates/squawk_parser/tests/snapshots/tests__misc_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1819,15 +1819,16 @@ SOURCE_FILE
WHITESPACE " "
ANALYZE_KW "ANALYZE"
WHITESPACE " "
PATH
RELATION_NAME
PATH
PATH
PATH_SEGMENT
NAME_REF
IDENT "partman_test"
DOT "."
PATH_SEGMENT
NAME_REF
IDENT "partman_test"
DOT "."
PATH_SEGMENT
NAME_REF
IDENT "time_taptest_table"
IDENT "time_taptest_table"
SEMICOLON ";"
WHITESPACE "\n\n"
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_parser/tests/tests.rs
input_file: crates/squawk_parser/tests/data/regression_suite/errors.sql
---
ERROR@948: expected path name
ERROR@948: expected relation name
ERROR@1074: expected path name
ERROR@2188: expected path name
ERROR@2219: expected path name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ ERROR@41835: expected command, found WHEN_KW
ERROR@41840: expected command, found MATCHED_KW
ERROR@41848: expected command, found THEN_KW
ERROR@41860: expected FROM_KW
ERROR@41860: expected path name
ERROR@41860: expected relation name
ERROR@41953: expected ON_KW
ERROR@41960: expected WHEN_KW
ERROR@41960: expected MATCHED, or NOT MATCHED
Expand Down
Loading
Loading