- /* The only "good" case is here. */
- unsigned symbol_index = variant_table[0].index;
- if (symbol_index == midrule_rhs_index)
- return LHS_REF;
- else
- return symbol_index;
- }
-
- /* Start complaining. */
-
- if (variant_count == 0)
- complain_at (text_loc, _("invalid reference: %s, symbol not found"),
- quote (text));
- else if (variant_count > 1 && !has_error)
- complain_at (text_loc, _("ambiguous reference: %s"),
- quote (text));
- else if (variant_count > 1 && has_valid && has_error)
- complain_at (text_loc, _("misleading reference: %s"),
- quote (text));
- else
- complain_at (text_loc, _("invalid reference: %s"),
- quote (text));
-
- for (i = 0; i < variant_count; ++i)
- {
- const variant *var = &variant_table[i];
- const char *at_spec = get_at_spec (var->index);
-
- if (var->err == 0)
- complain_at (var->loc, _(" refers to: %c%s at %s"),
- dollar_or_at, var->id, at_spec);
- else
- {
- static struct obstack msg_buf;
- const char *tail = exact_mode ? "" :
- cp + strlen (var->id);
- const char *id = var->hidden_by ? var->hidden_by->id :
- var->id;
- location id_loc = var->hidden_by ? var->hidden_by->loc :
- var->loc;
-
- /* Create the explanation message. */
- obstack_init (&msg_buf);
-
- obstack_fgrow1 (&msg_buf, " possibly meant: %c", dollar_or_at);
- if (contains_dot_or_dash (id))
- obstack_fgrow1 (&msg_buf, "[%s]", id);
- else
- obstack_sgrow (&msg_buf, id);
- obstack_sgrow (&msg_buf, tail);
-
- if (var->err & VARIANT_HIDDEN)
- {
- obstack_fgrow1 (&msg_buf, ", hiding %c", dollar_or_at);
- if (contains_dot_or_dash (var->id))
- obstack_fgrow1 (&msg_buf, "[%s]", var->id);
- else
- obstack_sgrow (&msg_buf, var->id);
- obstack_sgrow (&msg_buf, tail);
- }
-
- obstack_fgrow1 (&msg_buf, " at %s", at_spec);
-
- if (var->err & VARIANT_NOT_VISIBLE_FROM_MIDRULE)
- obstack_fgrow1 (&msg_buf, ", cannot be accessed from "
- "mid-rule action at $%d", midrule_rhs_index);
-
- obstack_1grow (&msg_buf, '\0');
- complain_at (id_loc, _("%s"), (char *) obstack_finish (&msg_buf));
- obstack_free (&msg_buf, 0);
- }
+ case 0:
+ {
+ unsigned len = (explicit_bracketing || !ref_tail_fields) ?
+ cp_end - cp : ref_tail_fields - cp;
+ unsigned indent = 0;
+
+ complain_at_indent (text_loc, &indent, _("invalid reference: %s"),
+ quote (text));
+ indent += SUB_INDENT;
+ if (len == 0)
+ {
+ location sym_loc = text_loc;
+ sym_loc.start.column += 1;
+ sym_loc.end = sym_loc.start;
+ const char *format =
+ _("syntax error after '%c', expecting integer, letter,"
+ " '_', '[', or '$'");
+ complain_at_indent (sym_loc, &indent, format, dollar_or_at);
+ }
+ else if (midrule_rhs_index)
+ {
+ const char *format =
+ _("symbol not found in production before $%d: %.*s");
+ complain_at_indent (rule->location, &indent, format,
+ midrule_rhs_index, len, cp);
+ }
+ else
+ {
+ const char *format =
+ _("symbol not found in production: %.*s");
+ complain_at_indent (rule->location, &indent, format,
+ len, cp);
+ }
+
+ if (variant_count > 0)
+ show_sub_messages (cp, explicit_bracketing, midrule_rhs_index,
+ dollar_or_at, false, indent);
+ return INVALID_REF;
+ }
+ case 1:
+ {
+ unsigned indent = 0;
+ if (variant_count > 1)
+ {
+ warn_at_indent (text_loc, &indent, _("misleading reference: %s"),
+ quote (text));
+ show_sub_messages (cp, explicit_bracketing, midrule_rhs_index,
+ dollar_or_at, true, indent + SUB_INDENT);
+ }
+ {
+ unsigned symbol_index =
+ variant_table[valid_variant_index].symbol_index;
+ return (symbol_index == midrule_rhs_index) ? LHS_REF : symbol_index;
+ }
+ }
+ case 2:
+ default:
+ {
+ unsigned indent = 0;
+ complain_at_indent (text_loc, &indent, _("ambiguous reference: %s"),
+ quote (text));
+ show_sub_messages (cp, explicit_bracketing, midrule_rhs_index,
+ dollar_or_at, false, indent + SUB_INDENT);
+ return INVALID_REF;
+ }