Add type identifier source locations

This commit is contained in:
Nikita Lisitsa 2025-12-20 01:10:56 +03:00
parent 709c7a7a0a
commit 6276d97c6b
4 changed files with 4 additions and 5 deletions

View file

@ -1,2 +1,2 @@
* Mutually recursive functions
* Type identifier location
* Figure out indentation: keep tabs - what to do with printing errors? Enforce e.g. 4 spaces?

View file

@ -2,7 +2,7 @@ struct vec2:
x : f32
y : f32
func add(a : vec2, b : vec2) -> vec2:
func add(a : vec2, b : vec2) -> qwe:
return vec2(a.x + b.x, a.y + b.y)
mut v = add(vec2(1.0, 2.0), vec2(3.0, 4.0))

View file

@ -90,8 +90,7 @@ namespace pslang::ast
}
}
// TODO location
throw parse_error("Identifier \"" + identifier.name + "\" not found", {});
throw parse_error("Identifier \"" + identifier.name + "\" not found", identifier.location);
}
void resolve_identifiers(context & context, type & type)

View file

@ -227,7 +227,7 @@ variable_keyword
type_expression
: unit { $$ = types::unit_type{}; }
| primitive_type { $$ = ast::type($1); }
| name { $$ = ast::type_identifier{$1}; }
| name { $$ = ast::type_identifier{$1, @$}; }
| type_expression lbracket lit_i32 rbracket { $$ = ast::array_type{std::make_unique<ast::type>($1), std::stoull($3)}; }
| type_expression arrow type_expression { std::vector<ast::type_ptr> args; args.push_back(std::make_unique<ast::type>($1)); $$ = ast::function_type{std::move(args), std::make_unique<ast::type>($3)}; }
| lparen function_paren_type_list rparen arrow type_expression { $$ = ast::function_type{$2, std::make_unique<ast::type>($5)}; }