Skip to content

Commit

Permalink
feat: add privilege name
Browse files Browse the repository at this point in the history
  • Loading branch information
dl239 committed Feb 21, 2024
1 parent 55be108 commit 65db553
Show file tree
Hide file tree
Showing 4 changed files with 345 additions and 0 deletions.
48 changes: 48 additions & 0 deletions zetasql/parser/bison_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ using zetasql::ASTDropStatement;
%token KW_CURRENT_ROW "CURRENT_ROW"
%token KW_DATA "DATA"
%token KW_DATABASE "DATABASE"
%token KW_DATABASES "DATABASES"
%token KW_DATE "DATE"
%token KW_DATETIME "DATETIME"
%token KW_DECIMAL "DECIMAL"
Expand Down Expand Up @@ -908,6 +909,7 @@ using zetasql::ASTDropStatement;
%token KW_RETURN "RETURN"
%token KW_RETURNS "RETURNS"
%token KW_REVOKE "REVOKE"
%token KW_ROLE "ROLE"
%token KW_ROLLBACK "ROLLBACK"
%token KW_ROW "ROW"
%token KW_RUN "RUN"
Expand Down Expand Up @@ -3440,6 +3442,50 @@ privilege_name:
// The SELECT keyword is allowed to be a privilege name.
$$ = parser->MakeIdentifier(@1, parser->GetInputText(@1));
}
| KW_CREATE
{
// The CREATE keyword is allowed to be a privilege name.
$$ = parser->MakeIdentifier(@1, parser->GetInputText(@1));
}
| KW_INDEX
{
$$ = parser->MakeIdentifier(@1, parser->GetInputText(@1));
}
| KW_ALTER KW_USER
{
std::string identifier = absl::StrCat(parser->GetInputText(@1), " ", parser->GetInputText(@2));
$$ = parser->MakeIdentifier(@$, identifier.c_str());
}
| KW_CREATE KW_USER
{
std::string identifier = absl::StrCat(parser->GetInputText(@1), " ", parser->GetInputText(@2));
$$ = parser->MakeIdentifier(@$, identifier.c_str());
}
| KW_CREATE KW_ROLE
{
std::string identifier = absl::StrCat(parser->GetInputText(@1), " ", parser->GetInputText(@2));
$$ = parser->MakeIdentifier(@$, identifier.c_str());
}
| KW_DROP "DEPLOYMENT"
{
std::string identifier = absl::StrCat(parser->GetInputText(@1), " ", parser->GetInputText(@2));
$$ = parser->MakeIdentifier(@$, identifier.c_str());
}
| KW_DROP KW_USER
{
std::string identifier = absl::StrCat(parser->GetInputText(@1), " ", parser->GetInputText(@2));
$$ = parser->MakeIdentifier(@$, identifier.c_str());
}
| KW_DROP KW_ROLE
{
std::string identifier = absl::StrCat(parser->GetInputText(@1), " ", parser->GetInputText(@2));
$$ = parser->MakeIdentifier(@$, identifier.c_str());
}
| KW_SHOW KW_DATABASES
{
std::string identifier = absl::StrCat(parser->GetInputText(@1), " ", parser->GetInputText(@2));
$$ = parser->MakeIdentifier(@$, identifier.c_str());
}
;

rename_statement:
Expand Down Expand Up @@ -7557,6 +7603,7 @@ keyword_as_identifier:
| "CURRENT_ROW"
| "DATA"
| "DATABASE"
| "DATABASES"
| "DATE"
| "DATETIME"
| "DECIMAL"
Expand Down Expand Up @@ -7648,6 +7695,7 @@ keyword_as_identifier:
| "RETURNS"
| "RETURN"
| "REVOKE"
| "ROLE"
| "ROLLBACK"
| "ROW"
| "RUN"
Expand Down
2 changes: 2 additions & 0 deletions zetasql/parser/flex_tokenizer.l
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ current_time { return BisonParserImpl::token::KW_CURRENT_TIME;}
current_row { return BisonParserImpl::token::KW_CURRENT_ROW; }
data { return BisonParserImpl::token::KW_DATA; }
database { return BisonParserImpl::token::KW_DATABASE; }
databases { return BisonParserImpl::token::KW_DATABASES; }
date { return BisonParserImpl::token::KW_DATE; }
datetime { return BisonParserImpl::token::KW_DATETIME; }
decimal { return BisonParserImpl::token::KW_DECIMAL; }
Expand Down Expand Up @@ -603,6 +604,7 @@ return { return BisonParserImpl::token::KW_RETURN; }
returns { return BisonParserImpl::token::KW_RETURNS; }
revoke { return BisonParserImpl::token::KW_REVOKE; }
right { return BisonParserImpl::token::KW_RIGHT; }
role { return BisonParserImpl::token::KW_ROLE; }
rollback { return BisonParserImpl::token::KW_ROLLBACK; }
rollup { return BisonParserImpl::token::KW_ROLLUP; }
row { return BisonParserImpl::token::KW_ROW; }
Expand Down
2 changes: 2 additions & 0 deletions zetasql/parser/keywords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ constexpr KeywordInfoPOD kAllKeywords[] = {
{"current_row", KW_CURRENT_ROW},
{"data", KW_DATA},
{"database", KW_DATABASE},
{"databases", KW_DATABASES},
{"date", KW_DATE},
{"datetime", KW_DATETIME},
{"decimal", KW_DECIMAL},
Expand Down Expand Up @@ -259,6 +260,7 @@ constexpr KeywordInfoPOD kAllKeywords[] = {
{"returns", KW_RETURNS},
{"revoke", KW_REVOKE},
{"right", KW_RIGHT, KeywordInfo::kReserved},
{"role", KW_ROLE},
{"rollback", KW_ROLLBACK},
{"rollup", KW_ROLLUP, KeywordInfo::kReserved},
{"row", KW_ROW},
Expand Down
Loading

0 comments on commit 65db553

Please sign in to comment.