aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-02-06 12:27:34 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-02-06 12:27:34 +0100
commitc3b655bad99c1c4110d2af18b5b5845b4b2a65df (patch)
tree76628234ee07b5179097e29717e716edce52d41a /src
parent6dfe62f7c305588023e74d6077f629a076c4769b (diff)
downloadsylt-c3b655bad99c1c4110d2af18b5b5845b4b2a65df.tar.gz
use fancy macro in parse branches
Diffstat (limited to 'src')
-rw-r--r--src/compiler.rs19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index bd23cd8..914f720 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -371,16 +371,10 @@ impl Compiler {
}
fn grouping_or_tuple(&mut self, block: &mut Block) {
- let block_length = block.ops.len();
- let token_length = self.curr;
- if self.try_tuple(block).is_err() {
- block.ops.truncate(block_length);
- self.curr = token_length;
- self.grouping(block);
- }
+ parse_branch!(self, block, [self.tuple(block), self.grouping(block)]);
}
- fn try_tuple(&mut self, block: &mut Block) -> Result<(), ()> {
+ fn tuple(&mut self, block: &mut Block) {
expect!(self, Token::LeftParen, "Expected '(' at start of tuple");
let mut num_args = 0;
@@ -398,18 +392,21 @@ impl Compiler {
match self.peek() {
Token::Comma => { self.eat(); },
Token::RightParen => {},
- _ => { return Err(()); },
+ _ => {
+ error!(self, "Expected ',' or ')' in tuple");
+ return;
+ },
}
}
}
}
if num_args == 1 {
- return Err(());
+ error!(self, "A tuple must contain more than 1 element.");
+ return;
}
expect!(self, Token::RightParen, "Expected ')' after tuple.");
add_op(self, block, Op::Tuple(num_args));
- Ok(())
}
fn grouping(&mut self, block: &mut Block) {