Browse Source

Tokenize Comma

github-actions
Garrit Franke 3 years ago
parent
commit
213924bc3d
  1. 2
      examples/hello_world.sb
  2. 2
      examples_out/out.js
  3. 1
      src/lexer/mod.rs
  4. 5
      src/parser/mod.rs
  5. 1
      src/parser/tests.rs

2
examples/hello_world.sb

@ -1,5 +1,5 @@
fn main() {
foo(2);
foo(2, 1);
}
fn foo(x) {

2
examples_out/out.js

@ -1,5 +1,5 @@
function main() {
foo(2)
foo(2,1)
}
function foo(x) {
return x

1
src/lexer/mod.rs

@ -172,6 +172,7 @@ impl Cursor<'_> {
},
':' => Colon,
';' => SemiColon,
',' => Comma,
'<' => SmallerThen,
'>' => LargerThen,
'(' => BraceOpen,

5
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()?)
}

1
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() {

Loading…
Cancel
Save