46 const auto file_id = sm.
add_virtual_file(
"demo.aw",
"fn add(left, right) {}");
51 (void) stream.
expect(Compiler_Token_Kind::Kw_Fn,
"expected 'fn'",
"EX001");
53 (void) stream.
expect(Compiler_Token_Kind::LParen,
"expected '('",
"EX003");
57 Compiler_Token_Kind::RParen,
64 (void) stream.
expect(Compiler_Token_Kind::RParen,
"expected ')'",
"EX005");
66 std::cout <<
"Function: " << name.
lexeme <<
'\n';
67 std::cout <<
"Params:";
68 for (
size_t i = 0; i < parameters.
size(); ++i)
69 std::cout <<
' ' << parameters.
access(i);
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.
Compiler_Token expect(const Compiler_Token_Kind kind, const std::string &message, const std::string &code, const std::string ¬e="", const std::string &help="")
Consumes a token of kind kind or emits one diagnostic error.
Compiler_Token expect_identifier(const std::string_view context, const std::string &code="PAR002")
Consumes one identifier token or emits one diagnostic error.
Diagnostic accumulator and renderer.
void render_plain(std::ostream &out) const
Renders all diagnostics as deterministic plain text.
size_t size() const noexcept
Returns the number of stored diagnostics.
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.
T & append()
Allocate a new entry to the end of array.
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.
std::string lexeme
Exact text found in the source.