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
640 changes: 351 additions & 289 deletions coverage/syntax/baseline.json

Large diffs are not rendered by default.

503 changes: 503 additions & 0 deletions coverage/syntax/reviews/ddl.toml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions coverage/syntax/reviews/dml.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,20 @@ note = "Read in full against the documentation page, the obligations, the cases

[review.definitions]
"sf.dml.merge" = "7199cb1b8a75bbd9be1b5b6185d63a4e1c3e2ac6d98dec6995cb9c56df84e900"

[[review]]
id = "dml-007"
family = "dml"
parser_tree = "e4c5015c6be45602859aa5366c26b7b470e2cc9c"
reviewed_utc = "2026-11-13T14:09:29Z"
verdict = "approved"
forms = [
"sf.dml.delete",
]
note = "Read in full against the documentation page, the obligations, the cases and the parse trees of the parser at 1fdf28bc5; every scored case agrees with its Snowflake receipt."

[review.fingerprints]
"sf.dml.delete" = "a908891254313f3bedbd6a61840fdffd3d496f43694dc75d79f7f2c3d588aff1"

[review.definitions]
"sf.dml.delete" = "259d0f1581f4aa78ea444d97b9682bdc89bc74a18edc0cb279162c2921c68ac6"
17 changes: 17 additions & 0 deletions coverage/syntax/reviews/scripting.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,20 @@ note = "Read in full against the documentation page, the obligations, the cases

[review.definitions]
"sf.scripting.declare.declare" = "d1a2db11ffc5ddcaad2d03f47571b6ecfced8545b9d56406ac984f1ffed6a459"

[[review]]
id = "scripting-006"
family = "scripting"
parser_tree = "e4c5015c6be45602859aa5366c26b7b470e2cc9c"
reviewed_utc = "2026-11-13T14:09:29Z"
verdict = "approved"
forms = [
"sf.scripting.let.let-resultset-default",
]
note = "Read in full against the documentation page, the obligations, the cases and the parse trees of the parser at 1fdf28bc5; every scored case agrees with its Snowflake receipt."

[review.fingerprints]
"sf.scripting.let.let-resultset-default" = "d60c314284e3f16e671d18a638f7eebe3c445c4eba1050281ca8a405bd6bb463"

[review.definitions]
"sf.scripting.let.let-resultset-default" = "aa4a4bc9c009cc62520630531fb61a3b770ae8f619bbff1bb414fbc020bc204a"
392 changes: 392 additions & 0 deletions coverage/syntax/reviews/security-admin.toml

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions coverage/syntax/reviews/utility.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,23 @@ note = "Re-approved after stage paths became stage references: of the 104 cases

[review.definitions]
"sf.utility.execute-job-service" = "f0d2489a4725394b38014d90c6c4832d295b389f79a5b19581c111ddc4237c64"

[[review]]
id = "utility-008"
family = "utility"
parser_tree = "e4c5015c6be45602859aa5366c26b7b470e2cc9c"
reviewed_utc = "2026-11-13T14:09:29Z"
verdict = "approved"
forms = [
"sf.utility.execute-immediate.immediate-2",
"sf.utility.execute-immediate.immediate.syntax",
]
note = "Read in full against the documentation page, the obligations, the cases and the parse trees of the parser at 1fdf28bc5; every scored case agrees with its Snowflake receipt."

[review.fingerprints]
"sf.utility.execute-immediate.immediate-2" = "32d01d688de37a84656c934f935eada4567fbaf781036162a0cb9d3808129e01"
"sf.utility.execute-immediate.immediate.syntax" = "394fd9bca3f35d694991b0a478cb303186d8693c589d25532ad388c6a7734069"

