diff options
| author | Mel <einebeere@gmail.com> | 2022-03-03 02:30:46 +0100 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-03-03 02:30:46 +0100 |
| commit | f5bb7bbd8824a20c991587d5a774644aa98241d9 (patch) | |
| tree | c8729e0e1a04f2c924b5351f57fb9b2ec18d4633 /src/parse/parser.rs | |
| parent | 8f7e3d1d2cd43d30ccc16799fcf69058ccc5a717 (diff) | |
| download | rabbithole-f5bb7bbd8824a20c991587d5a774644aa98241d9.tar.zst rabbithole-f5bb7bbd8824a20c991587d5a774644aa98241d9.zip | |
Diffstat (limited to 'src/parse/parser.rs')
| -rw-r--r-- | src/parse/parser.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/parse/parser.rs b/src/parse/parser.rs index f19dcf1..a9baf7a 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -51,11 +51,16 @@ impl<T: Iterator<Item = Token>> Parser<T> { fn return_statement(&mut self) -> Result<Statement, ParserError> { let return_token = consume!(self, KeywordReturn)?; - let expression = self.expression()?; - consume!(self, SemiColon)?; + let returned = if consume_if!(self, SemiColon).is_none() { + let expression = self.expression()?; + consume!(self, SemiColon)?; + Some(expression) + } else { + None + }; Ok(Statement { at: return_token.location, - kind: StatementKind::Return(expression), + kind: StatementKind::Return(returned), }) } |
