Skip to content

Commit 25d8b0c

Browse files
committed
feat: parse return, break and continue statements
1 parent bd01b26 commit 25d8b0c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/engine/src/parser/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ impl<'a> Parser<'a> {
105105
Match => self.stmt_match()?,
106106
For => self.stmt_for()?,
107107
While => self.stmt_while()?,
108+
Return => self.stmt_return()?,
109+
Break => Some(Statement::Break),
110+
Continue => Some(Statement::Continue),
108111
EOF | EOL => return Ok(None),
109112

110113
_ => {
@@ -242,6 +245,15 @@ impl<'a> Parser<'a> {
242245
Ok(Some(Statement::While(Box::from((condition, block)))))
243246
}
244247

248+
// MARK: Return
249+
fn stmt_return(&mut self) -> ParserResult<Option<Statement>> {
250+
self.expect_token(&LexerTokenKind::Return)?;
251+
252+
let value = self.expression()?;
253+
254+
Ok(Some(Statement::Return(Box::from(value))))
255+
}
256+
245257
fn expression(&mut self) -> ParserResult<Option<WithCursor<Expression>>> {
246258
self.expr_assignment()
247259
}

script.tsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
for i in 0..5 {
22
while true {
3-
aaa
3+
return true
44
}
55
}

0 commit comments

Comments
 (0)