37# include <gtest/gtest.h>
48 std::vector<Compiler_Token_Kind>
51 std::vector<Compiler_Token_Kind>
kinds;
56 if (
tok.is_eof()
or tok.is_invalid())
68 "fn add(x, y) { return x + 42; }\n");
72 const auto t0 = lexer.
next();
73 const auto t1 = lexer.
next();
74 const auto t2 = lexer.
next();
75 const auto t3 = lexer.
next();
76 const auto t4 = lexer.
next();
77 const auto t5 = lexer.
next();
78 const auto t6 = lexer.
next();
79 const auto t7 = lexer.
next();
80 const auto t8 = lexer.
next();
81 const auto t9 = lexer.
next();
89 EXPECT_EQ(
t1.kind, Compiler_Token_Kind::Identifier);
94 EXPECT_EQ(
t3.kind, Compiler_Token_Kind::Identifier);
97 EXPECT_EQ(
t5.kind, Compiler_Token_Kind::Identifier);
101 EXPECT_EQ(
t8.kind, Compiler_Token_Kind::Kw_Return);
102 EXPECT_EQ(
t9.kind, Compiler_Token_Kind::Identifier);
104 EXPECT_EQ(
t11.kind, Compiler_Token_Kind::Integer_Literal);
119 const auto id =
sm.
add_virtual_file(
"types.aw",
"struct Point {} enum Color {} type UserId = Int;");
122 const auto t0 = lexer.
next();
123 const auto t1 = lexer.
next();
124 const auto t2 = lexer.
next();
125 const auto t3 = lexer.
next();
126 const auto t4 = lexer.
next();
127 const auto t5 = lexer.
next();
128 const auto t6 = lexer.
next();
129 const auto t7 = lexer.
next();
130 const auto t8 = lexer.
next();
131 const auto t9 = lexer.
next();
136 EXPECT_EQ(
t0.kind, Compiler_Token_Kind::Kw_Struct);
137 EXPECT_EQ(
t1.kind, Compiler_Token_Kind::Identifier);
139 EXPECT_EQ(
t5.kind, Compiler_Token_Kind::Identifier);
141 EXPECT_EQ(
t9.kind, Compiler_Token_Kind::Identifier);
172 "let x = 1; // note\n/* block */ return x;");
177 const std::vector<Compiler_Token_Kind>
expected = {
178 Compiler_Token_Kind::Kw_Let,
179 Compiler_Token_Kind::Identifier,
180 Compiler_Token_Kind::Assign,
181 Compiler_Token_Kind::Integer_Literal,
182 Compiler_Token_Kind::Semicolon,
183 Compiler_Token_Kind::Kw_Return,
184 Compiler_Token_Kind::Identifier,
185 Compiler_Token_Kind::Semicolon,
186 Compiler_Token_Kind::End_Of_File
202 const auto t0 = lexer.
next();
203 const auto t1 = lexer.
next();
204 const auto t2 = lexer.
next();
206 EXPECT_EQ(
t0.kind, Compiler_Token_Kind::Line_Comment);
208 EXPECT_EQ(
t1.kind, Compiler_Token_Kind::Block_Comment);
223 const std::vector<Compiler_Token_Kind>
expected = {
224 Compiler_Token_Kind::Slash,
225 Compiler_Token_Kind::Star,
226 Compiler_Token_Kind::Identifier,
227 Compiler_Token_Kind::Star,
228 Compiler_Token_Kind::Slash,
229 Compiler_Token_Kind::End_Of_File
243 const auto t0 = lexer.
next();
244 const auto t1 = lexer.
next();
245 const auto t2 = lexer.
next();
246 const auto t3 = lexer.
next();
247 const auto t4 = lexer.
next();
248 const auto t5 = lexer.
next();
249 const auto t6 = lexer.
next();
251 EXPECT_EQ(
t0.kind, Compiler_Token_Kind::Char_Literal);
253 EXPECT_EQ(
t1.kind, Compiler_Token_Kind::String_Literal);
Lexical analyzer (Lexer) based on Source_Manager.
Token generator for a single source file.
Source_Offset current_offset() const noexcept
Returns the current byte offset in the file.
Compiler_Token next()
Consumes and returns the next token from the stream.
bool eof()
Indicates whether the end of the file has been reached.
const Compiler_Token & peek()
Peeks at the next token without advancing the cursor.
Source_File_Id source_file_id() const noexcept
Returns the file ID currently being analyzed.
void reset(const Source_Offset offset=0)
Repositions the reading cursor.
Diagnostic accumulator and renderer.
bool has_errors() const noexcept
Returns whether any error or fatal diagnostic was emitted.
const Diagnostic & get(const size_t i) const
Returns diagnostic i.
size_t size() const noexcept
Returns the number of stored diagnostics.
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.
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().
Main namespace for Aleph-w library functions.
void next()
Advance all underlying iterators (bounds-checked).
Configuration options for lexer behavior.
bool allow_block_comments
If false, /* is treated as / followed by *.
bool keep_comments
If true, comments are returned as tokens.
std::string code
Optional stable code such as E001.
std::string message
Main headline message.