* 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>.
+2007-12-08 Joel E. Denny <jdenny@ces.clemson.edu>
+
+ 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>.
+
2007-12-08 Joel E. Denny <jdenny@ces.clemson.edu>
* data/xslt/bison.xsl (bison:ruleNumber): Rename to...
* data/xslt/xml2dot.xsl (xsl:template match="automaton/state"): After
2007-10-11 change, the child elements here are items not rules.
- (<xsl:template match="item"): New.
+ (xsl:template match="item"): New.
(xsl:template match="rule"): Update for new reduced itemset.
(xsl:template match="point"): Remove.
(xsl:template match="empty"): For consistency with --graph, don't
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bison="http://www.gnu.org/software/bison/">
+<xsl:key
+ name="bison:symbolByName"
+ match="/bison-xml-report/grammar/nonterminals/nonterminal"
+ use="@name"
+/>
+<xsl:key
+ name="bison:symbolByName"
+ match="/bison-xml-report/grammar/terminals/terminal"
+ use="@name"
+/>
<xsl:key
name="bison:ruleByNumber"
match="/bison-xml-report/grammar/rules/rule"
<xsl:template match="symbol">
<xsl:text> </xsl:text>
<xsl:choose>
- <xsl:when test="@class = 'nonterminal'">
+ <xsl:when test="name(key('bison:symbolByName', .)) = 'nonterminal'">
<span class="i"><xsl:value-of select="."/></span>
</xsl:when>
<xsl:otherwise>
item_number *rp;
xml_puts (out, level, "<rhs>");
for (rp = r->rhs; *rp >= 0; rp++)
- xml_printf (out, level + 1, "<symbol class=\"%s\">%s</symbol>",
- symbol_class_get_string (symbols[*rp]),
+ xml_printf (out, level + 1, "<symbol>%s</symbol>",
xml_escape (symbols[*rp]->tag));
xml_puts (out, level, "</rhs>");
}
usefulness = "useless-in-parser";
else
usefulness = "useful";
- xml_printf (out, level + 2, "<rule number=\"%d\" usefulness=\"%s\">",
- rules[r].number, usefulness);
+ xml_indent (out, level + 2);
+ fprintf (out, "<rule number=\"%d\" usefulness=\"%s\"",
+ rules[r].number, usefulness);
+ if (rules[r].precsym)
+ fprintf (out, " percent_prec=\"%s\"", rules[r].precsym->tag);
+ fputs (">\n", out);
}
rule_lhs_print_xml (&rules[r], out, level + 3);
rule_rhs_print_xml (&rules[r], out, level + 3);
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>");
}
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);
}
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);
#ifndef PRINT_XML_H_
# define PRINT_XML_H_
+void xml_indent (FILE *out, int level);
void xml_puts (FILE *, int, char const *);
void xml_printf (FILE *, int, char const *, ...);
char const *xml_escape_n (int n, char const *str);
xml_puts (out, level, "<lookaheads>");
BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0)
{
- xml_printf (out, level + 1, "<symbol class=\"%s\">%s</symbol>",
- symbol_class_get_string (symbols[k]),
+ xml_printf (out, level + 1, "<symbol>%s</symbol>",
xml_escape (symbols[k]->tag));
}
xml_puts (out, level, "</lookaheads>");
| LABEL ':' optional_separator element
| LABEL ':' optional_separator position_not_place
| LABEL ':' optional_separator place
- | '{}'
+ | '{' {} element_list '}'
{}
optional_element
| placeless_element