diff options
| author | Mel <einebeere@gmail.com> | 2021-11-14 22:31:34 +0100 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2021-11-14 22:31:34 +0100 |
| commit | 2a3ab5c161ac98cb3c6326173e5ed78089a9ed68 (patch) | |
| tree | 2a25e0017f6b90f4296e1d9f5d10980a345e1373 /src/parse/parser.rs | |
| parent | 89fcc9a395f2aa9744d507d79d29aa117b89fa7e (diff) | |
| download | rabbithole-2a3ab5c161ac98cb3c6326173e5ed78089a9ed68.tar.zst rabbithole-2a3ab5c161ac98cb3c6326173e5ed78089a9ed68.zip | |
Function calling and the ensuing scope shenanigans
Diffstat (limited to 'src/parse/parser.rs')
| -rw-r--r-- | src/parse/parser.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 5a09a8f..ee83293 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -217,10 +217,10 @@ impl<T: Iterator<Item = Token>> Parser<T> { while let Some(token) = consume_if!(self, GroupOpen | ArrayOpen | Dot) { match token.variant { - GroupOpen => loop { + GroupOpen => { let mut arguments = Vec::new(); - loop { + while consume_if!(self, GroupClose).is_none() { arguments.push(self.expression()?); if consume_if!(self, Comma).is_none() { @@ -232,8 +232,8 @@ impl<T: Iterator<Item = Token>> Parser<T> { left = Expression::Call(Box::new(CallNode { called: left, arguments, - })) - }, + })); + } ArrayOpen => { let index = self.expression()?; consume!(self, ArrayClose)?; @@ -335,10 +335,9 @@ impl<T: Iterator<Item = Token>> Parser<T> { fn function(&mut self) -> Result<FnNode> { consume!(self, KeywordFn)?; - let token = self.tokens.next().expect("Expected function header."); let header = { - let has_self_receiver = if let KeywordSelf = token.variant { + let has_self_receiver = if consume_if!(self, KeywordSelf).is_some() { consume_if!(self, Comma); true } else { |
