From 213924bc3db2f3c2c6a8f1c52c1c69c11955d085 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Sun, 6 Dec 2020 15:47:15 +0100 Subject: [PATCH] Tokenize Comma --- examples/hello_world.sb | 2 +- examples_out/out.js | 2 +- src/lexer/mod.rs | 1 + src/parser/mod.rs | 5 ++++- src/parser/tests.rs | 1 - 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/hello_world.sb b/examples/hello_world.sb index 4101960..a9f36ba 100644 --- a/examples/hello_world.sb +++ b/examples/hello_world.sb @@ -1,5 +1,5 @@ fn main() { - foo(2); + foo(2, 1); } fn foo(x) { diff --git a/examples_out/out.js b/examples_out/out.js index de93608..a2f284f 100644 --- a/examples_out/out.js +++ b/examples_out/out.js @@ -1,5 +1,5 @@ function main() { -foo(2) +foo(2,1) } function foo(x) { return x diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index 42deb64..fa82527 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -172,6 +172,7 @@ impl Cursor<'_> { }, ':' => Colon, ';' => SemiColon, + ',' => Comma, '<' => SmallerThen, '>' => LargerThen, '(' => BraceOpen, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 02075f8..df4b84d 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -241,7 +241,10 @@ impl Parser { let next = self.peek().ok_or_else(|| "Can not peek token")?; match &next.kind { TokenKind::BraceClose => break, - TokenKind::Comma => continue, + TokenKind::Comma => { + self.next(); + continue; + } TokenKind::Identifier(_) | TokenKind::Literal(_) => { args.push(self.parse_expression()?) } diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 00b1570..3e2bc06 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -120,7 +120,6 @@ fn test_parse_return_function_call() { } #[test] -#[ignore] fn test_parse_function_call_multiple_arguments() { let raw = " fn main() {