37# include <gtest/gtest.h>
44TEST(CompilerToken, ClassifiesKeywordsAndPredicates)
50 Compiler_Token_Kind::Identifier);
68TEST(CompilerToken, PrecedenceAndAssociativityMatchParserMetadata)
80 Compiler_Associativity::Right);
82 Compiler_Associativity::Left);
84 Compiler_Associativity::None);
88TEST(CompilerToken, ToStringIncludesKindLexemeAndSpan)
91 tok.
kind = Compiler_Token_Kind::Identifier;
95 EXPECT_EQ(tok.
to_string(),
"Identifier(\"value\")@#1:[4,9)");
97 tok.
kind = Compiler_Token_Kind::String_Literal;
99 tok.
span = {1, 10, 16};
101 EXPECT_EQ(tok.
to_string(),
"String_Literal(\"\\\"hi\\\\n\\\"\")@#1:[10,16)");
Token model and parser-facing metadata for compiler front-ends.
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?
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?
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_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).
std::string lexeme
Exact text found in the source.
std::string to_string() const
Formats the token as a descriptive string for debugging.