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
10 changes: 3 additions & 7 deletions crates/squawk_ide/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,9 @@ fn bind_create_schema(b: &mut Binder, create_schema: ast::CreateSchema) {
let schema_name = Name::from_node(&schema_name_node);
let name_ptr = SyntaxNodePtr::new(schema_name_node.syntax());
(schema_name, name_ptr)
} else if let Some(schema_name_ref) = create_schema
.schema_authorization()
.and_then(|authorization| authorization.role())
.and_then(|role| role.name_ref())
{
let schema_name = Name::from_node(&schema_name_ref);
let name_ptr = SyntaxNodePtr::new(schema_name_ref.syntax());
} else if let Some(name) = create_schema.role().and_then(|role| role.name()) {
let schema_name = Name::from_node(&name);
let name_ptr = SyntaxNodePtr::new(name.syntax());
(schema_name, name_ptr)
} else {
return;
Expand Down
11 changes: 0 additions & 11 deletions crates/squawk_ide/src/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub(crate) enum NameRefClass {
DropRoutine,
CallProcedure,
DropSchema,
CreateSchema,
CreateIndex,
CreateIndexColumn,
DefaultConstraintFunctionCall,
Expand Down Expand Up @@ -353,17 +352,13 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
}

let mut in_type = false;
let mut in_schema_authorization = false;
for ancestor in name_ref.syntax().ancestors() {
if ast::PathType::can_cast(ancestor.kind()) || ast::ExprType::can_cast(ancestor.kind()) {
in_type = true;
}
if in_type {
return Some(NameRefClass::TypeReference);
}
if ast::SchemaAuthorization::can_cast(ancestor.kind()) {
in_schema_authorization = true;
}
if ast::Fetch::can_cast(ancestor.kind())
|| ast::Move::can_cast(ancestor.kind())
|| ast::Close::can_cast(ancestor.kind())
Expand Down Expand Up @@ -590,12 +585,6 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
if ast::DropSchema::can_cast(ancestor.kind()) {
return Some(NameRefClass::DropSchema);
}
if in_schema_authorization
&& let Some(create_schema) = ast::CreateSchema::cast(ancestor.clone())
&& create_schema.name().is_none()
{
return Some(NameRefClass::CreateSchema);
}
if ast::CreateIndex::can_cast(ancestor.kind()) {
if in_partition_item {
return Some(NameRefClass::CreateIndexColumn);
Expand Down
11 changes: 2 additions & 9 deletions crates/squawk_ide/src/document_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,8 @@ fn create_schema_symbol(create_schema: ast::CreateSchema) -> Option<DocumentSymb
name_node.syntax().text().to_string(),
name_node.syntax().text_range(),
)
} else if let Some(schema_name_ref) = create_schema
.schema_authorization()
.and_then(|authorization| authorization.role())
.and_then(|role| role.name_ref())
{
(
schema_name_ref.syntax().text().to_string(),
schema_name_ref.syntax().text_range(),
)
} else if let Some(name) = create_schema.role().and_then(|r| r.name()) {
(name.syntax().text().to_string(), name.syntax().text_range())
} else {
return None;
};
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/expand_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const DELIMITED_LIST_KINDS: &[SyntaxKind] = &[
SyntaxKind::PARTITION_LIST,
SyntaxKind::RETURNING_OPTION_LIST,
SyntaxKind::REVOKE_COMMAND_LIST,
SyntaxKind::ROLE_LIST,
SyntaxKind::ROLE_REF_LIST,
SyntaxKind::ROW_LIST,
SyntaxKind::XML_ATTRIBUTE_LIST,
SyntaxKind::XML_NAMESPACE_LIST,
Expand Down
8 changes: 3 additions & 5 deletions crates/squawk_ide/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ pub fn hover(file: &ast::SourceFile, offset: TextSize) -> Option<String> {
}
NameRefClass::SchemaQualifier
| NameRefClass::DropSchema
| NameRefClass::CreateSchema
| NameRefClass::ReindexSchema => {
return hover_schema(root, &name_ref, &binder);
}
Expand Down Expand Up @@ -1129,10 +1128,9 @@ fn create_schema_name(create_schema: &ast::CreateSchema) -> Option<String> {
}

create_schema
.schema_authorization()
.and_then(|authorization| authorization.role())
.and_then(|role| role.name_ref())
.map(|name_ref| name_ref.syntax().text().to_string())
.role()
.and_then(|r| r.name())
.map(|n| n.syntax().text().to_string())
}

fn format_create_schema(create_schema: &ast::CreateSchema) -> Option<String> {
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ pub(crate) fn resolve_name_ref(
resolve_procedure(binder, &procedure_name, &schema, None, position)
.map(|ptr| smallvec![ptr])
}
NameRefClass::DropSchema | NameRefClass::SchemaQualifier | NameRefClass::CreateSchema => {
NameRefClass::DropSchema | NameRefClass::SchemaQualifier => {
let schema_name = Name::from_node(name_ref);
resolve_schema(binder, &schema_name).map(|ptr| smallvec![ptr])
}
Expand Down
4 changes: 2 additions & 2 deletions crates/squawk_parser/src/generated/syntax_kind.rs

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

87 changes: 50 additions & 37 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5296,7 +5296,7 @@ fn owner_to(p: &mut Parser<'_>) -> CompletedMarker {
let m = p.start();
p.bump(OWNER_KW);
p.expect(TO_KW);
role(p);
role_ref(p);
m.complete(p, OWNER_TO)
}

Expand Down Expand Up @@ -6099,7 +6099,7 @@ fn alter_role(p: &mut Parser<'_>) -> CompletedMarker {
p.bump(ALTER_KW);
p.bump(ROLE_KW);
if !p.eat(ALL_KW) {
role(p);
role_ref(p);
}
match p.current() {
RENAME_KW => {
Expand Down Expand Up @@ -6258,11 +6258,11 @@ fn alter_policy(p: &mut Parser<'_>) -> CompletedMarker {

fn role_list(p: &mut Parser<'_>) {
let m = p.start();
role(p);
role_ref(p);
while !p.at(EOF) && p.eat(COMMA) {
role(p);
role_ref(p);
}
m.complete(p, ROLE_LIST);
m.complete(p, ROLE_REF_LIST);
}

// ALTER OPERATOR FAMILY name USING index_method ADD
Expand Down Expand Up @@ -6525,7 +6525,7 @@ fn alter_large_object(p: &mut Parser<'_>) -> CompletedMarker {
}
p.expect(OWNER_KW);
p.expect(TO_KW);
role(p);
role_ref(p);
m.complete(p, ALTER_LARGE_OBJECT)
}

Expand Down Expand Up @@ -6658,7 +6658,7 @@ fn alter_group(p: &mut Parser<'_>) -> CompletedMarker {
let m = p.start();
p.bump(ALTER_KW);
p.bump(GROUP_KW);
role(p);
role_ref(p);
match p.current() {
ADD_KW | DROP_KW => {
p.bump_any();
Expand Down Expand Up @@ -7983,7 +7983,7 @@ fn alter_user(p: &mut Parser<'_>) -> CompletedMarker {
p.bump(ALTER_KW);
p.bump(USER_KW);
if !p.eat(ALL_KW) {
role(p);
role_ref(p);
}
// be careful of the case where we're at the IN of IN DATABASE
if p.at(WITH_KW) || (p.at_ts(ROLE_OPTION_FIRST) && !p.nth_at(1, DATABASE_KW)) {
Expand Down Expand Up @@ -8024,7 +8024,7 @@ fn alter_user_mapping(p: &mut Parser<'_>) -> CompletedMarker {
p.bump(USER_KW);
p.bump(MAPPING_KW);
p.expect(FOR_KW);
role(p);
role_ref(p);
server_name(p);
if !opt_alter_option_list(p) {
p.error("expected options");
Expand Down Expand Up @@ -9369,7 +9369,7 @@ fn create_tablespace(p: &mut Parser<'_>) -> CompletedMarker {
p.bump(TABLESPACE_KW);
name(p);
if p.eat(OWNER_KW) {
role(p);
role_ref(p);
}
p.expect(LOCATION_KW);
string_literal(p);
Expand Down Expand Up @@ -9500,7 +9500,7 @@ fn create_user_mapping(p: &mut Parser<'_>) -> CompletedMarker {
p.expect(FOR_KW);
// role | USER
if !p.eat(USER_KW) {
role(p);
role_ref(p);
}
server_name(p);
opt_alter_option_list(p);
Expand Down Expand Up @@ -10177,7 +10177,7 @@ fn drop_user_mapping(p: &mut Parser<'_>) -> CompletedMarker {
p.expect(FOR_KW);
// role | USER
if !p.eat(USER_KW) {
role(p);
role_ref(p);
}
server_name(p);
m.complete(p, DROP_USER_MAPPING)
Expand Down Expand Up @@ -10751,7 +10751,7 @@ fn privilege_target(p: &mut Parser<'_>) {
fn opt_granted_by(p: &mut Parser<'_>) {
if p.eat(GRANTED_KW) {
p.expect(BY_KW);
role(p);
role_ref(p);
}
}

Expand Down Expand Up @@ -10843,7 +10843,7 @@ const REVOKE_COMMAND_FIRST: TokenSet = TokenSet::new(&[

fn revoke_command(p: &mut Parser<'_>) {
let m = p.start();
if !opt_role(p) {
if !opt_role_ref(p) {
if p.eat(ALTER_KW) {
p.expect(SYSTEM_KW);
} else if p.at_ts(REVOKE_COMMAND_FIRST) {
Expand All @@ -10863,18 +10863,34 @@ fn revoke_command(p: &mut Parser<'_>) {
// | CURRENT_ROLE
// | CURRENT_USER
// | SESSION_USER
fn role(p: &mut Parser<'_>) {
if !opt_role(p) {
fn role_ref(p: &mut Parser<'_>) {
if !opt_role_ref(p) {
p.error(format!("expected role, got {:?}", p.current()))
}
}

fn opt_role(p: &mut Parser<'_>) -> bool {
fn opt_role_ref(p: &mut Parser<'_>) -> bool {
opt_role_(p, ROLE_REF)
}

fn role(p: &mut Parser<'_>) -> bool {
opt_role_(p, ROLE)
}

fn opt_role_(p: &mut Parser<'_>, kind: SyntaxKind) -> bool {
assert!(matches!(kind, ROLE | ROLE_REF));
let func = |p: &mut Parser<'_>| {
if kind == ROLE_REF {
name_ref(p);
} else {
name(p);
}
};
let m = p.start();
match p.current() {
GROUP_KW => {
p.bump(GROUP_KW);
name_ref(p);
func(p);
}
CURRENT_ROLE_KW | CURRENT_USER_KW | SESSION_USER_KW => {
p.bump_any();
Expand All @@ -10888,14 +10904,14 @@ fn opt_role(p: &mut Parser<'_>) -> bool {
}
}
_ if p.at_ts(NON_RESERVED_WORD) => {
name_ref(p);
func(p);
}
_ => {
m.abandon(p);
return false;
}
}
m.complete(p, ROLE);
m.complete(p, kind);
true
}

Expand Down Expand Up @@ -11081,7 +11097,7 @@ fn set_role(p: &mut Parser<'_>) -> CompletedMarker {
let _ = p.eat(SESSION_KW) || p.eat(LOCAL_KW);
p.expect(ROLE_KW);
if !p.eat(NONE_KW) && opt_string_literal(p).is_none() {
role(p);
role_ref(p);
}
}
m.complete(p, SET_ROLE)
Expand All @@ -11098,7 +11114,7 @@ fn set_session_auth(p: &mut Parser<'_>) -> CompletedMarker {
p.eat(SESSION_KW);
p.expect(AUTHORIZATION_KW);
if !p.eat(DEFAULT_KW) && opt_string_literal(p).is_none() {
role(p);
role_ref(p);
}
m.complete(p, SET_SESSION_AUTH)
}
Expand Down Expand Up @@ -12159,17 +12175,6 @@ fn drop_schema(p: &mut Parser<'_>) -> CompletedMarker {
m.complete(p, DROP_SCHEMA)
}

fn opt_schema_auth(p: &mut Parser<'_>) -> bool {
let m = p.start();
if p.eat(AUTHORIZATION_KW) {
role(p);
m.complete(p, SCHEMA_AUTHORIZATION);
return true;
}
m.abandon(p);
false
}

// An SQL statement defining an object to be created within the schema.
//
// Currently, only CREATE TABLE, CREATE VIEW, CREATE INDEX, CREATE SEQUENCE,
Expand Down Expand Up @@ -12237,28 +12242,36 @@ fn create_schema(p: &mut Parser<'_>) -> CompletedMarker {
p.bump(CREATE_KW);
p.bump(SCHEMA_KW);
let if_not_exists = opt_if_not_exists(p).is_some();
match (if_not_exists, opt_schema_auth(p)) {
match (if_not_exists, p.eat(AUTHORIZATION_KW)) {
// CREATE SCHEMA IF NOT EXISTS AUTHORIZATION role_specification
// ^
(true, true) => m.complete(p, CREATE_SCHEMA),
(true, true) => {
role(p);
m.complete(p, CREATE_SCHEMA)
}
// CREATE SCHEMA IF NOT EXISTS schema_name [ AUTHORIZATION role_specification ]
// ^
(true, false) => {
name(p);
opt_schema_auth(p);
if p.eat(AUTHORIZATION_KW) {
role_ref(p);
}
m.complete(p, CREATE_SCHEMA)
}
// CREATE SCHEMA AUTHORIZATION role_specification [ schema_element [ ... ] ]
// ^
(false, true) => {
role(p);
opt_schema_elements(p);
m.complete(p, CREATE_SCHEMA)
}
// CREATE SCHEMA schema_name [ AUTHORIZATION role_specification ] [ schema_element [ ... ] ]
// ^
(false, false) => {
name(p);
opt_schema_auth(p);
if p.eat(AUTHORIZATION_KW) {
role_ref(p);
}
opt_schema_elements(p);
m.complete(p, CREATE_SCHEMA)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ SOURCE_FILE
WHITESPACE " "
TO_KW "to"
WHITESPACE " "
ROLE
ROLE_REF
CURRENT_USER_KW "current_user"
SEMICOLON ";"
WHITESPACE "\n\n"
Expand Down
Loading
Loading