Skip to content

Commit 237b2e6

Browse files
CMN-1258: As Debora I want to be able to parse Loops (#135)
Co-authored-by: Kieran Kaelin <[email protected]>
1 parent 0858281 commit 237b2e6

File tree

7 files changed

+894
-4
lines changed

7 files changed

+894
-4
lines changed

crates/definitions/src/data.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ pub const TOKENS: Tokens<'_> = Tokens {
5656
"'[^']*'"
5757
),
5858
T!("bind_var", "bind_var", "bind_var", r"(?i):[a-z][a-z0-9_]*"),
59+
T!(
60+
"loop_label",
61+
"loop_label",
62+
"ident",
63+
r"(?i)<<[a-z_][a-z0-9_$#]*>>",
64+
1
65+
),
66+
T!(
67+
"iter_range",
68+
"iter_range",
69+
"iter_range",
70+
r"[0-9]*[[:space:]]?\.\.[[:space:]]?[0-9]*",
71+
5
72+
),
5973
],
6074
keywords: &[
6175
T!["accessible"],
@@ -117,6 +131,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
117131
T!("container"),
118132
T!("container_map"),
119133
T!("containers_default"),
134+
T!("continue"),
120135
T!("context"),
121136
T!("create"),
122137
T!("cross"),
@@ -160,6 +175,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
160175
T!("exceptions"),
161176
T!("execute"),
162177
T!("exists"),
178+
T!("exit"),
163179
T!("extend"),
164180
T!("extended"),
165181
T!("external"),
@@ -185,10 +201,12 @@ pub const TOKENS: Tokens<'_> = Tokens {
185201
T!("if"),
186202
T!("ilike", "ilike", "comparison_op"),
187203
T!("immediate"),
204+
T!("immutable"),
188205
T!("in"),
189206
T!("increment"),
190207
T!("index"),
191208
T!("indicator"),
209+
T!("indices"),
192210
T!("initially"),
193211
T!("inner"),
194212
T!("insert"),
@@ -216,6 +234,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
216234
T!("logoff"),
217235
T!("logon"),
218236
T!("long"),
237+
T!("loop"),
219238
T!("map"),
220239
T!("maxlen"),
221240
T!("maxvalue"),
@@ -225,6 +244,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
225244
T!("mle"),
226245
T!("module"),
227246
T!("month"),
247+
T!("mutable"),
228248
T!("name"),
229249
T!("national"),
230250
T!("natural"),
@@ -273,6 +293,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
273293
T!("parallel_enable"),
274294
T!("parameters"),
275295
T!("parent"),
296+
T!("pairs"),
276297
T!("partition"),
277298
T!("persistable"),
278299
T!("pipelined"),
@@ -299,6 +320,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
299320
T!("relies_on"),
300321
T!("rely"),
301322
T!("rename"),
323+
T!("repeat"),
302324
T!("replace"),
303325
T!("result"),
304326
T!("result_cache"),
@@ -372,6 +394,7 @@ pub const TOKENS: Tokens<'_> = Tokens {
372394
T!("wait"),
373395
T!("when"),
374396
T!("where"),
397+
T!("while"),
375398
T!("with"),
376399
T!("wnds"),
377400
T!("wnps"),
@@ -394,6 +417,7 @@ pub const SYNTAX_NODES: &'_ [SyntaxNode<'_>] = &[
394417
S!("assign", "An Assign operator `:=`"),
395418
S!("assignment_expr", "An assignment like a=b"),
396419
S!("asterisk", "An asterisk `*`"),
420+
S!("basic_loop", "A node that contains a basic LOOP"),
397421
S!("bind_var", "A bind variable, e.g. `:OLD`"),
398422
S!("block", "A node that marks a block"),
399423
S!("block_statement", "A node that marks an individual statement inside a block"),
@@ -411,6 +435,7 @@ pub const SYNTAX_NODES: &'_ [SyntaxNode<'_>] = &[
411435
S!("connect_by_root", "The CONNECT_BY_ROOT operator"),
412436
S!("connect", "The CONNECT BY clause in selects"),
413437
S!("constraint", "A node that marks a full constraint"),
438+
S!("continue_stmt", "A node that contains a continue statement"),
414439
S!("constructor_declaration", "A node containing a constructor_declaration"),
415440
S!("cross_join_clause", "A node that contains a full CROSS JOIN clause"),
416441
S!("cross_outer_apply_clause", "A node that contains a full cross outer apply clause"),
@@ -429,7 +454,9 @@ pub const SYNTAX_NODES: &'_ [SyntaxNode<'_>] = &[
429454
S!("error", "An error token with a cause"),
430455
S!("exclam", "An exclamation mark `!`"),
431456
S!("execute_immediate_stmt", "A node that contains a full EXECUTE IMMEDIATE statement"),
457+
S!("exit_stmt", "A node that contains a full EXIT statement"),
432458
S!("expression", "Holds a generic SQL logic/arithmetic expression"),
459+
S!("for_loop", "A node containing a FOR LOOP"),
433460
S!("func_decl_in_type", "A node containing a func_decl_in_type"),
434461
S!("function", "A node that marks a full CREATE [..] FUNCTION block"),
435462
S!("function_header", "A node that marks a FUNCTION header with params and return type"),
@@ -441,14 +468,18 @@ pub const SYNTAX_NODES: &'_ [SyntaxNode<'_>] = &[
441468
S!("hierarchical_op", "An operator in hierarchical queries"),
442469
S!("ident", "An identifier, either quoted or unquoted"),
443470
S!("ident_group", "An identifier group, consisting of multiple idents"),
444-
S!("inner_join_clause", "A node that contains an INNER JOIN clause"),
471+
S!("iteration_control", "A node containing an iteration control block"),
445472
S!("insert_stmt", "A node that marks a full INSERT statement"),
446473
S!("integer", "Any integer, positive and negative"),
447474
S!("into_clause", "A node that contains an `INTO` clause of a SELECT statement"),
475+
S!("iterator", "A node that contains an Iterator"),
476+
S!("iter_range", "A node containing an iter range like 1..69"),
477+
S!("inner_join_clause", "A node that contains an INNER JOIN clause"),
448478
S!("invoker_rights_clause", "A node that contains an invoker rights clause"),
449479
S!("join_clause", "A node that contains a JOIN clause"),
450480
S!("keyword", "A SQL keyword, e.g. `CREATE`"),
451481
S!("logic_op", "Represents a logical SQL operator (AND, OR, NOT)"),
482+
S!("loop", "A node that contains a Basic, For, or While LOOP"),
452483
S!("l_paren", "Left Paren"),
453484
S!("map_order_func_declaration", "A node containing a map_order_func_declaration"),
454485
S!("minus", "A minus `-`"),
@@ -510,5 +541,6 @@ pub const SYNTAX_NODES: &'_ [SyntaxNode<'_>] = &[
510541
S!("variable_decl_list", "A node that marks a list of variable declarations of functions and procedures"),
511542
S!("view", "A node that marks a full CREATE VIEW block"),
512543
S!("where_clause", "Represent a complete `WHERE` clause expression"),
544+
S!("while_loop", "A node containing a WHILE LOOP"),
513545
S!("whitespace", "Any whitespace character"),
514546
];

