- /* The only "good" case is here. */
- unsigned index = variant_table[0].index;
- if (index == midrule_rhs_index)
- return LHS_REF;
- else
- return index;
- }
-
- /* Start complaining. */
-
- if (variant_count == 0)
- complain_at (loc, _("invalid reference: %s, symbol not found"),
- quote (text));
- else if (variant_count > 1 && !has_error)
- complain_at (loc, _("ambiguous reference: %s"),
- quote (text));
- else if (variant_count > 1 && has_valid && has_error)
- complain_at (loc, _("misleading reference: %s"),
- quote (text));
- else
- complain_at (loc, _("invalid reference: %s"),
- quote (text));
-
- for (i = 0; i < variant_count; ++i)
- {
- const variant *variant = &variant_table[i];
- const char *at_spec = get_at_spec (variant->index);
-
- if (variant->err == 0)
- complain_at (variant->loc, _(" refers to: %c%s at %s"),
- dollar_or_at, variant->id, at_spec);
- else
- {
- static struct obstack msg_buf;
- const char *tail = exact_mode ? "" :
- cp + strlen (variant->id);
- const char *id = variant->hidden_by ? variant->hidden_by->id :
- variant->id;
- location loc = variant->hidden_by ? variant->hidden_by->loc :
- variant->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 (variant->err & VARIANT_HIDDEN)
- {
- obstack_fgrow1 (&msg_buf, ", hiding %c", dollar_or_at);
- if (contains_dot_or_dash (variant->id))
- obstack_fgrow1 (&msg_buf, "[%s]", variant->id);
- else
- obstack_sgrow (&msg_buf, variant->id);
- obstack_sgrow (&msg_buf, tail);
- }
-
- obstack_fgrow1 (&msg_buf, " at %s", at_spec);
-
- if (variant->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 (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, complaint, &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, complaint, &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, complaint, &indent, format,
+ midrule_rhs_index, len, cp);
+ }
+ else
+ {
+ const char *format =
+ _("symbol not found in production: %.*s");
+ complain_at_indent (rule->location, complaint, &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)
+ {
+ complain_at_indent (text_loc, Wother, &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, complaint, &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;
+ }