style: format the whole tree with cargo fmt (stock defaults, #35)
One-time, mechanical reformat — no functional changes. The tree was not rustfmt-clean (~1800 hunks across ~100 files); this brings it to stock `cargo fmt` defaults so a `cargo fmt --check` CI gate can follow. Behaviour-preserving: 2509 pass / 0 fail / 1 ignored (unchanged baseline), clippy clean. A .git-blame-ignore-revs entry follows so `git blame` skips this commit.
This commit is contained in:
@@ -141,8 +141,15 @@ static EMPTY_NOMATCH: Node = Node::Choice(&[]);
|
||||
/// suffix keywords. `as` is not listed — the AS-form alias is a
|
||||
/// separate `Choice` branch that fires before the lookahead.
|
||||
const PROJECTION_FOLLOW_SET: &[&str] = &[
|
||||
"from", "where", "group", "order", "having", "limit",
|
||||
"union", "intersect", "except",
|
||||
"from",
|
||||
"where",
|
||||
"group",
|
||||
"order",
|
||||
"having",
|
||||
"limit",
|
||||
"union",
|
||||
"intersect",
|
||||
"except",
|
||||
// `returning` belongs to an enclosing DML statement
|
||||
// (`INSERT … SELECT … RETURNING …`, ADR-0033 §5), never to a
|
||||
// projection item's bare alias — so a no-FROM SELECT row source
|
||||
@@ -158,9 +165,21 @@ const PROJECTION_FOLLOW_SET: &[&str] = &[
|
||||
/// only when `b` has no alias — `on` is not a base-table name a
|
||||
/// learner would type as an alias.
|
||||
const TABLE_SOURCE_FOLLOW_SET: &[&str] = &[
|
||||
"where", "group", "order", "having", "limit",
|
||||
"union", "intersect", "except",
|
||||
"inner", "left", "right", "full", "cross", "join", "on",
|
||||
"where",
|
||||
"group",
|
||||
"order",
|
||||
"having",
|
||||
"limit",
|
||||
"union",
|
||||
"intersect",
|
||||
"except",
|
||||
"inner",
|
||||
"left",
|
||||
"right",
|
||||
"full",
|
||||
"cross",
|
||||
"join",
|
||||
"on",
|
||||
// `returning` belongs to an enclosing DML statement
|
||||
// (`INSERT … SELECT … FROM t RETURNING …`, ADR-0033 §5), so the
|
||||
// SELECT row source must not read it as table `t`'s bare alias.
|
||||
@@ -172,15 +191,9 @@ fn peek_next_ident_lower(source: &str, pos: usize) -> Option<String> {
|
||||
consume_ident(source, p).map(|(s, e)| source[s..e].to_ascii_lowercase())
|
||||
}
|
||||
|
||||
fn projection_bare_alias_factory(
|
||||
_: &WalkContext,
|
||||
source: &str,
|
||||
pos: usize,
|
||||
) -> Node {
|
||||
fn projection_bare_alias_factory(_: &WalkContext, source: &str, pos: usize) -> Node {
|
||||
match peek_next_ident_lower(source, pos) {
|
||||
Some(word)
|
||||
if PROJECTION_FOLLOW_SET.iter().any(|k| *k == word) =>
|
||||
{
|
||||
Some(word) if PROJECTION_FOLLOW_SET.iter().any(|k| *k == word) => {
|
||||
Node::Subgrammar(&EMPTY_NOMATCH)
|
||||
}
|
||||
Some(_) => PROJECTION_BARE_ALIAS_IDENT,
|
||||
@@ -188,15 +201,9 @@ fn projection_bare_alias_factory(
|
||||
}
|
||||
}
|
||||
|
||||
fn table_source_bare_alias_factory(
|
||||
_: &WalkContext,
|
||||
source: &str,
|
||||
pos: usize,
|
||||
) -> Node {
|
||||
fn table_source_bare_alias_factory(_: &WalkContext, source: &str, pos: usize) -> Node {
|
||||
match peek_next_ident_lower(source, pos) {
|
||||
Some(word)
|
||||
if TABLE_SOURCE_FOLLOW_SET.iter().any(|k| *k == word) =>
|
||||
{
|
||||
Some(word) if TABLE_SOURCE_FOLLOW_SET.iter().any(|k| *k == word) => {
|
||||
Node::Subgrammar(&EMPTY_NOMATCH)
|
||||
}
|
||||
Some(_) => TABLE_SOURCE_BARE_ALIAS_IDENT,
|
||||
@@ -237,14 +244,12 @@ const TABLE_SOURCE_BARE_ALIAS_IDENT: Node = Node::Ident {
|
||||
writes_column: false,
|
||||
writes_user_listed_column: false,
|
||||
writes_table_alias: true,
|
||||
writes_cte_name: false,
|
||||
writes_projection_alias: false,
|
||||
writes_cte_name: false,
|
||||
writes_projection_alias: false,
|
||||
};
|
||||
|
||||
static PROJECTION_AS_ALIAS_NODES: &[Node] = &[
|
||||
Node::Word(Word::keyword("as")),
|
||||
PROJECTION_BARE_ALIAS_IDENT,
|
||||
];
|
||||
static PROJECTION_AS_ALIAS_NODES: &[Node] =
|
||||
&[Node::Word(Word::keyword("as")), PROJECTION_BARE_ALIAS_IDENT];
|
||||
static PROJECTION_AS_ALIAS: Node = Node::Seq(PROJECTION_AS_ALIAS_NODES);
|
||||
|
||||
static TABLE_SOURCE_AS_ALIAS_NODES: &[Node] = &[
|
||||
@@ -258,17 +263,14 @@ static PROJECTION_ALIAS_CHOICES: &[Node] = &[
|
||||
Node::Lookahead(projection_bare_alias_factory),
|
||||
];
|
||||
static PROJECTION_ALIAS_CHOICE: Node = Node::Choice(PROJECTION_ALIAS_CHOICES);
|
||||
static PROJECTION_ALIAS_OPTIONAL: Node =
|
||||
Node::Optional(&PROJECTION_ALIAS_CHOICE);
|
||||
static PROJECTION_ALIAS_OPTIONAL: Node = Node::Optional(&PROJECTION_ALIAS_CHOICE);
|
||||
|
||||
static TABLE_SOURCE_ALIAS_CHOICES: &[Node] = &[
|
||||
Node::Subgrammar(&TABLE_SOURCE_AS_ALIAS),
|
||||
Node::Lookahead(table_source_bare_alias_factory),
|
||||
];
|
||||
static TABLE_SOURCE_ALIAS_CHOICE: Node =
|
||||
Node::Choice(TABLE_SOURCE_ALIAS_CHOICES);
|
||||
static TABLE_SOURCE_ALIAS_OPTIONAL: Node =
|
||||
Node::Optional(&TABLE_SOURCE_ALIAS_CHOICE);
|
||||
static TABLE_SOURCE_ALIAS_CHOICE: Node = Node::Choice(TABLE_SOURCE_ALIAS_CHOICES);
|
||||
static TABLE_SOURCE_ALIAS_OPTIONAL: Node = Node::Optional(&TABLE_SOURCE_ALIAS_CHOICE);
|
||||
|
||||
// =================================================================
|
||||
// Projection item
|
||||
@@ -282,16 +284,13 @@ const QUALIFIED_STAR_QUALIFIER: Node = Node::Ident {
|
||||
writes_table: false,
|
||||
writes_column: false,
|
||||
writes_user_listed_column: false,
|
||||
writes_table_alias: false,
|
||||
writes_cte_name: false,
|
||||
writes_projection_alias: false,
|
||||
writes_table_alias: false,
|
||||
writes_cte_name: false,
|
||||
writes_projection_alias: false,
|
||||
};
|
||||
|
||||
static QUALIFIED_STAR_NODES: &[Node] = &[
|
||||
QUALIFIED_STAR_QUALIFIER,
|
||||
Node::Punct('.'),
|
||||
Node::Punct('*'),
|
||||
];
|
||||
static QUALIFIED_STAR_NODES: &[Node] =
|
||||
&[QUALIFIED_STAR_QUALIFIER, Node::Punct('.'), Node::Punct('*')];
|
||||
static QUALIFIED_STAR: Node = Node::Seq(QUALIFIED_STAR_NODES);
|
||||
|
||||
static PROJECTION_EXPR_ITEM_NODES: &[Node] = &[
|
||||
@@ -310,11 +309,7 @@ static PROJECTION_EXPR_ITEM: Node = Node::Seq(PROJECTION_EXPR_ITEM_NODES);
|
||||
/// ambiguity between `t.*` and `sql_expr` (which can match a
|
||||
/// bare `t`), since the walker's `Choice` doesn't backtrack on
|
||||
/// a committed match.
|
||||
fn projection_item_factory(
|
||||
_: &WalkContext,
|
||||
source: &str,
|
||||
pos: usize,
|
||||
) -> Node {
|
||||
fn projection_item_factory(_: &WalkContext, source: &str, pos: usize) -> Node {
|
||||
let p = skip_whitespace(source, pos);
|
||||
let bytes = source.as_bytes();
|
||||
if bytes.get(p) == Some(&b'*') {
|
||||
@@ -363,8 +358,7 @@ static DISTINCT_OR_ALL_CHOICES: &[Node] = &[
|
||||
Node::Word(Word::keyword("all")),
|
||||
];
|
||||
static DISTINCT_OR_ALL_CHOICE: Node = Node::Choice(DISTINCT_OR_ALL_CHOICES);
|
||||
static DISTINCT_OR_ALL_OPTIONAL: Node =
|
||||
Node::Optional(&DISTINCT_OR_ALL_CHOICE);
|
||||
static DISTINCT_OR_ALL_OPTIONAL: Node = Node::Optional(&DISTINCT_OR_ALL_CHOICE);
|
||||
|
||||
// =================================================================
|
||||
// Table source (FROM / JOIN target)
|
||||
@@ -379,8 +373,8 @@ const TABLE_NAME_IDENT: Node = Node::Ident {
|
||||
writes_column: false,
|
||||
writes_user_listed_column: false,
|
||||
writes_table_alias: false,
|
||||
writes_cte_name: false,
|
||||
writes_projection_alias: false,
|
||||
writes_cte_name: false,
|
||||
writes_projection_alias: false,
|
||||
};
|
||||
|
||||
static TABLE_SOURCE_NODES: &[Node] = &[
|
||||
@@ -395,8 +389,7 @@ static TABLE_SOURCE: Node = Node::Seq(TABLE_SOURCE_NODES);
|
||||
|
||||
const JOIN_WORD: Node = Node::Word(Word::keyword("join"));
|
||||
const ON_WORD: Node = Node::Word(Word::keyword("on"));
|
||||
static OUTER_OPTIONAL: Node =
|
||||
Node::Optional(&Node::Word(Word::keyword("outer")));
|
||||
static OUTER_OPTIONAL: Node = Node::Optional(&Node::Word(Word::keyword("outer")));
|
||||
|
||||
// `INNER JOIN` and bare `JOIN` are split into two Choice
|
||||
// branches so each branch has a distinct leading keyword
|
||||
@@ -585,8 +578,7 @@ static SET_OP_CHOICES: &[Node] = &[
|
||||
];
|
||||
static SET_OP: Node = Node::Choice(SET_OP_CHOICES);
|
||||
|
||||
static SET_OP_TAIL_NODES: &[Node] =
|
||||
&[Node::Subgrammar(&SET_OP), Node::Subgrammar(&SELECT_CORE)];
|
||||
static SET_OP_TAIL_NODES: &[Node] = &[Node::Subgrammar(&SET_OP), Node::Subgrammar(&SELECT_CORE)];
|
||||
static SET_OP_TAIL: Node = Node::Seq(SET_OP_TAIL_NODES);
|
||||
|
||||
static PLAIN_COMPOUND_NODES: &[Node] = &[
|
||||
@@ -619,8 +611,7 @@ static WITH_PREFIXED_COMPOUND_NODES: &[Node] = &[
|
||||
Node::Subgrammar(&WITH_CLAUSE),
|
||||
Node::Subgrammar(&PLAIN_COMPOUND),
|
||||
];
|
||||
static WITH_PREFIXED_COMPOUND: Node =
|
||||
Node::Seq(WITH_PREFIXED_COMPOUND_NODES);
|
||||
static WITH_PREFIXED_COMPOUND: Node = Node::Seq(WITH_PREFIXED_COMPOUND_NODES);
|
||||
|
||||
static COMPOUND_CHOICES: &[Node] = &[
|
||||
Node::Subgrammar(&WITH_PREFIXED_COMPOUND),
|
||||
@@ -659,9 +650,9 @@ const CTE_COLUMN_IDENT: Node = Node::Ident {
|
||||
writes_table: false,
|
||||
writes_column: false,
|
||||
writes_user_listed_column: false,
|
||||
writes_table_alias: false,
|
||||
writes_cte_name: false,
|
||||
writes_projection_alias: false,
|
||||
writes_table_alias: false,
|
||||
writes_cte_name: false,
|
||||
writes_projection_alias: false,
|
||||
};
|
||||
|
||||
static CTE_COLUMN_LIST_NODES: &[Node] = &[
|
||||
@@ -674,18 +665,13 @@ static CTE_COLUMN_LIST_NODES: &[Node] = &[
|
||||
RPAREN,
|
||||
];
|
||||
static CTE_COLUMN_LIST_SEQ: Node = Node::Seq(CTE_COLUMN_LIST_NODES);
|
||||
static CTE_COLUMN_LIST_OPTIONAL: Node =
|
||||
Node::Optional(&CTE_COLUMN_LIST_SEQ);
|
||||
static CTE_COLUMN_LIST_OPTIONAL: Node = Node::Optional(&CTE_COLUMN_LIST_SEQ);
|
||||
|
||||
// CTE body recursion pushes a fresh lexical scope frame (ADR-
|
||||
// 0032 §4 / §10.2). Subqueries in `sql_expr.rs` do the same;
|
||||
// the top-level statement's own COMPOUND embedding does not
|
||||
// (it shares the implicit bottom frame).
|
||||
static CTE_BODY_NODES: &[Node] = &[
|
||||
LPAREN,
|
||||
Node::ScopedSubgrammar(&SQL_SELECT_COMPOUND),
|
||||
RPAREN,
|
||||
];
|
||||
static CTE_BODY_NODES: &[Node] = &[LPAREN, Node::ScopedSubgrammar(&SQL_SELECT_COMPOUND), RPAREN];
|
||||
static CTE_BODY: Node = Node::Seq(CTE_BODY_NODES);
|
||||
|
||||
static CTE_DEF_NODES: &[Node] = &[
|
||||
@@ -807,9 +793,7 @@ mod tests {
|
||||
let mut path = MatchedPath::new();
|
||||
let mut per_byte = Vec::new();
|
||||
match walk_node(input, 0, fragment, &mut ctx, &mut path, &mut per_byte) {
|
||||
NodeWalkResult::Matched { end, .. } => {
|
||||
input[end..].trim().is_empty()
|
||||
}
|
||||
NodeWalkResult::Matched { end, .. } => input[end..].trim().is_empty(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -819,10 +803,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn good(input: &str) {
|
||||
assert!(
|
||||
walks(input),
|
||||
"{input:?} should be a valid SELECT statement"
|
||||
);
|
||||
assert!(walks(input), "{input:?} should be a valid SELECT statement");
|
||||
}
|
||||
|
||||
fn bad(input: &str) {
|
||||
@@ -1051,16 +1032,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn set_op_chain() {
|
||||
good(
|
||||
"select a from t union select b from u intersect select c from v",
|
||||
);
|
||||
good("select a from t union select b from u intersect select c from v");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_op_with_outer_order_by_and_limit() {
|
||||
good(
|
||||
"select a from t union select b from u order by a limit 10",
|
||||
);
|
||||
good("select a from t union select b from u order by a limit 10");
|
||||
}
|
||||
|
||||
// ----- ORDER BY / LIMIT / OFFSET -----
|
||||
@@ -1126,16 +1103,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn recursive_cte() {
|
||||
good(
|
||||
"with recursive r as (select 1 union all select 2) select * from r",
|
||||
);
|
||||
good("with recursive r as (select 1 union all select 2) select * from r");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_ctes() {
|
||||
good(
|
||||
"with a as (select 1), b as (select 2) select * from a union select * from b",
|
||||
);
|
||||
good("with a as (select 1), b as (select 2) select * from a union select * from b");
|
||||
}
|
||||
|
||||
// ----- subquery shapes (recursion through SQL_SELECT_COMPOUND) -----
|
||||
@@ -1147,9 +1120,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn nested_cte_body_with_union() {
|
||||
good(
|
||||
"with x as (select 1 union select 2) select * from x",
|
||||
);
|
||||
good("with x as (select 1 union select 2) select * from x");
|
||||
}
|
||||
|
||||
// ----- case insensitivity / spacing -----
|
||||
@@ -1363,9 +1334,7 @@ mod tests {
|
||||
#[test]
|
||||
fn in_subquery_in_where_clause() {
|
||||
good("select * from t where id in (select user_id from orders)");
|
||||
good(
|
||||
"select * from customers where id not in (select customer_id from blocklist)",
|
||||
);
|
||||
good("select * from customers where id not in (select customer_id from blocklist)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1378,9 +1347,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn nested_subqueries() {
|
||||
good(
|
||||
"select * from t where x in (select y from u where y in (select z from v))",
|
||||
);
|
||||
good("select * from t where x in (select y from u where y in (select z from v))");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1393,8 +1360,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn cte_body_references_qualified_columns() {
|
||||
good(
|
||||
"with x as (select t.name, t.age from t) select x.name from x",
|
||||
);
|
||||
good("with x as (select t.name, t.age from t) select x.name from x");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user