#include "tables.h"
static bitset no_reduce_set;
+struct escape_buf
+{
+ char *ptr;
+ size_t size;
+};
+static struct escape_buf escape_bufs[2];
/*----------------------------.
for (i = 0; i < snritems; i++)
{
+ bool printed = false;
item_number *sp;
item_number *sp1;
rule_number r;
sp++;
r = item_number_as_rule_number (*sp);
-
- xml_printf (out, level + 1, "<rule number=\"%d\">",
- rules[r].number);
-
- rule_lhs_print_xml (&rules[r], out, level + 2);
-
- xml_puts (out, level + 2, "<rhs>");
- for (sp = rules[r].rhs; sp < sp1; sp++)
- xml_printf (out, level + 3, "<symbol class=\"%s\">%s</symbol>",
- symbol_class_get_string (symbols[*sp]),
- xml_escape (symbols[*sp]->tag));
- xml_puts (out, level + 3, "<point/>");
- for (/* Nothing */; *sp >= 0; ++sp)
- xml_printf (out, level + 3, "<symbol class=\"%s\">%s</symbol>",
- symbol_class_get_string (symbols[*sp]),
- xml_escape (symbols[*sp]->tag));
-
- xml_puts (out, level + 2, "</rhs>");
+ sp = rules[r].rhs;
/* Display the lookahead tokens? */
- if (report_flag & report_lookahead_tokens)
- state_rule_lookahead_tokens_print_xml (s, &rules[r], out, level + 2);
+ if (report_flag & report_lookahead_tokens
+ && item_number_is_rule_number (*sp1))
+ {
+ reductions *reds = s->reductions;
+ int red = state_reduction_find (s, &rules[r]);
+ /* Print item with lookaheads if there are. */
+ if (reds->lookahead_tokens && red != -1)
+ {
+ xml_printf (out, level + 1,
+ "<item rule-number=\"%d\" point=\"%d\">",
+ rules[r].number, sp1 - sp);
+ state_rule_lookahead_tokens_print_xml (s, &rules[r],
+ out, level + 2);
+ xml_puts (out, level + 1, "</item>");
+ printed = true;
+ }
+ }
- xml_puts (out, level + 1, "</rule>");
+ if (!printed)
+ {
+ xml_printf (out, level + 1,
+ "<item rule-number=\"%d\" point=\"%d\"/>",
+ rules[r].number,
+ sp1 - sp);
+ }
}
xml_puts (out, level, "</itemset>");
}
item_number *rhsp;
xml_printf (out, level + 2,
- "<terminal type=\"%d\" symbol=\"%s\">",
- i, xml_escape (tag));
+ "<terminal symbol-number=\"%d\" token-number=\"%d\""
+ " name=\"%s\">",
+ token_translations[i], i, xml_escape (tag));
for (r = 0; r < nrules; r++)
for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
}
xml_printf (out, level + 2,
- "<nonterminal type=\"%d\" symbol=\"%s\">",
+ "<nonterminal symbol-number=\"%d\" name=\"%s\">",
i, xml_escape (tag));
if (left_count > 0)
}
void
-xml_puts (FILE *out, int level, char *s)
+xml_puts (FILE *out, int level, char const *s)
{
int i;
- level *= 2;
for (i = 0; i < level; i++)
- fputc (' ', out);
+ fputs (" ", out);
fputs (s, out);
fputc ('\n', out);
}
va_list arglist;
for (i = 0; i < level; i++)
- fputc (' ', out);
+ fputs (" ", out);
va_start (arglist, fmt);
vfprintf (out, fmt, arglist);
fputc ('\n', out);
}
-struct escape_buf
-{
- char *ptr;
- size_t size;
-};
-
static char const *
xml_escape_string (struct escape_buf *buf, char const *str)
{
char const *
xml_escape_n (int n, char const *str)
{
- static struct escape_buf buf[2];
- return xml_escape_string (buf + n, str);
+ return xml_escape_string (escape_bufs + n, str);
}
char const *
/* print rules never reduced */
print_rules_never_reduced (out, level + 1);
- /* print conflicts */
- conflicts_output_xml (out, level + 1);
-
/* print grammar */
print_grammar (out, level + 1);
xml_puts (out, 0, "</bison-xml-report>");
+ free (escape_bufs[0].ptr);
+ free (escape_bufs[1].ptr);
+
xfclose (out);
}