[review.definitions]
"sf.utility.execute-immediate.immediate-2" = "3416aeb205558b4247bfd90128e0c794bcc6107c0b5f687312ae897706f926be"
"sf.utility.execute-immediate.immediate.syntax" = "473a9693f23b0879c4dcf7de1358a00cc8180d19977ee8adb151e3dcce2fcab1"
Original file line number Diff line number Diff line change
Expand Up @@ -6,91 +6,129 @@ use crate::parser::constants::SNOWFLAKE_DEFINE_OPAQUE_KINDS;
use crate::parser::constants::SNOWFLAKE_RESERVED_KEYWORDS;
use crate::parser::models::Parser;
use sqlquack_syntax::expressions::names::models::Identifier;
use sqlquack_syntax::expressions::operators::models::BinaryOp;
use sqlquack_syntax::expressions::operators::models::Call;
use sqlquack_syntax::expressions::operators::models::NamedArgSeparator;
use sqlquack_syntax::expressions::operators::models::NamedArgument;
use sqlquack_syntax::expressions::operators::models::Parameter;
use sqlquack_syntax::expressions::operators::models::ParameterStyle;
use sqlquack_syntax::expressions::schema_objects::models::ExecuteObject;
use sqlquack_syntax::expressions::schema_objects::models::ObjectProperty;
use sqlquack_syntax::expressions::statements::models::CreateTask;
use sqlquack_syntax::expressions::statements::models::ExecuteImmediate;
use sqlquack_syntax::expressions::statements::models::ExecuteUsingPolicyContext;
use sqlquack_syntax::expressions::statements::models::Raw;
use sqlquack_syntax::expressions::tree::models::Expression;
use sqlquack_syntax::expressions::types::models::Tuple;
use sqlquack_syntax::tokens::models::SourceSpan;
use sqlquack_syntax::tokens::models::TokenType;
use sqlquack_syntax::tokens::types::Result;
use sqlquack_syntax::traversal::types::ExpressionWalk;

