43#ifndef COMPILER_PARSER_UTILS_H
44#define COMPILER_PARSER_UTILS_H
135 const std::string &
code,
136 const std::string ¬e =
"",
137 const std::string &help =
"")
const
143 if (
not note.empty())
145 if (
not help.empty())
186 const std::string &
code,
187 const std::string ¬e =
"",
188 const std::string &help =
"")
191 if (
tok.kind == kind)
195 return {kind,
"",
tok.span};
200 const std::string &
code =
"PAR002")
218 template <
typename Parse_Item>
224 if (
check(terminator))
Lexical analyzer (Lexer) based on Source_Manager.
Token generator for a single source file.
Compiler_Token next()
Consumes and returns the next token from the stream.
const Compiler_Token & peek()
Peeks at the next token without advancing the cursor.
Lightweight token stream facade for recursive-descent parsers.
void emit_error(const Source_Span &span, const std::string &message, const std::string &code, const std::string ¬e="", const std::string &help="") const
bool check(const Compiler_Token_Kind kind)
Returns whether the next token has the requested kind.
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_Parser_Stream(Compiler_Lexer &token_source, Diagnostic_Engine *dx=nullptr) noexcept
Builds one parser stream over an existing lexer.
bool match(const Compiler_Token_Kind kind)
Consumes the next token if it matches kind.
void synchronize_statement()
Skips tokens until a statement boundary suitable for recovery.
Compiler_Token peek()
Returns the next token without consuming it.
Diagnostic_Engine * diagnostics
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.
Compiler_Token next()
Consumes and returns the next token.
Diagnostic_Builder & code(const std::string &value)
Sets the stable diagnostic code.
size_t emit() const noexcept
Finalizes the builder and returns the diagnostic index.
Diagnostic_Builder & help(const std::string &msg)
Appends a help line.
Diagnostic_Builder & note(const std::string &msg)
Appends a note line.
Diagnostic accumulator and renderer.
Diagnostic_Builder error(const Source_Span &span, const std::string &msg)
Starts an error diagnostic.
static void separator(const string &title)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
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.
void message(const char *file, int line, const char *format,...)
Print an informational message with file and line info.
and
Check uniqueness with explicit hash + equality functors.
std::string code(Node *root)
Compute a string with the Lukasiewicz`s word of a tree.
bool compiler_is_top_level_declaration_start(const Compiler_Token_Kind kind) noexcept
Returns whether a token kind starts one top-level declaration.
Compiler_Token_Kind
Token kinds supported by the compiler MVP.
@ Identifier
Named identifier (e.g., variable or function name).
@ Integer_Literal
Integer constant.
@ Char_Literal
Single character constant.
@ String_Literal
String constant (with escape sequences).
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).
std::string lexeme
Exact text found in the source.
Half-open byte range inside a source file.