srctree

Robin Linden parent 01abf619 a69febc2
js: Support tokenizing commas

inlinesplit
js/tokenizer.h added: 14, removed: 2, total 12
@@ -37,6 +37,10 @@ struct Semicolon {
bool operator==(Semicolon const &) const = default;
};
 
struct Comma {
bool operator==(Comma const &) const = default;
};
 
struct Eof {
bool operator==(Eof const &) const = default;
};
@@ -47,6 +51,7 @@ using Token = std::variant< //
LParen,
RParen,
Semicolon,
Comma,
Eof>;
 
class Tokenizer {
@@ -69,6 +74,8 @@ public:
return RParen{};
case ';':
return Semicolon{};
case ',':
return Comma{};
default:
break;
}
 
js/tokenizer_test.cpp added: 14, removed: 2, total 12
@@ -41,5 +41,10 @@ int main() {
expect_eq(tokenize("func( 9 )"), Tokens{Identifier{"func"}, LParen{}, IntLiteral{9}, RParen{}, Eof{}});
});
 
etest::test("function call w/ multiple arguments", [] {
expect_eq(tokenize("nh(5, 20)"),
Tokens{Identifier{"nh"}, LParen{}, IntLiteral{5}, Comma{}, IntLiteral{20}, RParen{}, Eof{}});
});
 
return etest::run_all_tests();
}