Skip to content

Commit

Permalink
libnixf: fix lexer float trailing e args (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Jan 20, 2024
1 parent 7fe6b8a commit 8a8d1ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libnixf/src/Parse/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ std::optional<char> Lexer::consumeOneOf(std::string_view Chars) {
if (eof())
return std::nullopt;
if (Chars.find(peekUnwrap()) != std::string_view::npos) {
char Ret = peekUnwrap();
consume();
return peek();
return Ret;
}
return std::nullopt;
}
Expand Down
20 changes: 20 additions & 0 deletions libnixf/test/Parse/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ TEST_F(LexerTest, FloatLeadingZero) {
ASSERT_EQ(std::string(Diags[0].args()[0]), "00");
}

TEST_F(LexerTest, FloatNoExp_little) {
Lexer Lexer("0.33e", Diags);
auto P = Lexer.lex();
ASSERT_EQ(P.kind(), tok_float);
ASSERT_EQ(P.view(), "0.33e");
ASSERT_FALSE(Diags.empty());
ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_FloatNoExp);
ASSERT_EQ(std::string(Diags[0].args()[0]), "e");
}

TEST_F(LexerTest, FloatNoExp_big) {
Lexer Lexer("0.33E", Diags);
auto P = Lexer.lex();
ASSERT_EQ(P.kind(), tok_float);
ASSERT_EQ(P.view(), "0.33E");
ASSERT_FALSE(Diags.empty());
ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_FloatNoExp);
ASSERT_EQ(std::string(Diags[0].args()[0]), "E");
}

TEST_F(LexerTest, lexString) {
Lexer Lexer(R"("aa bb \\ \t \" \n ${}")", Diags);
const TokenKind Match[] = {
Expand Down

0 comments on commit 8a8d1ac

Please sign in to comment.