36#ifndef COMPILER_TOKEN_H
37#define COMPILER_TOKEN_H
290namespace Compiler_Token_Detail {
294 escaped.reserve(text.size() + 8);
296 for (
const char ch : text)
330 return "End_Of_File";
334 return "Integer_Literal";
336 return "String_Literal";
338 return "Char_Literal";
340 return "Line_Comment";
342 return "Block_Comment";
356 return "Kw_Continue";
378 return "Kw_Namespace";
412 return "Double_Colon";
477 if (lexeme ==
"else")
479 if (lexeme ==
"while")
483 if (lexeme ==
"return")
485 if (lexeme ==
"break")
487 if (lexeme ==
"continue")
495 if (lexeme ==
"const")
497 if (lexeme ==
"type")
499 if (lexeme ==
"struct")
501 if (lexeme ==
"enum")
503 if (lexeme ==
"class")
505 if (lexeme ==
"import")
507 if (lexeme ==
"export")
509 if (lexeme ==
"namespace")
513 if (lexeme ==
"catch")
515 if (lexeme ==
"throw")
517 if (lexeme ==
"true")
519 if (lexeme ==
"false")
691 std::ostringstream
out;
697 out <<
"<invalid-span>";
Source file and span management utilities for compiler-style tooling.
size_t size_t int32_t * out
Minimal std::expected-style result type for C++20.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
std::string escape_token_lexeme(std::string_view text)
Main namespace for Aleph-w library functions.
Compiler_Token_Kind classify_compiler_keyword(std::string_view lexeme) noexcept
Classifies a lexeme as a keyword or Identifier.
bool compiler_token_is_keyword(Compiler_Token_Kind kind) noexcept
Predicate: Is the kind a reserved keyword?
@ Identifier
Variable or function name reference.
@ Integer_Literal
Numeric integer constant.
@ Char_Literal
Character constant.
@ String_Literal
String constant.
const char * compiler_token_kind_name(Compiler_Token_Kind kind)
Returns a human-readable name for a token kind.
@ Invalid
Uninitialized register/slot or explicit invalid placeholder.
int compiler_binary_precedence(Compiler_Token_Kind kind) noexcept
Returns binary precedence for an operator.
bool compiler_token_is_comment(Compiler_Token_Kind kind) noexcept
Predicate: Is the kind a comment?
Compiler_Associativity
Associativity metadata for binary operators.
@ None
The operator is not associative (e.g., chained comparators prohibited).
@ Right
Right-associative: a = (b = c).
@ Left
Left-associative: (a - b) - c.
bool compiler_token_is_literal(Compiler_Token_Kind kind) noexcept
Predicate: Is the kind a literal (number, string, bool, etc.)?
bool compiler_token_is_operator(Compiler_Token_Kind kind) noexcept
Predicate: Is the kind an operator (arithmetic, logical, etc.)?
Compiler_Token_Kind
Token kinds supported by the compiler MVP.
@ Line_Comment
Single-line comment (// ...).
@ Identifier
Named identifier (e.g., variable or function name).
@ Integer_Literal
Integer constant.
@ End_Of_File
End of the source stream.
@ Invalid
Sentinel for lexer errors or uninitialized tokens.
@ Char_Literal
Single character constant.
@ Block_Comment
Multi-line comment (/* ... *‍/).
@ String_Literal
String constant (with escape sequences).
Compiler_Associativity compiler_binary_associativity(Compiler_Token_Kind kind) noexcept
Returns binary associativity for an operator.
Lexical token representation with its value and location.
Source_Span span
Precise location in the source code.
Compiler_Token_Kind kind
Logical category (e.g., Kw_If).
bool is(const Compiler_Token_Kind expected) const noexcept
Fast kind check.
std::string lexeme
Exact text found in the source.
std::string to_string() const
Formats the token as a descriptive string for debugging.
bool is_invalid() const noexcept
Returns whether the token represents a lexical error.
bool is_eof() const noexcept
Returns whether the token marks the end of the file.
Represents a missing value.
Half-open byte range inside a source file.
bool is_valid() const noexcept
Returns whether the span belongs to a registered file.
std::string to_string() const
Formats the span as #file:[begin,end).