- if (variant_count == 0)
- {
- if (explicit_bracketing || !ref_tail_fields)
- complain_at (text_loc, _("unresolved reference: %s"),
- quote(text));
- else
- {
- unsigned len = ref_tail_fields - text;
- char *str = strndup (text, len);
- text_loc.end.column = text_loc.start.column + len;
- complain_at (text_loc, _("unresolved reference: %s"),
- quote (str));
- free (str);
- }
- }
- else
- {
- complain_at (text_loc, _("invalid reference: %s"),
- quote (text));
+ {
+ 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 (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)