crates/source_gen/src/lexer/generated.rs

Lines changed: 25 additions & 1 deletion
Large diffs are not rendered by default.

crates/source_gen/src/syntax/generated.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub enum SyntaxKind {
3434
AssignmentExpr,
3535
#[doc = "An asterisk `*`"]
3636
Asterisk,
37+
#[doc = "A node that contains a basic LOOP"]
38+
BasicLoop,
3739
#[doc = "A bind variable, e.g. `:OLD`"]
3840
BindVar,
3941
#[doc = "A node that marks a block"]
@@ -68,6 +70,8 @@ pub enum SyntaxKind {
6870
Connect,
6971
#[doc = "A node that marks a full constraint"]
7072
Constraint,
73+
#[doc = "A node that contains a continue statement"]
74+
ContinueStmt,
7175
#[doc = "A node containing a constructor_declaration"]
7276
ConstructorDeclaration,
7377
#[doc = "A node that contains a full CROSS JOIN clause"]
@@ -104,8 +108,12 @@ pub enum SyntaxKind {
104108
Exclam,
105109
#[doc = "A node that contains a full EXECUTE IMMEDIATE statement"]
106110
ExecuteImmediateStmt,
111+
#[doc = "A node that contains a full EXIT statement"]
112+
ExitStmt,
107113
#[doc = "Holds a generic SQL logic/arithmetic expression"]
108114
Expression,
115+
#[doc = "A node containing a FOR LOOP"]
116+
ForLoop,
109117
#[doc = "A node containing a func_decl_in_type"]
110118
FuncDeclInType,
111119
#[doc = "A node that marks a full CREATE [..] FUNCTION block"]
@@ -128,14 +136,20 @@ pub enum SyntaxKind {
128136
Ident,
129137
#[doc = "An identifier group, consisting of multiple idents"]
130138
IdentGroup,
131-
#[doc = "A node that contains an INNER JOIN clause"]
132-
InnerJoinClause,
139+
#[doc = "A node containing an iteration control block"]
140+
IterationControl,
133141
#[doc = "A node that marks a full INSERT statement"]
134142
InsertStmt,
135143
#[doc = "Any integer, positive and negative"]
136144
Integer,
137145
#[doc = "A node that contains an `INTO` clause of a SELECT statement"]
138146
IntoClause,
147+
#[doc = "A node that contains an Iterator"]
148+
Iterator,
149+
#[doc = "A node containing an iter range like 1..69"]
150+
IterRange,
151+
#[doc = "A node that contains an INNER JOIN clause"]
152+
InnerJoinClause,
139153
#[doc = "A node that contains an invoker rights clause"]
140154
InvokerRightsClause,
141155
#[doc = "A node that contains a JOIN clause"]
@@ -144,6 +158,8 @@ pub enum SyntaxKind {
144158
Keyword,
145159
#[doc = "Represents a logical SQL operator (AND, OR, NOT)"]
146160
LogicOp,
161+
#[doc = "A node that contains a Basic, For, or While LOOP"]
162+
Loop,
147163
#[doc = "Left Paren"]
148164
LParen,
149165
#[doc = "A node containing a map_order_func_declaration"]
@@ -266,6 +282,8 @@ pub enum SyntaxKind {
266282
View,
267283
#[doc = "Represent a complete `WHERE` clause expression"]
268284
WhereClause,
285+
#[doc = "A node containing a WHILE LOOP"]
286+
WhileLoop,
269287
#[doc = "Any whitespace character"]
270288
Whitespace,
271289
}
@@ -303,6 +321,8 @@ impl From<TokenKind> for SyntaxKind {
303321
TokenKind::QuotedIdent => SyntaxKind::Ident,
304322
TokenKind::QuotedLiteral => SyntaxKind::QuotedLiteral,
305323
TokenKind::BindVar => SyntaxKind::BindVar,
324+
TokenKind::LoopLabel => SyntaxKind::Ident,
325+
TokenKind::IterRange => SyntaxKind::IterRange,
306326
TokenKind::AccessibleKw => SyntaxKind::Keyword,
307327
TokenKind::AddKw => SyntaxKind::Keyword,
308328
TokenKind::AfterKw => SyntaxKind::Keyword,
@@ -362,6 +382,7 @@ impl From<TokenKind> for SyntaxKind {
362382
TokenKind::ContainerKw => SyntaxKind::Keyword,
363383
TokenKind::ContainerMapKw => SyntaxKind::Keyword,
364384
TokenKind::ContainersDefaultKw => SyntaxKind::Keyword,
385+
TokenKind::ContinueKw => SyntaxKind::Keyword,
365386
TokenKind::ContextKw => SyntaxKind::Keyword,
366387
TokenKind::CreateKw => SyntaxKind::Keyword,
367388
TokenKind::CrossKw => SyntaxKind::Keyword,
@@ -405,6 +426,7 @@ impl From<TokenKind> for SyntaxKind {
405426
TokenKind::ExceptionsKw => SyntaxKind::Keyword,
406427
TokenKind::ExecuteKw => SyntaxKind::Keyword,
407428
TokenKind::ExistsKw => SyntaxKind::Keyword,
429+
TokenKind::ExitKw => SyntaxKind::Keyword,
408430
TokenKind::ExtendKw => SyntaxKind::Keyword,
409431
TokenKind::ExtendedKw => SyntaxKind::Keyword,
410432
TokenKind::ExternalKw => SyntaxKind::Keyword,
@@ -430,10 +452,12 @@ impl From<TokenKind> for SyntaxKind {
430452
TokenKind::IfKw => SyntaxKind::Keyword,
431453
TokenKind::IlikeKw => SyntaxKind::ComparisonOp,
432454
TokenKind::ImmediateKw => SyntaxKind::Keyword,
455+
TokenKind::ImmutableKw => SyntaxKind::Keyword,
433456
TokenKind::InKw => SyntaxKind::Keyword,
434457
TokenKind::IncrementKw => SyntaxKind::Keyword,
435458
TokenKind::IndexKw => SyntaxKind::Keyword,
436459
TokenKind::IndicatorKw => SyntaxKind::Keyword,
460+
TokenKind::IndicesKw => SyntaxKind::Keyword,
437461
TokenKind::InitiallyKw => SyntaxKind::Keyword,
438462
TokenKind::InnerKw => SyntaxKind::Keyword,
439463
TokenKind::InsertKw => SyntaxKind::Keyword,
@@ -461,6 +485,7 @@ impl From<TokenKind> for SyntaxKind {
461485
TokenKind::LogoffKw => SyntaxKind::Keyword,
462486
TokenKind::LogonKw => SyntaxKind::Keyword,
463487
TokenKind::LongKw => SyntaxKind::Keyword,
488+
TokenKind::LoopKw => SyntaxKind::Keyword,
464489
TokenKind::MapKw => SyntaxKind::Keyword,
465490
TokenKind::MaxlenKw => SyntaxKind::Keyword,
466491
TokenKind::MaxvalueKw => SyntaxKind::Keyword,
@@ -470,6 +495,7 @@ impl From<TokenKind> for SyntaxKind {
470495
TokenKind::MleKw => SyntaxKind::Keyword,
471496
TokenKind::ModuleKw => SyntaxKind::Keyword,
472497
TokenKind::MonthKw => SyntaxKind::Keyword,
498+
TokenKind::MutableKw => SyntaxKind::Keyword,
473499
TokenKind::NameKw => SyntaxKind::Keyword,
474500
TokenKind::NationalKw => SyntaxKind::Keyword,
475501
TokenKind::NaturalKw => SyntaxKind::Keyword,
@@ -518,6 +544,7 @@ impl From<TokenKind> for SyntaxKind {
518544
TokenKind::ParallelEnableKw => SyntaxKind::Keyword,
519545
TokenKind::ParametersKw => SyntaxKind::Keyword,
520546
TokenKind::ParentKw => SyntaxKind::Keyword,
547+
TokenKind::PairsKw => SyntaxKind::Keyword,
521548
TokenKind::PartitionKw => SyntaxKind::Keyword,
522549
TokenKind::PersistableKw => SyntaxKind::Keyword,
523550
TokenKind::PipelinedKw => SyntaxKind::Keyword,
@@ -544,6 +571,7 @@ impl From<TokenKind> for SyntaxKind {
544571
TokenKind::ReliesOnKw => SyntaxKind::Keyword,
545572
TokenKind::RelyKw => SyntaxKind::Keyword,
546573
TokenKind::RenameKw => SyntaxKind::Keyword,
574+
TokenKind::RepeatKw => SyntaxKind::Keyword,
547575
TokenKind::ReplaceKw => SyntaxKind::Keyword,
548576
TokenKind::ResultKw => SyntaxKind::Keyword,
549577
TokenKind::ResultCacheKw => SyntaxKind::Keyword,
@@ -617,6 +645,7 @@ impl From<TokenKind> for SyntaxKind {
617645
TokenKind::WaitKw => SyntaxKind::Keyword,
618646
TokenKind::WhenKw => SyntaxKind::Keyword,
619647
TokenKind::WhereKw => SyntaxKind::Keyword,
648+
TokenKind::WhileKw => SyntaxKind::Keyword,
620649
TokenKind::WithKw => SyntaxKind::Keyword,
621650
TokenKind::WndsKw => SyntaxKind::Keyword,
622651
TokenKind::WnpsKw => SyntaxKind::Keyword,

src/grammar/block.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use source_gen::syntax::SyntaxKind;
1515
use source_gen::T;
1616

1717
use super::commit::parse_commit;
18+
use super::loops::{parse_continue_stmt, parse_exit_stmt, parse_loop};
1819
use super::{parse_cursor, parse_dml, parse_execute_immediate, parse_raise_stmt};
1920

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

4849
match p.current() {
50+
T![continue] => parse_continue_stmt(p),
4951
T![cursor] => parse_cursor(p),
5052
T![declare] | T![begin] => parse_block(p),
5153
T![execute] => parse_execute_immediate(p),
54+
T![exit] => parse_exit_stmt(p),
5255
T![if] => parse_if_stmt(p),
5356
T![insert] => parse_insert(p),
57+
T![loop] | T![loop_label] => {
58+
parse_loop(p);
59+
}
5460
T![null] => parse_null_stmt(p),
5561
T![return] => parse_return_stmt(p),
5662
T![select] => parse_query(p, true),

src/grammar/datatype.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,52 @@ use source_gen::lexer::TokenKind;
1212
use source_gen::syntax::SyntaxKind;
1313
use source_gen::T;
1414

15+
pub fn opt_parse_datatype(p: &mut Parser) -> bool {
16+
match p.current() {
17+
T![bfile]
18+
| T![binary]
19+
| T![binary_double]
20+
| T![binary_float]
21+
| T![binary_integer]
22+
| T![blob]
23+
| T![char]
24+
| T![character]
25+
| T![clob]
26+
| T![date]
27+
| T![dec]
28+
| T![decimal]
29+
| T![double]
30+
| T![float]
31+
| T![int]
32+
| T![integer]
33+
| T![interval]
34+
| T![long]
35+
| T![national]
36+
| T![natural]
37+
| T![nchar]
38+
| T![nclob]
39+
| T![number]
40+
| T![numeric]
41+
| T![nvarchar2]
42+
| T![pls_integer]
43+
| T![quoted_ident]
44+
| T![raw]
45+
| T![real]
46+
| T![rowid]
47+
| T![smallint]
48+
| T![string]
49+
| T![timestamp]
50+
| T![unquoted_ident]
51+
| T![urowid]
52+
| T![varchar2]
53+
| T![varchar] => {
54+
parse_datatype(p);
55+
true
56+
}
57+
_ => false,
58+
}
59+
}
60+
1561
/// Parses a complete datatype.
1662
pub fn parse_datatype(p: &mut Parser) {
1763
p.start(SyntaxKind::Datatype);

0 commit comments

Comments
 (0)