extern int symbol_unbind(const struct scope *scope, const char *identifier);
extern struct symbol *symbol_lookup(const struct scope *scope,
const char *identifier);
+struct symbol *symbol_lookup_fuzzy(const struct scope *scope,
+ const char *identifier);
struct symbol *symbol_get(const struct scope *scope, const char *identifier);
enum table_flags {
sym = symbol_get(scope, $2);
if (!sym) {
- erec_queue(error(&@2, "unknown identifier '%s'", $2),
- state->msgs);
+ sym = symbol_lookup_fuzzy(scope, $2);
+ if (sym) {
+ erec_queue(error(&@2, "unknown identifier '%s'; "
+ "did you mean identifier ‘%s’?",
+ $2, sym->identifier),
+ state->msgs);
+ } else {
+ erec_queue(error(&@2, "unknown identifier '%s'", $2),
+ state->msgs);
+ }
xfree($2);
YYERROR;
}
return NULL;
}
+struct symbol *symbol_lookup_fuzzy(const struct scope *scope,
+ const char *identifier)
+{
+ struct string_misspell_state st;
+ struct symbol *sym;
+
+ string_misspell_init(&st);
+
+ while (scope != NULL) {
+ list_for_each_entry(sym, &scope->symbols, list)
+ string_misspell_update(sym->identifier, identifier,
+ sym, &st);
+
+ scope = scope->parent;
+ }
+ return st.obj;
+}
+
static const char * const chain_type_str_array[] = {
"filter",
"nat",