impl Parser {
/// In Snowflake, refuse an EXECUTE IMMEDIATE, read after EXECUTE, that is neither `IMMEDIATE <source> [ USING ( <variable> [ , ... ] ) ]` nor `IMMEDIATE FROM <location> [ USING ( <name> => <value> [ , ... ] ) ] [ DRY_RUN = { TRUE | FALSE } ]`, and return the index of the token that ends it, a `)` closing an enclosing assignment included; the cursor ends where it started.
pub(crate) fn check_execute_immediate(&mut self) -> Result<Option<usize>> {
if !self.applies_snowflake_context_rules() {
return Ok(None);
/// Snowflake's `IMMEDIATE <source> [ USING ( <variable> [ , ... ] ) ]` or `IMMEDIATE FROM <location> [ USING ( <name> => <value> [ , ... ] ) ] [ DRY_RUN = { TRUE | FALSE } ]`, read after EXECUTE up to the statement end or a `)` closing an enclosing assignment.
pub(crate) fn parse_execute_immediate(&mut self) -> Result<Expression> {
self.skip();
let from = self.match_token(TokenType::From);
let source = match from {
true if !self.check(TokenType::String) && !self.is_stage_path() => {
return Err(self.parse_error("Expected a stage path or a string"));
}
true => self.parse_location_value()?,
false => self.parse_execute_source()?,
};
let mut using: Vec<Expression> = Vec::new();
if self.match_token(TokenType::Using) {
self.expect_token(TokenType::LParen)?;
loop {
using.push(match from {
true => self.parse_execute_argument()?,
false => self.parse_expression()?,
});
if !self.match_token(TokenType::Comma) {
break;
}
}
self.expect_token(TokenType::RParen)?;
}
let start = self.current;
let checked = self.check_execute_immediate_parts();
self.current = start;
checked
let mut dry_run = None;
if from && self.match_identifier("DRY_RUN") {
self.expect_token(TokenType::Eq)?;
dry_run = Some(match () {
() if self.match_token(TokenType::True) => true,
() if self.match_token(TokenType::False) => false,
() => return Err(self.parse_error("Expected TRUE or FALSE")),
});
}
if !self.is_statement_end_at(0) && !self.check(TokenType::RParen) {
return Err(self.parse_error("Expected the end of EXECUTE IMMEDIATE"));
}
Ok(Expression::ExecuteImmediate(Box::new(ExecuteImmediate {
source,
from,
using,
dry_run,
})))
}

/// The text EXECUTE IMMEDIATE runs: operands joined by `||`, left to right.
fn parse_execute_source(&mut self) -> Result<Expression> {
let mut source = self.parse_execute_operand()?;
while self.match_token(TokenType::DPipe) {
let right = self.parse_execute_operand()?;
source = Expression::Concat(Box::new(BinaryOp::new(source, right)));
}
Ok(source)
}

/// One part of the text EXECUTE IMMEDIATE runs: a string, a `$session` or `:bound` variable, or a variable's name.
fn check_execute_operand(&mut self) -> Result<()> {
if self.check(TokenType::Dollar) || self.check(TokenType::Colon) {
fn parse_execute_operand(&mut self) -> Result<Expression> {
let style = match self.peek().token_type {
TokenType::Dollar => Some(ParameterStyle::Dollar),
TokenType::Colon => Some(ParameterStyle::Colon),
_ => None,
};
if let Some(style) = style {
let end = self.peek().span.end;
self.skip();
if !self.is_identifier_token() || self.peek().span.start != end {
return Err(self.parse_error("Expected a variable's name"));
}
self.skip();
return Ok(());
return Ok(Expression::Parameter(Box::new(Parameter {
name: Some(self.advance_text()?),
index: None,
style,
quoted: false,
string_quoted: false,
expression: None,
span: SourceSpan::default(),
})));
}
if self.check(TokenType::String)
|| self.check(TokenType::DollarString)
|| (self.is_identifier_token()
&& !self.is_snowflake_reserved_keyword()
&& !self.peek_text().starts_with('@'))
{
self.skip();
return Ok(());
let start = self.current;
let operand = self.parse_primary()?;
if self.current == start + 1 {
return Ok(operand);
}
}
Err(self.parse_error("Expected the statement to execute"))
}

fn check_execute_immediate_parts(&mut self) -> Result<Option<usize>> {
self.skip();
let from = self.match_token(TokenType::From);
if from {
if !self.check(TokenType::String) && !self.is_stage_path() {
return Err(self.parse_error("Expected a stage path or a string"));
}
self.parse_location_value()?;
} else {
self.check_execute_operand()?;
while self.match_token(TokenType::DPipe) {
self.check_execute_operand()?;
}
}
if self.match_token(TokenType::Using) {
self.expect_token(TokenType::LParen)?;
loop {
if from {
self.expect_identifier_or_keyword()?;
self.expect_token(TokenType::FArrow)?;
}
self.parse_expression()?;
if !self.match_token(TokenType::Comma) {
break;
}
}
self.expect_token(TokenType::RParen)?;
}
if from && self.match_identifier("DRY_RUN") {
self.expect_token(TokenType::Eq)?;
if !self.match_token(TokenType::True) && !self.match_token(TokenType::False) {
return Err(self.parse_error("Expected TRUE or FALSE"));
}
}
match self.is_statement_end_at(0) || self.check(TokenType::RParen) {
true => Ok(Some(self.current)),
false => Err(self.parse_error("Expected the end of EXECUTE IMMEDIATE")),
}
/// `<name> => <value>`, one argument of a file EXECUTE IMMEDIATE FROM runs.
fn parse_execute_argument(&mut self) -> Result<Expression> {
let token = self.peek().span;
let name = self.expect_identifier_or_keyword()?;
self.expect_token(TokenType::FArrow)?;
Ok(Expression::NamedArgument(Box::new(NamedArgument {
name: Identifier::new(name).with_span(token),
value: self.parse_expression()?,
separator: NamedArgSeparator::DArrow,
})))
}

/// In Snowflake, refuse an unquoted reserved keyword in any dotted part of a COMMENT ON name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ impl Parser {
let checked = match (connector, warehouse) {
(true, _) if self.check_text_seq(&["ADD"]) => self.check_connector_version(),
(true, _) if self.check_text_seq(&["PUSH"]) => self.check_connector_push(),
(_, true) => self.check_warehouse_action(self.current == kind_at + 1),
(_, true) => {
let exists = self.tokens[kind_at + 1].token_type == TokenType::If
&& self.tokens.get(kind_at + 2).map(|token| token.token_type)
== Some(TokenType::Exists);
let unnamed =
self.current == kind_at + 1 || (exists && self.current == kind_at + 3);
self.check_warehouse_action(unnamed)
}
_ => Ok(()),
};
self.current = after_name;
Expand Down Expand Up @@ -343,10 +350,18 @@ impl Parser {
}
}

/// Whether the token `offset` tokens ahead ends a notebook's name: the statement end or FROM, so `CREATE NOTEBOOK project FROM @s1` names the notebook PROJECT.
/// Whether the token `offset` tokens ahead ends a notebook's name: the statement end, FROM or an unquoted `<property> =`, so `CREATE NOTEBOOK project FROM @s1` names the notebook PROJECT.
fn notebook_name_ends_at(&self, offset: usize) -> bool {
self.peek_nth(offset)
.is_none_or(|token| matches!(token.token_type, TokenType::From | TokenType::Semicolon))
let property = self
.peek_nth(offset)
.is_some_and(|token| token.token_type != TokenType::QuotedIdentifier)
&& self
.peek_nth(offset + 1)
.is_some_and(|token| token.token_type == TokenType::Eq);
property
|| self.peek_nth(offset).is_none_or(|token| {
matches!(token.token_type, TokenType::From | TokenType::Semicolon)
})
}

/// Refuse a kind whose first word starts a kind the check knows but whose next words complete none, as `ALTER OPENFLOW v1` does.
Expand Down
Loading
Loading