Skip to content

Commit

Permalink
parser+lexer: setup for DETACH
Browse files Browse the repository at this point in the history
  • Loading branch information
xNaCly committed Nov 15, 2024
1 parent bc92b01 commit 0ba9281
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion example/stmt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@ ROLLBACK TO save_point;
ROLLBACK TO SAVEPOINT save_point;
ROLLBACK TRANSACTION;
ROLLBACK TRANSACTION TO save_point;
ROLLBACK TRANSACTION TO SAVEPOINT 'huh';
ROLLBACK TRANSACTION TO SAVEPOINT save_point;
/* ------------------------------------------------------ */

-- https://www.sqlite.org/lang_detach.html
DETACH schema_name;
DETACH DATABASE schema_name;
1 change: 1 addition & 0 deletions src/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ macro_rules! test_group_fail {

#[cfg(test)]
mod should_pass {

test_group_pass_assert! {
booleans,
r#true: "true"=vec![Type::Boolean(true)],
Expand Down
1 change: 0 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ impl<'a> Parser<'a> {
}
err.doc_url = Some("https://www.sqlite.org/syntax/sql-stmt.html");
self.errors.push(err);
self.advance();
}
self.advance(); // we advance either way to keep the parser error resistant
}
Expand Down
11 changes: 11 additions & 0 deletions src/parser/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,29 @@ node!(
Literal,
"holds all literal types, such as strings, numbers, etc.",
);

node!(Explain,"Explain stmt, see: https://www.sqlite.org/lang_explain.html", child: Option<Box<dyn Node>>);

node!(Vacuum,"Vacuum stmt, see: https://www.sqlite.org/lang_vacuum.html", schema_name: Option<Token>, filename: Option<Token>);

node!(
Begin,
"Begin stmt, see: https://www.sqlite.org/syntax/begin-stmt.html",
);

node!(
Commit,
"Commit stmt, see: https://www.sqlite.org/syntax/commit-stmt.html",
);

node!(
Rollback,
"Rollback stmt, see: https://www.sqlite.org/syntax/rollback-stmt.html",
save_point: Option<String>
);

node!(
Detach,
"Rollback stmt, see: https://www.sqlite.org/syntax/rollback-stmt.html",
schema_name: String
);
8 changes: 8 additions & 0 deletions src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ EXPLAIN VACUUM;
rollback_transaction_to_save_point:r"ROLLBACK TRANSACTION TO save_point;"=vec![Type::Keyword(Keyword::ROLLBACK)],
rollback_transaction_to_savepoint_save_point:r"ROLLBACK TRANSACTION TO SAVEPOINT save_point;"=vec![Type::Keyword(Keyword::ROLLBACK)]
}

test_group_pass_assert! {
detach_stmt,

detach:r"DETACH;"=vec![Type::Keyword(Keyword::DETACH)],
detach_schema_name:r"DETACH schema_name;"=vec![Type::Keyword(Keyword::DETACH)],
detach_database_schema_name:r"DETACH DATABASE schema_name;"=vec![Type::Keyword(Keyword::DETACH)]
}
}

#[cfg(test)]
Expand Down

0 comments on commit 0ba9281

Please sign in to comment.