In XML output, remove redundant class attribute on symbol element.

* data/xslt/bison.xsl (xsl:key name="bison:symbolByName"): New.
* data/xslt/xml2xhtml.xsl (xsl:template match="symbol"): Use it to
look up a symbol to determine whether it's a nonterminal or terminal.
* src/gram.c (rule_rhs_print_xml): Remove class attribute.
* src/state.c (state_rule_lookahead_tokens_print_xml): Likewise.

Add prec/assoc information to XML output.
* src/gram.c (grammar_rules_print_xml): For each rule that has a
%prec, add a percent_prec attribute.
* src/print-xml.c (print_grammar): For each terminal that has a
precedence or associativity, add a prec or assoc attribute.
(xml_indent): New.
(xml_puts): Use xml_indent.
(xml_printf): Use xml_indent.
* src/print-xml.h (xml_indent): Prototype.

* tests/existing.at (GNU pic Grammar): Fix a rule miscopied from
<http://lists.gnu.org/archive/html/bug-bison/2003-04/msg00026.html>.
This commit is contained in:
Joel E. Denny
2007-12-15 02:08:02 +00:00
parent d4a26c4832
commit 408476bca9
8 changed files with 66 additions and 19 deletions

View File

@@ -392,12 +392,20 @@ print_grammar (FILE *out, int level)
if (token_translations[i] != undeftoken->number)
{
char const *tag = symbols[token_translations[i]]->tag;
xml_printf (out, level + 2,
"<terminal symbol-number=\"%d\" token-number=\"%d\""
" name=\"%s\" usefulness=\"%s\"/>",
token_translations[i], i, xml_escape (tag),
reduce_token_unused_in_grammar (token_translations[i])
? "unused-in-grammar" : "useful");
int precedence = symbols[token_translations[i]]->prec;
assoc associativity = symbols[token_translations[i]]->assoc;
xml_indent (out, level + 2);
fprintf (out,
"<terminal symbol-number=\"%d\" token-number=\"%d\""
" name=\"%s\" usefulness=\"%s\"",
token_translations[i], i, xml_escape (tag),
reduce_token_unused_in_grammar (token_translations[i])
? "unused-in-grammar" : "useful");
if (precedence)
fprintf (out, " prec=\"%d\"", precedence);
if (associativity != undef_assoc)
fprintf (out, " assoc=\"%s\"", assoc_to_string (associativity) + 1);
fputs ("/>\n", out);
}
xml_puts (out, level + 1, "</terminals>");
@@ -418,11 +426,17 @@ print_grammar (FILE *out, int level)
}
void
xml_puts (FILE *out, int level, char const *s)
xml_indent (FILE *out, int level)
{
int i;
for (i = 0; i < level; i++)
fputs (" ", out);
}
void
xml_puts (FILE *out, int level, char const *s)
{
xml_indent (out, level);
fputs (s, out);
fputc ('\n', out);
}
@@ -430,11 +444,9 @@ xml_puts (FILE *out, int level, char const *s)
void
xml_printf (FILE *out, int level, char const *fmt, ...)
{
int i;
va_list arglist;
for (i = 0; i < level; i++)
fputs (" ", out);
xml_indent (out, level);
va_start (arglist, fmt);
vfprintf (out, fmt, arglist);