From 705a2bb2f43b988ee359fd5fb305bf54363c6240 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Tue, 30 Mar 2021 10:10:47 +0200 Subject: [PATCH] :art: Improve dym --- include/env/env.h | 17 ++++++++--------- src/parse/check.c | 2 +- src/parse/did_you_mean.c | 12 +++++++++--- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/env/env.h b/include/env/env.h index 63be0aab..0962ba9e 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -5,17 +5,16 @@ #define NSPC(a) { nspc_push_value(env->curr); SCOPE(a); nspc_pop_value(env->curr); } struct Env_Scope_ { - struct Vector_ nspc_stack; - struct Vector_ class_stack; - struct Vector_ breaks; - struct Vector_ conts; - struct Vector_ known_ctx; - struct Match_ *match; + struct Vector_ nspc_stack; + struct Vector_ class_stack; + struct Vector_ breaks; + struct Vector_ conts; + struct Vector_ known_ctx; + struct Match_ *match; size_t depth; }; -typedef struct Env_ * Env; -struct Env_ { +typedef struct Env_ { m_str name; Nspc curr; Nspc global_nspc; @@ -24,7 +23,7 @@ struct Env_ { Func func; struct Gwion_ *gwion; struct Env_Scope_* scope; -}; +} *Env; ANEW Env new_env(MemPool); ANN void env_reset(const Env); diff --git a/src/parse/check.c b/src/parse/check.c index 2a4578d4..82c2b10a 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -289,7 +289,7 @@ ANN static Type prim_id_non_res(const Env env, const Symbol *data) { const Symbol sym = *data; const Value v = check_non_res_value(env, data); if(!v || !vflag(v, vflag_valid) || (v->from->ctx && v->from->ctx->error)) { - gwerr_basic(_("Invalid variable"), _("not legit at this point."), "did you mean:", + gwerr_basic(_("Invalid variable"), _("not legit at this point."), NULL, env->name, prim_pos(data), 0); did_you_mean_nspc(v ? value_owner(env, v) : env->curr, s_name(sym)); env->context->error++; diff --git a/src/parse/did_you_mean.c b/src/parse/did_you_mean.c index b8b3d2e8..2d724d6b 100644 --- a/src/parse/did_you_mean.c +++ b/src/parse/did_you_mean.c @@ -32,13 +32,17 @@ static m_bool wagner_fisher(const char *s, const char* t) { return (i && j && d[m-1][n-1] < MAX_DISTANCE); } -ANN static void ressembles(const Vector v, const Nspc nspc, const char* name) { +ANN static void ressembles(const Vector v, const Nspc nspc, const char* name, bool *const done) { struct scope_iter iter = { nspc->info->value, 0, 0 }; Value value; while(scope_iter(&iter, &value) > 0) { if(vector_find(v, (vtype)value->name) > 0 &&!strcmp(name, value->name)) continue; if(wagner_fisher(name, value->name)) { + if(!*done) { + *done = true; + gw_err("{-/}did you mean{0}:"); + } if(!vflag(value, vflag_builtin)) gwerr_secondary("declared here", value->from->filename, value->from->loc); } @@ -54,7 +58,8 @@ ANN void did_you_mean_nspc(Nspc nspc, const char* name) { CHECK_LEN(name) struct Vector_ v; vector_init(&v); - do ressembles(&v, nspc, name); + bool done; + do ressembles(&v, nspc, name, &done); while((nspc = nspc->parent)); vector_release(&v); } @@ -65,7 +70,8 @@ ANN void did_you_mean_type(Type type, const char* name) { Type t = type; struct Vector_ v; vector_init(&v); - do ressembles(&v, t->nspc, name); + bool done; + do ressembles(&v, t->nspc, name, &done); while((t = t->info->parent) && t->nspc); vector_release(&v); } -- 2.43.0