36#include <gtest/gtest.h>
42TEST(CompilerParserUtils, ClassifiesParserEntryPoints)
57TEST(CompilerParserUtils, UnquotesStringLiteralTokens)
64 const Compiler_Token identifier{Compiler_Token_Kind::Identifier,
"math", {}};
68TEST(CompilerParserUtils, ParsesSeparatedIdentifierListsWithoutAstSupport)
71 const auto file_id = sm.
add_virtual_file(
"params.aw",
"left, right, total)");
78 Compiler_Token_Kind::RParen,
82 stream.expect_identifier(
"in parameter list").lexeme);
86 ASSERT_EQ(names.
size(), 3u);
87 EXPECT_EQ(names.
access(0),
"left");
88 EXPECT_EQ(names.
access(1),
"right");
89 EXPECT_EQ(names.
access(2),
"total");
90 EXPECT_EQ(stream.
peek().
kind, Compiler_Token_Kind::RParen);
94TEST(CompilerParserUtils, AcceptsTrailingSeparatorWhenRequested)
104 Compiler_Token_Kind::RBrace,
108 stream.expect_identifier(
"in enum variant list").lexeme);
113 ASSERT_EQ(names.
size(), 2u);
114 EXPECT_EQ(names.
access(0),
"Red");
115 EXPECT_EQ(names.
access(1),
"Green");
116 EXPECT_EQ(stream.
peek().
kind, Compiler_Token_Kind::RBrace);
120TEST(CompilerParserUtils, SynchronizesToNextStatementStart)
123 const auto file_id = sm.
add_virtual_file(
"recover.aw",
"1 2 let value = 3;");
128 EXPECT_EQ(stream.
next().
kind, Compiler_Token_Kind::Integer_Literal);
130 EXPECT_EQ(stream.
peek().
kind, Compiler_Token_Kind::Kw_Let);
Reusable token-stream helpers for recursive-descent frontends.
Token generator for a single source file.
Lightweight token stream facade for recursive-descent parsers.
bool parse_separated_list(const Compiler_Token_Kind separator, const Compiler_Token_Kind terminator, Parse_Item &&parse_item, const bool allow_trailing_separator=false)
Parses one separated list until a terminator token is reached.
void synchronize_statement()
Skips tokens until a statement boundary suitable for recovery.
Compiler_Token peek()
Returns the next token without consuming it.
Compiler_Token next()
Consumes and returns the next token.
Diagnostic accumulator and renderer.
bool has_errors() const noexcept
Returns whether any error or fatal diagnostic was emitted.
size_t size() const noexcept
Return the current dimension of array.
T & access(const size_t i) noexcept
Fast access without checking allocation and bound_min_clock checking.
Stores source files and resolves offsets into human-readable data.
Source_File_Id add_virtual_file(const std::string &name, const std::string &text)
Registers an in-memory source file.
Main namespace for Aleph-w library functions.
bool compiler_is_expression_start(const Compiler_Token_Kind kind) noexcept
Returns whether a token kind can start an expression in the MVP grammar.
bool compiler_is_top_level_declaration_start(const Compiler_Token_Kind kind) noexcept
Returns whether a token kind starts one top-level declaration.
bool compiler_is_statement_start(const Compiler_Token_Kind kind) noexcept
Returns whether a token kind can start a statement in the MVP grammar.
std::string compiler_unquote_string_token(const Compiler_Token &token)
Removes surrounding double quotes from one string-literal token.
Lexical token representation with its value and location.
Compiler_Token_Kind kind
Logical category (e.g., Kw_If).