diff --git a/TODO b/TODO index 4d28a40..8b60439 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,6 @@ # Bugs - Uninitialized variables don't compile +- stdlib moves line of file, which makes error reporting impossible # Features - For loop diff --git a/examples/ackermann.sb b/examples/ackermann.sb new file mode 100644 index 0000000..64ffc09 --- /dev/null +++ b/examples/ackermann.sb @@ -0,0 +1,15 @@ +fn main() { + let m = 3 + let n = 3 + println(ackermann(m, n)) +} + +fn ackermann(m, n) { + if m == 0 { + return n + 1 + } else if n == 0 { + return ackermann(m - 1, 1) + } else { + return ackermann(m - 1, ackermann(m, n - 1)) + } +} \ No newline at end of file diff --git a/src/parser/rules.rs b/src/parser/rules.rs index d968118..91042fc 100644 --- a/src/parser/rules.rs +++ b/src/parser/rules.rs @@ -79,6 +79,9 @@ impl Parser { while let Err(_) = self.peek_token(TokenKind::BraceClose) { let next = self.next()?; match next.kind { + TokenKind::Comma => { + continue; + } TokenKind::Identifier(name) => args.push(Variable { name: name }), _ => return Err(self.make_error(TokenKind::Identifier("Argument".into()), next)), } diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 1a95b62..255db51 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -530,3 +530,27 @@ fn test_uninitialized_variables() { let tree = parse(tokens, Some(raw.to_string())); assert!(tree.is_ok()) } + +#[test] +fn test_function_call_math() { + let raw = " + fn main(m) { + main(m - 1) + } + "; + let tokens = tokenize(raw); + let tree = parse(tokens, Some(raw.to_string())); + assert!(tree.is_ok()) +} + +#[test] +fn test_function_multiple_args() { + let raw = " + fn main(m, n) { + main(m, n) + } + "; + let tokens = tokenize(raw); + let tree = parse(tokens, Some(raw.to_string())); + assert!(tree.is_ok()) +}