From 6276d97c6b532231140d5c0d27f99b6f5a89dc66 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sat, 20 Dec 2025 01:10:56 +0300 Subject: [PATCH] Add type identifier source locations --- backlog.txt | 2 +- examples/test.psl | 2 +- libs/ast/source/resolve_identifiers.cpp | 3 +-- libs/parser/rules/pslang.y | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backlog.txt b/backlog.txt index e3c7632..804a288 100644 --- a/backlog.txt +++ b/backlog.txt @@ -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? diff --git a/examples/test.psl b/examples/test.psl index 4749d3d..8988c9e 100644 --- a/examples/test.psl +++ b/examples/test.psl @@ -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)) diff --git a/libs/ast/source/resolve_identifiers.cpp b/libs/ast/source/resolve_identifiers.cpp index 9dd3c9d..5999a3b 100644 --- a/libs/ast/source/resolve_identifiers.cpp +++ b/libs/ast/source/resolve_identifiers.cpp @@ -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) diff --git a/libs/parser/rules/pslang.y b/libs/parser/rules/pslang.y index e8f9ea3..7bba141 100644 --- a/libs/parser/rules/pslang.y +++ b/libs/parser/rules/pslang.y @@ -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($1), std::stoull($3)}; } | type_expression arrow type_expression { std::vector args; args.push_back(std::make_unique($1)); $$ = ast::function_type{std::move(args), std::make_unique($3)}; } | lparen function_paren_type_list rparen arrow type_expression { $$ = ast::function_type{$2, std::make_unique($5)}; }