Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmn 1258 add loops #135

Merged
merged 12 commits into from
Aug 23, 2024
34 changes: 33 additions & 1 deletion crates/definitions/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ pub const TOKENS: Tokens<'_> = Tokens {
"'[^']*'"
),
T!("bind_var", "bind_var", "bind_var", r"(?i):[a-z][a-z0-9_]*"),
T!(
"loop_label",
"loop_label",
"ident",
r"(?i)<<[a-z_][a-z0-9_$#]*>>",
1
),
T!(
"iter_range",
"iter_range",
"iter_range",
r"[0-9]*[[:space:]]?\.\.[[:space:]]?[0-9]*",
5
),
],
keywords: &[
T!["accessible"],
Expand Down Expand Up @@ -117,6 +131,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
T!("container"),
T!("container_map"),
T!("containers_default"),
T!("continue"),
T!("context"),
T!("create"),
T!("cross"),
Expand Down Expand Up @@ -160,6 +175,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
T!("exceptions"),
T!("execute"),
T!("exists"),
T!("exit"),
T!("extend"),
T!("extended"),
T!("external"),
Expand All @@ -185,10 +201,12 @@ pub const TOKENS: Tokens<'_> = Tokens {
T!("if"),
T!("ilike", "ilike", "comparison_op"),
T!("immediate"),
T!("immutable"),
T!("in"),
T!("increment"),
T!("index"),
T!("indicator"),
T!("indices"),
T!("initially"),
T!("inner"),
T!("insert"),
Expand Down Expand Up @@ -216,6 +234,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
T!("logoff"),
T!("logon"),
T!("long"),
T!("loop"),
T!("map"),
T!("maxlen"),
T!("maxvalue"),
Expand All @@ -225,6 +244,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
T!("mle"),
T!("module"),
T!("month"),
T!("mutable"),
T!("name"),
T!("national"),
T!("natural"),
Expand Down Expand Up @@ -273,6 +293,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
T!("parallel_enable"),
T!("parameters"),
T!("parent"),
T!("pairs"),
T!("partition"),
T!("persistable"),
T!("pipelined"),
Expand All @@ -299,6 +320,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
T!("relies_on"),
T!("rely"),
T!("rename"),
T!("repeat"),
T!("replace"),
T!("result"),
T!("result_cache"),
Expand Down Expand Up @@ -372,6 +394,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
T!("wait"),
T!("when"),
T!("where"),
T!("while"),
T!("with"),
T!("wnds"),
T!("wnps"),
Expand All @@ -394,6 +417,7 @@ pub const SYNTAX_NODES: &'_ [SyntaxNode<'_>] = &[
S!("assign", "An Assign operator `:=`"),
S!("assignment_expr", "An assignment like a=b"),
S!("asterisk", "An asterisk `*`"),
S!("basic_loop", "A node that contains a basic LOOP"),
S!("bind_var", "A bind variable, e.g. `:OLD`"),
S!("block", "A node that marks a block"),
S!("block_statement", "A node that marks an individual statement inside a block"),
Expand All @@ -411,6 +435,7 @@ pub const SYNTAX_NODES: &'_ [SyntaxNode<'_>] = &[
S!("connect_by_root", "The CONNECT_BY_ROOT operator"),
S!("connect", "The CONNECT BY clause in selects"),
S!("constraint", "A node that marks a full constraint"),
S!("continue_stmt", "A node that contains a continue statement"),
S!("constructor_declaration", "A node containing a constructor_declaration"),
S!("cross_join_clause", "A node that contains a full CROSS JOIN clause"),
S!("cross_outer_apply_clause", "A node that contains a full cross outer apply clause"),
Expand All @@ -429,7 +454,9 @@ pub const SYNTAX_NODES: &'_ [SyntaxNode<'_>] = &[
S!("error", "An error token with a cause"),
S!("exclam", "An exclamation mark `!`"),
S!("execute_immediate_stmt", "A node that contains a full EXECUTE IMMEDIATE statement"),
S!("exit_stmt", "A node that contains a full EXIT statement"),
S!("expression", "Holds a generic SQL logic/arithmetic expression"),
S!("for_loop", "A node containing a FOR LOOP"),
S!("func_decl_in_type", "A node containing a func_decl_in_type"),
S!("function", "A node that marks a full CREATE [..] FUNCTION block"),
S!("function_header", "A node that marks a FUNCTION header with params and return type"),
Expand All @@ -441,14 +468,18 @@ pub const SYNTAX_NODES: &'_ [SyntaxNode<'_>] = &[
S!("hierarchical_op", "An operator in hierarchical queries"),
S!("ident", "An identifier, either quoted or unquoted"),
S!("ident_group", "An identifier group, consisting of multiple idents"),
S!("inner_join_clause", "A node that contains an INNER JOIN clause"),
S!("iteration_control", "A node containing an iteration control block"),
S!("insert_stmt", "A node that marks a full INSERT statement"),
S!("integer", "Any integer, positive and negative"),
S!("into_clause", "A node that contains an `INTO` clause of a SELECT statement"),
S!("iterator", "A node that contains an Iterator"),
S!("iter_range", "A node containing an iter range like 1..69"),
S!("inner_join_clause", "A node that contains an INNER JOIN clause"),
S!("invoker_rights_clause", "A node that contains an invoker rights clause"),
S!("join_clause", "A node that contains a JOIN clause"),
S!("keyword", "A SQL keyword, e.g. `CREATE`"),
S!("logic_op", "Represents a logical SQL operator (AND, OR, NOT)"),
S!("loop", "A node that contains a Basic, For, or While LOOP"),
S!("l_paren", "Left Paren"),
S!("map_order_func_declaration", "A node containing a map_order_func_declaration"),
S!("minus", "A minus `-`"),
Expand Down Expand Up @@ -510,5 +541,6 @@ pub const SYNTAX_NODES: &'_ [SyntaxNode<'_>] = &[
S!("variable_decl_list", "A node that marks a list of variable declarations of functions and procedures"),
S!("view", "A node that marks a full CREATE VIEW block"),
S!("where_clause", "Represent a complete `WHERE` clause expression"),
S!("while_loop", "A node containing a WHILE LOOP"),
S!("whitespace", "Any whitespace character"),
];
26 changes: 25 additions & 1 deletion crates/source_gen/src/lexer/generated.rs

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions crates/source_gen/src/syntax/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum SyntaxKind {
AssignmentExpr,
#[doc = "An asterisk `*`"]
Asterisk,
#[doc = "A node that contains a basic LOOP"]
BasicLoop,
#[doc = "A bind variable, e.g. `:OLD`"]
BindVar,
#[doc = "A node that marks a block"]
Expand Down Expand Up @@ -68,6 +70,8 @@ pub enum SyntaxKind {
Connect,
#[doc = "A node that marks a full constraint"]
Constraint,
#[doc = "A node that contains a continue statement"]
ContinueStmt,
#[doc = "A node containing a constructor_declaration"]
ConstructorDeclaration,
#[doc = "A node that contains a full CROSS JOIN clause"]
Expand Down Expand Up @@ -104,8 +108,12 @@ pub enum SyntaxKind {
Exclam,
#[doc = "A node that contains a full EXECUTE IMMEDIATE statement"]
ExecuteImmediateStmt,
#[doc = "A node that contains a full EXIT statement"]
ExitStmt,
#[doc = "Holds a generic SQL logic/arithmetic expression"]
Expression,
#[doc = "A node containing a FOR LOOP"]
ForLoop,
#[doc = "A node containing a func_decl_in_type"]
FuncDeclInType,
#[doc = "A node that marks a full CREATE [..] FUNCTION block"]
Expand All @@ -128,14 +136,20 @@ pub enum SyntaxKind {
Ident,
#[doc = "An identifier group, consisting of multiple idents"]
IdentGroup,
#[doc = "A node that contains an INNER JOIN clause"]
InnerJoinClause,
#[doc = "A node containing an iteration control block"]
IterationControl,
#[doc = "A node that marks a full INSERT statement"]
InsertStmt,
#[doc = "Any integer, positive and negative"]
Integer,
#[doc = "A node that contains an `INTO` clause of a SELECT statement"]
IntoClause,
#[doc = "A node that contains an Iterator"]
Iterator,
#[doc = "A node containing an iter range like 1..69"]
IterRange,
#[doc = "A node that contains an INNER JOIN clause"]
InnerJoinClause,
#[doc = "A node that contains an invoker rights clause"]
InvokerRightsClause,
#[doc = "A node that contains a JOIN clause"]
Expand All @@ -144,6 +158,8 @@ pub enum SyntaxKind {
Keyword,
#[doc = "Represents a logical SQL operator (AND, OR, NOT)"]
LogicOp,
#[doc = "A node that contains a Basic, For, or While LOOP"]
Loop,
#[doc = "Left Paren"]
LParen,
#[doc = "A node containing a map_order_func_declaration"]
Expand Down Expand Up @@ -266,6 +282,8 @@ pub enum SyntaxKind {
View,
#[doc = "Represent a complete `WHERE` clause expression"]
WhereClause,
#[doc = "A node containing a WHILE LOOP"]
WhileLoop,
#[doc = "Any whitespace character"]
Whitespace,
}
Expand Down Expand Up @@ -303,6 +321,8 @@ impl From<TokenKind> for SyntaxKind {
TokenKind::QuotedIdent => SyntaxKind::Ident,
TokenKind::QuotedLiteral => SyntaxKind::QuotedLiteral,
TokenKind::BindVar => SyntaxKind::BindVar,
TokenKind::LoopLabel => SyntaxKind::Ident,
TokenKind::IterRange => SyntaxKind::IterRange,
TokenKind::AccessibleKw => SyntaxKind::Keyword,
TokenKind::AddKw => SyntaxKind::Keyword,
TokenKind::AfterKw => SyntaxKind::Keyword,
Expand Down Expand Up @@ -362,6 +382,7 @@ impl From<TokenKind> for SyntaxKind {
TokenKind::ContainerKw => SyntaxKind::Keyword,
TokenKind::ContainerMapKw => SyntaxKind::Keyword,
TokenKind::ContainersDefaultKw => SyntaxKind::Keyword,
TokenKind::ContinueKw => SyntaxKind::Keyword,
TokenKind::ContextKw => SyntaxKind::Keyword,
TokenKind::CreateKw => SyntaxKind::Keyword,
TokenKind::CrossKw => SyntaxKind::Keyword,
Expand Down Expand Up @@ -405,6 +426,7 @@ impl From<TokenKind> for SyntaxKind {
TokenKind::ExceptionsKw => SyntaxKind::Keyword,
TokenKind::ExecuteKw => SyntaxKind::Keyword,
TokenKind::ExistsKw => SyntaxKind::Keyword,
TokenKind::ExitKw => SyntaxKind::Keyword,
TokenKind::ExtendKw => SyntaxKind::Keyword,
TokenKind::ExtendedKw => SyntaxKind::Keyword,
TokenKind::ExternalKw => SyntaxKind::Keyword,
Expand All @@ -430,10 +452,12 @@ impl From<TokenKind> for SyntaxKind {
TokenKind::IfKw => SyntaxKind::Keyword,
TokenKind::IlikeKw => SyntaxKind::ComparisonOp,
TokenKind::ImmediateKw => SyntaxKind::Keyword,
TokenKind::ImmutableKw => SyntaxKind::Keyword,
TokenKind::InKw => SyntaxKind::Keyword,
TokenKind::IncrementKw => SyntaxKind::Keyword,
TokenKind::IndexKw => SyntaxKind::Keyword,
TokenKind::IndicatorKw => SyntaxKind::Keyword,
TokenKind::IndicesKw => SyntaxKind::Keyword,
TokenKind::InitiallyKw => SyntaxKind::Keyword,
TokenKind::InnerKw => SyntaxKind::Keyword,
TokenKind::InsertKw => SyntaxKind::Keyword,
Expand Down Expand Up @@ -461,6 +485,7 @@ impl From<TokenKind> for SyntaxKind {
TokenKind::LogoffKw => SyntaxKind::Keyword,
TokenKind::LogonKw => SyntaxKind::Keyword,
TokenKind::LongKw => SyntaxKind::Keyword,
TokenKind::LoopKw => SyntaxKind::Keyword,
TokenKind::MapKw => SyntaxKind::Keyword,
TokenKind::MaxlenKw => SyntaxKind::Keyword,
TokenKind::MaxvalueKw => SyntaxKind::Keyword,
Expand All @@ -470,6 +495,7 @@ impl From<TokenKind> for SyntaxKind {
TokenKind::MleKw => SyntaxKind::Keyword,
TokenKind::ModuleKw => SyntaxKind::Keyword,
TokenKind::MonthKw => SyntaxKind::Keyword,
TokenKind::MutableKw => SyntaxKind::Keyword,
TokenKind::NameKw => SyntaxKind::Keyword,
TokenKind::NationalKw => SyntaxKind::Keyword,
TokenKind::NaturalKw => SyntaxKind::Keyword,
Expand Down Expand Up @@ -518,6 +544,7 @@ impl From<TokenKind> for SyntaxKind {
TokenKind::ParallelEnableKw => SyntaxKind::Keyword,
TokenKind::ParametersKw => SyntaxKind::Keyword,
TokenKind::ParentKw => SyntaxKind::Keyword,
TokenKind::PairsKw => SyntaxKind::Keyword,
TokenKind::PartitionKw => SyntaxKind::Keyword,
TokenKind::PersistableKw => SyntaxKind::Keyword,
TokenKind::PipelinedKw => SyntaxKind::Keyword,
Expand All @@ -544,6 +571,7 @@ impl From<TokenKind> for SyntaxKind {
TokenKind::ReliesOnKw => SyntaxKind::Keyword,
TokenKind::RelyKw => SyntaxKind::Keyword,
TokenKind::RenameKw => SyntaxKind::Keyword,
TokenKind::RepeatKw => SyntaxKind::Keyword,
TokenKind::ReplaceKw => SyntaxKind::Keyword,
TokenKind::ResultKw => SyntaxKind::Keyword,
TokenKind::ResultCacheKw => SyntaxKind::Keyword,
Expand Down Expand Up @@ -617,6 +645,7 @@ impl From<TokenKind> for SyntaxKind {
TokenKind::WaitKw => SyntaxKind::Keyword,
TokenKind::WhenKw => SyntaxKind::Keyword,
TokenKind::WhereKw => SyntaxKind::Keyword,
TokenKind::WhileKw => SyntaxKind::Keyword,
TokenKind::WithKw => SyntaxKind::Keyword,
TokenKind::WndsKw => SyntaxKind::Keyword,
TokenKind::WnpsKw => SyntaxKind::Keyword,
Expand Down
6 changes: 6 additions & 0 deletions src/grammar/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use source_gen::syntax::SyntaxKind;
use source_gen::T;

use super::commit::parse_commit;
use super::loops::{parse_continue_stmt, parse_exit_stmt, parse_loop};
use super::{parse_cursor, parse_dml, parse_execute_immediate, parse_raise_stmt};

/// Parses a complete block.
Expand Down Expand Up @@ -46,11 +47,16 @@ pub(super) fn parse_stmt(p: &mut Parser) {
p.start(SyntaxKind::BlockStatement);

match p.current() {
T![continue] => parse_continue_stmt(p),
T![cursor] => parse_cursor(p),
T![declare] | T![begin] => parse_block(p),
T![execute] => parse_execute_immediate(p),
T![exit] => parse_exit_stmt(p),
T![if] => parse_if_stmt(p),
T![insert] => parse_insert(p),
T![loop] | T![loop_label] => {
parse_loop(p);
}
T![null] => parse_null_stmt(p),
T![return] => parse_return_stmt(p),
T![select] => parse_query(p, true),
Expand Down
46 changes: 46 additions & 0 deletions src/grammar/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,52 @@ use source_gen::lexer::TokenKind;
use source_gen::syntax::SyntaxKind;
use source_gen::T;

pub fn opt_parse_datatype(p: &mut Parser) -> bool {
match p.current() {
T![bfile]
| T![binary]
| T![binary_double]
| T![binary_float]
| T![binary_integer]
| T![blob]
| T![char]
| T![character]
| T![clob]
| T![date]
| T![dec]
| T![decimal]
| T![double]
| T![float]
| T![int]
| T![integer]
| T![interval]
| T![long]
| T![national]
| T![natural]
| T![nchar]
| T![nclob]
| T![number]
| T![numeric]
| T![nvarchar2]
| T![pls_integer]
| T![quoted_ident]
| T![raw]
| T![real]
| T![rowid]
| T![smallint]
| T![string]
| T![timestamp]
| T![unquoted_ident]
| T![urowid]
| T![varchar2]
| T![varchar] => {
parse_datatype(p);
true
}
_ => false,
}
}

/// Parses a complete datatype.
pub fn parse_datatype(p: &mut Parser) {
p.start(SyntaxKind::Datatype);
Expand Down
Loading
Loading