From 408476bca98e78ea0c398f36ef58f4466edb277a Mon Sep 17 00:00:00 2001 From: "Joel E. Denny" Date: Sat, 15 Dec 2007 02:08:02 +0000 Subject: [PATCH 1/1] 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 . --- ChangeLog | 24 +++++++++++++++++++++++- data/xslt/bison.xsl | 10 ++++++++++ data/xslt/xml2xhtml.xsl | 2 +- src/gram.c | 11 +++++++---- src/print-xml.c | 32 ++++++++++++++++++++++---------- src/print-xml.h | 1 + src/state.c | 3 +-- tests/existing.at | 2 +- 8 files changed, 66 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index b3db792b..558cfee8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2007-12-08 Joel E. Denny + + 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 + . + 2007-12-08 Joel E. Denny * data/xslt/bison.xsl (bison:ruleNumber): Rename to... @@ -300,7 +322,7 @@ * data/xslt/xml2dot.xsl (xsl:template match="automaton/state"): After 2007-10-11 change, the child elements here are items not rules. - ( + + - + diff --git a/src/gram.c b/src/gram.c index 1f2885f0..6b9eda13 100644 --- a/src/gram.c +++ b/src/gram.c @@ -121,8 +121,7 @@ rule_rhs_print_xml (rule *r, FILE *out, int level) item_number *rp; xml_puts (out, level, ""); for (rp = r->rhs; *rp >= 0; rp++) - xml_printf (out, level + 1, "%s", - symbol_class_get_string (symbols[*rp]), + xml_printf (out, level + 1, "%s", xml_escape (symbols[*rp]->tag)); xml_puts (out, level, ""); } @@ -221,8 +220,12 @@ grammar_rules_print_xml (FILE *out, int level) usefulness = "useless-in-parser"; else usefulness = "useful"; - xml_printf (out, level + 2, "", - rules[r].number, usefulness); + xml_indent (out, level + 2); + fprintf (out, "tag); + fputs (">\n", out); } rule_lhs_print_xml (&rules[r], out, level + 3); rule_rhs_print_xml (&rules[r], out, level + 3); diff --git a/src/print-xml.c b/src/print-xml.c index 9b1891bd..cb6707da 100644 --- a/src/print-xml.c +++ b/src/print-xml.c @@ -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, - "", - 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, + "\n", out); } xml_puts (out, level + 1, ""); @@ -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); diff --git a/src/print-xml.h b/src/print-xml.h index 6257f861..cdef4890 100644 --- a/src/print-xml.h +++ b/src/print-xml.h @@ -22,6 +22,7 @@ #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); diff --git a/src/state.c b/src/state.c index aa392aec..d3460c15 100644 --- a/src/state.c +++ b/src/state.c @@ -262,8 +262,7 @@ state_rule_lookahead_tokens_print_xml (state *s, rule *r, xml_puts (out, level, ""); BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0) { - xml_printf (out, level + 1, "%s", - symbol_class_get_string (symbols[k]), + xml_printf (out, level + 1, "%s", xml_escape (symbols[k]->tag)); } xml_puts (out, level, ""); diff --git a/tests/existing.at b/tests/existing.at index 55e8f858..9b519b2b 100644 --- a/tests/existing.at +++ b/tests/existing.at @@ -1266,7 +1266,7 @@ element: | LABEL ':' optional_separator element | LABEL ':' optional_separator position_not_place | LABEL ':' optional_separator place - | '{}' + | '{' {} element_list '}' {} optional_element | placeless_element -- 2.45.2