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
38 changes: 20 additions & 18 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5615,6 +5615,22 @@ fn string_literal(p: &mut Parser<'_>) {

const BOOL_FIRST: TokenSet = TokenSet::new(&[TRUE_KW, FALSE_KW, OFF_KW, ON_KW, INT_NUMBER]);

const UTILITY_OPTION_ARG_FIRST: TokenSet = BOOL_FIRST
.union(NUMERIC_FIRST)
.union(STRING_FIRST)
.union(NON_RESERVED_WORD);

fn opt_utility_option_arg(p: &mut Parser<'_>) -> bool {
if opt_bool_literal(p) || opt_numeric_literal(p).is_some() || opt_string_literal(p).is_some() {
return true;
}
if p.at_ts(NON_RESERVED_WORD) {
p.bump_any();
return true;
}
false
}

fn opt_bool_literal(p: &mut Parser<'_>) -> bool {
let m = p.start();
// TOOD: add validation to check for `1` or `0` inside the INT_NUMBER
Expand Down Expand Up @@ -11178,15 +11194,7 @@ fn opt_explain_option(p: &mut Parser<'_>) -> bool {

fn opt_explain_option_value(p: &mut Parser<'_>) -> Option<CompletedMarker> {
let m = p.start();
// boolean, { NONE | TEXT | BINARY }, or { TEXT | XML | JSON | YAML }
if opt_bool_literal(p)
|| p.eat(NONE_KW)
|| p.eat(TEXT_KW)
|| p.eat(BINARY_KW)
|| p.eat(XML_KW)
|| p.eat(JSON_KW)
|| opt_ident(p)
{
if opt_utility_option_arg(p) {
return Some(m.complete(p, EXPLAIN_OPTION_VALUE));
}
m.abandon(p);
Expand Down Expand Up @@ -12214,7 +12222,7 @@ fn opt_reindex_option(p: &mut Parser<'_>) -> bool {
let parsed = match p.current() {
CONCURRENTLY_KW | VERBOSE_KW => {
p.bump_any();
opt_bool_literal(p);
opt_utility_option_arg(p);
true
}
TABLESPACE_KW => {
Expand Down Expand Up @@ -12800,9 +12808,7 @@ fn opt_table_and_columns(p: &mut Parser<'_>) -> bool {

const VACUUM_OPTION_FIRST: TokenSet = NON_RESERVED_WORD
.union(TokenSet::new(&[ANALYZE_KW, ANALYSE_KW, FORMAT_KW, ON_KW]))
.union(NUMERIC_FIRST)
.union(STRING_FIRST)
.union(BOOL_FIRST);
.union(UTILITY_OPTION_ARG_FIRST);

// where option can be one of:
// FORMAT format_name
Expand Down Expand Up @@ -12835,11 +12841,7 @@ fn opt_vacuum_option(p: &mut Parser<'_>) -> Option<CompletedMarker> {
// utility_option_arg
fn opt_vacuum_option_value(p: &mut Parser<'_>) -> Option<CompletedMarker> {
let m = p.start();
if p.at_ts(NON_RESERVED_WORD) || p.at(ON_KW) {
col_label(p);
return Some(m.complete(p, VACUUM_OPTION_VALUE));
}
if opt_numeric_literal(p).is_some() || opt_string_literal(p).is_some() || opt_bool_literal(p) {
if opt_utility_option_arg(p) {
return Some(m.complete(p, VACUUM_OPTION_VALUE));
}
m.abandon(p);
Expand Down
1 change: 1 addition & 0 deletions crates/squawk_parser/tests/data/ok/analyze.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ analyze verbose foo.bar, foo.bar(a, b, c), foo;

-- full_parens
analyze (verbose false, skip_locked, buffer_usage_limit 10) foo.bar(a, b, c);
analyze (verbose no, skip_locked 'on') foo;

5 changes: 4 additions & 1 deletion crates/squawk_parser/tests/data/ok/explain.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ explain (
format text,
format xml,
format json,
format yaml
format yaml,
verbose 'true',
costs yes,
settings no
)
select 1;

Expand Down
1 change: 1 addition & 0 deletions crates/squawk_parser/tests/data/ok/reindex.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ REINDEX TABLE CONCURRENTLY my_broken_table;

-- complete_syntax
reindex (concurrently true, tablespace fooo, verbose false) database concurrently foo;
reindex (concurrently 'off', verbose yes) table foo;

reindex system foo;

Expand Down
5 changes: 4 additions & 1 deletion crates/squawk_parser/tests/data/ok/vacuum.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ VACUUM (
only_database_stats true,
only_database_stats false,
buffer_usage_limit 10,
buffer_usage_limit '10 TB'
buffer_usage_limit '10 TB',
full no,
verbose 'off',
analyze yes
) t1;

-- pre_pg_9_syntax
Expand Down
27 changes: 27 additions & 0 deletions crates/squawk_parser/tests/snapshots/tests__analyze_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,31 @@ SOURCE_FILE
IDENT "c"
R_PAREN ")"
SEMICOLON ";"
WHITESPACE "\n"
ANALYZE
ANALYZE_KW "analyze"
WHITESPACE " "
OPTION_ITEM_LIST
L_PAREN "("
OPTION_ITEM
VERBOSE_KW "verbose"
WHITESPACE " "
NO_KW "no"
COMMA ","
WHITESPACE " "
OPTION_ITEM
IDENT "skip_locked"
WHITESPACE " "
LITERAL
STRING "'on'"
R_PAREN ")"
WHITESPACE " "
TABLE_AND_COLUMNS_LIST
TABLE_AND_COLUMNS
RELATION_NAME
PATH
PATH_SEGMENT
NAME_REF
IDENT "foo"
SEMICOLON ";"
WHITESPACE "\n\n"
25 changes: 25 additions & 0 deletions crates/squawk_parser/tests/snapshots/tests__explain_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,31 @@ SOURCE_FILE
WHITESPACE " "
EXPLAIN_OPTION_VALUE
IDENT "yaml"
COMMA ","
WHITESPACE "\n "
EXPLAIN_OPTION
NAME
VERBOSE_KW "verbose"
WHITESPACE " "
EXPLAIN_OPTION_VALUE
LITERAL
STRING "'true'"
COMMA ","
WHITESPACE "\n "
EXPLAIN_OPTION
NAME
IDENT "costs"
WHITESPACE " "
EXPLAIN_OPTION_VALUE
YES_KW "yes"
COMMA ","
WHITESPACE "\n "
EXPLAIN_OPTION
NAME
IDENT "settings"
WHITESPACE " "
EXPLAIN_OPTION_VALUE
NO_KW "no"
WHITESPACE "\n"
R_PAREN ")"
WHITESPACE "\n"
Expand Down
7 changes: 1 addition & 6 deletions crates/squawk_parser/tests/snapshots/tests__reindex_err.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ SOURCE_FILE
L_PAREN "("
REINDEX_OPTION
CONCURRENTLY_KW "concurrently"
WHITESPACE " "
REINDEX_OPTION
WHITESPACE " "
VERBOSE_KW "verbose"
WHITESPACE " "
REINDEX_OPTION
Expand All @@ -32,10 +31,6 @@ SOURCE_FILE
SEMICOLON ";"
WHITESPACE "\n"
---
error[syntax-error]: expected COMMA
╭▸
2 │ reindex (concurrently verbose tablespace t) index i;
╰╴ ━
error[syntax-error]: expected COMMA
╭▸
2 │ reindex (concurrently verbose tablespace t) index i;
Expand Down
26 changes: 26 additions & 0 deletions crates/squawk_parser/tests/snapshots/tests__reindex_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ SOURCE_FILE
NAME_REF
IDENT "foo"
SEMICOLON ";"
WHITESPACE "\n"
REINDEX
REINDEX_KW "reindex"
WHITESPACE " "
REINDEX_OPTION_LIST
L_PAREN "("
REINDEX_OPTION
CONCURRENTLY_KW "concurrently"
WHITESPACE " "
LITERAL
STRING "'off'"
COMMA ","
WHITESPACE " "
REINDEX_OPTION
VERBOSE_KW "verbose"
WHITESPACE " "
YES_KW "yes"
R_PAREN ")"
WHITESPACE " "
TABLE_KW "table"
WHITESPACE " "
PATH
PATH_SEGMENT
NAME_REF
IDENT "foo"
SEMICOLON ";"
WHITESPACE "\n\n"
REINDEX
REINDEX_KW "reindex"
Expand Down
32 changes: 28 additions & 4 deletions crates/squawk_parser/tests/snapshots/tests__vacuum_ok.snap
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,15 @@ SOURCE_FILE
IDENT "index_cleanup"
WHITESPACE " "
VACUUM_OPTION_VALUE
NAME
IDENT "auto"
IDENT "auto"
COMMA ","
WHITESPACE "\n "
VACUUM_OPTION
NAME
IDENT "index_cleanup"
WHITESPACE " "
VACUUM_OPTION_VALUE
NAME
LITERAL
ON_KW "on"
COMMA ","
WHITESPACE "\n "
Expand All @@ -158,7 +157,7 @@ SOURCE_FILE
IDENT "index_cleanup"
WHITESPACE " "
VACUUM_OPTION_VALUE
NAME
LITERAL
OFF_KW "off"
COMMA ","
WHITESPACE "\n "
Expand Down Expand Up @@ -279,6 +278,31 @@ SOURCE_FILE
VACUUM_OPTION_VALUE
LITERAL
STRING "'10 TB'"
COMMA ","
WHITESPACE "\n "
VACUUM_OPTION
NAME
FULL_KW "full"
WHITESPACE " "
VACUUM_OPTION_VALUE
NO_KW "no"
COMMA ","
WHITESPACE "\n "
VACUUM_OPTION
NAME
VERBOSE_KW "verbose"
WHITESPACE " "
VACUUM_OPTION_VALUE
LITERAL
STRING "'off'"
COMMA ","
WHITESPACE "\n "
VACUUM_OPTION
NAME
ANALYZE_KW "analyze"
WHITESPACE " "
VACUUM_OPTION_VALUE
YES_KW "yes"
WHITESPACE "\n"
R_PAREN ")"
WHITESPACE " "
Expand Down
32 changes: 32 additions & 0 deletions crates/squawk_syntax/src/ast/generated/nodes.rs

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

Loading
Loading