37# include <gtest/gtest.h>
50 " let z = add(x, y);\n"
58 auto *
module = parser.parse_module();
65 const auto *
fn =
module->functions.access(0);
75 ASSERT_EQ(
fn->body->statements.access(0)->kind, Compiler_Stmt_Kind::Let);
85 ASSERT_EQ(
fn->body->statements.access(1)->kind, Compiler_Stmt_Kind::Return);
115 auto *
module = parser.parse_module();
119 ASSERT_EQ(module->statements.size(), 2u);
122 ASSERT_EQ(module->statements.access(0)->kind, Compiler_Stmt_Kind::Let);
127 ASSERT_EQ(module->statements.access(1)->kind, Compiler_Stmt_Kind::While);
142 "fn id(x: T) -> T {\n"
143 " let alias: fn(T) -> T = id;\n"
144 " return alias(x);\n"
151 auto *
module = parser.parse_module();
157 const auto *
fn =
module->functions.access(0);
159 ASSERT_NE(
fn->parameters.access(0).annotation,
nullptr);
160 EXPECT_EQ(
fn->parameters.access(0).annotation->kind, Compiler_Type_Expr_Kind::Named);
162 EXPECT_EQ(
fn->return_annotation->kind, Compiler_Type_Expr_Kind::Named);
173 EXPECT_EQ(
fn_type->parameters.access(0)->kind, Compiler_Type_Expr_Kind::Named);
179 EXPECT_NE(
dump.find(
"Let(alias): fn(T) -> T"), std::string::npos);
192 "enum Color { Red, Green, Blue, }\n"
193 "type UserId = Int;\n");
199 auto *
module = parser.parse_module();
202 ASSERT_EQ(module->type_declarations.size(), 3u);
205 const auto * point =
static_cast<const Compiler_Struct_Decl *
>(
module->type_declarations.access(0));
206 ASSERT_EQ(point->kind, Compiler_Type_Decl_Kind::Struct);
208 EXPECT_EQ(point->fields.access(0).name,
"x");
209 EXPECT_EQ(point->fields.access(1).name,
"y");
226 EXPECT_NE(
dump.find(
"TypeAlias(UserId) = Int"), std::string::npos);
235 "import \"math.aw\";\n"
236 "import \"types.aw\";\n"
237 "fn use() { return value; }\n");
243 auto *
module = parser.parse_module();
248 EXPECT_EQ(module->source_name,
"main.aw");
249 EXPECT_EQ(module->imports.access(0)->module_name,
"math.aw");
250 EXPECT_EQ(module->imports.access(1)->module_name,
"types.aw");
253 EXPECT_NE(
dump.find(
"Import(\"math.aw\")"), std::string::npos);
254 EXPECT_NE(
dump.find(
"Import(\"types.aw\")"), std::string::npos);
270 auto *
module = parser.parse_module();
273 ASSERT_EQ(module->statements.size(), 1u);
289 auto *
module = parser.parse_module();
292 ASSERT_EQ(module->statements.size(), 1u);
296 ASSERT_EQ(module->statements.access(0)->kind, Compiler_Stmt_Kind::Let);
313 auto *
module = parser.parse_module();
317 EXPECT_EQ(module->statements.size(), 0u);
Recursive-descent parser for the compiler-support MVP grammar.
Arena-backed ownership context for AST nodes.
Recursive-descent parser that produces an AST in Compiler_Ast_Context.
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.
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.
std::string compiler_dump_module(const Compiler_Module *module)
Dumps a parsed module in a deterministic text format.
std::string compiler_dump_function(const Compiler_Function_Decl *fn)
Dumps a function declaration in a deterministic text format.
static long & color(typename GT::Node *p)
Node representing an infix binary operation.
Node representing a function or method call.
Nominal top-level enum declaration with unit variants.
Function type syntax such as fn(Int, T) -> Bool.
Node representing a local variable binding.
Parser configuration knobs for the MVP grammar.
bool allow_top_level_statements
If false, only top-level declarations are accepted.
Node representing a return from the current function.
Nominal top-level struct declaration.
Transparent top-level type alias declaration.
Node representing a while-loop.
std::string code
Optional stable code such as E001.