mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
* data/xslt/xml2dot.xsl (xsl:template match="rule"): Use a ` ' instead of a `\n'. That is, don't add escapes yet or they'll be doubly escaped later. (xsl:template name="output-node"): Use the new escape template instead of the string-replace template directly. (xsl:template name="output-edge"): Likewise. (xsl:template name="escape"): New, escapes backslashes and newlines in addition to quotation marks. * src/graphviz.c (start_graph, output_node, output_edge): Add whitespace to output for legibility. Make xml2text.xsl and --report produce the same output, and remove the XML "conflicts" element since a conflict summary is easily extracted from the automaton. * data/xslt/bison.xsl: New. (xsl:template match="state" mode="bison:count-conflicts): New. * data/xslt/xml2text.xsl: Import bison.xsl. (xsl:template match="bison-xml-report"): Instead of styling the "conflicts" element, style the "automaton" element with mode "conflicts". Unlike the former, the latter lists S/R and R/R conflicts for a state on the same line. (xsl:template match="conflicts"): Remove. (xsl:template match="conflict"): Remove. (xsl:template match="terminal"): Line-wrap the list of rules in which the terminal is used. (xsl:template match="nonterminal"): Likewise for nonterminals. (xsl:template match="automaton" mode="conflicts"): New. (xsl:template match="state" mode="conflicts"): New. (xsl:template name="line-wrap"): New. (xsl:template name="ws-search"): New. * data/xslt/xml2xhtml.xsl: Import bison.xsl. (xsl:template match="bison-xml-report"): Instead of styling the "conflicts" element, style the "automaton" element with mode "conflicts." (xsl:template match="conflicts"): Remove. (xsl:template match="conflict"): Remove. (xsl:template match="automaton" mode="conflicts"): New. (xsl:template match="state" mode="conflicts): New. * src/conflicts.c (conflicts_output_xml): Remove. * src/conflicts.h (conflicts_output_xml): Remove prototype. * src/print-xml.c (print_xml): Don't invoke conflicts_output_xml. * src/print.c (print_grammar): Consistently wrap at the 66th column so the corresponding XSLT is easier. Also, never wrap between a word and the comma that follows it.
197 lines
5.9 KiB
XML
197 lines
5.9 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!--
|
|
xml2dot.xsl - transform Bison XML Report into DOT.
|
|
$Id$
|
|
|
|
Copyright (C) 2007 Free Software Foundation, Inc.
|
|
|
|
This file is part of Bison, the GNU Compiler Compiler.
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
Written by Wojciech Polak <polak@gnu.org>.
|
|
-->
|
|
|
|
<xsl:stylesheet version="1.0"
|
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
|
|
<xsl:output method="text" encoding="UTF-8" indent="no"/>
|
|
|
|
<xsl:template match="/">
|
|
<xsl:apply-templates select="bison-xml-report"/>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="bison-xml-report">
|
|
<xsl:apply-templates select="automaton"/>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="automaton">
|
|
<xsl:text>digraph Automaton { </xsl:text>
|
|
<xsl:apply-templates select="state"/>
|
|
<xsl:text>} </xsl:text>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="automaton/state">
|
|
<xsl:call-template name="output-node">
|
|
<xsl:with-param name="number" select="@number"/>
|
|
<xsl:with-param name="label">
|
|
<xsl:value-of select="@number"/>
|
|
<xsl:apply-templates select="itemset/rule"/>
|
|
</xsl:with-param>
|
|
</xsl:call-template>
|
|
<xsl:apply-templates select="actions/transitions"/>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="actions/transitions">
|
|
<xsl:apply-templates select="transition"/>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="rule">
|
|
<xsl:text> </xsl:text>
|
|
<xsl:value-of select="lhs"/>
|
|
<xsl:text> -></xsl:text>
|
|
<xsl:apply-templates select="rhs/symbol|rhs/point|rhs/empty"/>
|
|
<xsl:apply-templates select="lookaheads"/>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="symbol">
|
|
<xsl:text> </xsl:text>
|
|
<xsl:value-of select="."/>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="point">
|
|
<xsl:text> .</xsl:text>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="empty">
|
|
<xsl:text> /* empty */</xsl:text>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="lookaheads">
|
|
<xsl:text>[</xsl:text>
|
|
<xsl:apply-templates select="symbol"/>
|
|
<xsl:text>]</xsl:text>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="lookaheads/symbol">
|
|
<xsl:value-of select="."/>
|
|
<xsl:if test="position() != last()">
|
|
<xsl:text>, </xsl:text>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
|
|
<xsl:template match="transition">
|
|
<xsl:call-template name="output-edge">
|
|
<xsl:with-param name="src" select="../../../@number"/>
|
|
<xsl:with-param name="dst" select="@state"/>
|
|
<xsl:with-param name="style">
|
|
<xsl:choose>
|
|
<xsl:when test="@symbol = 'error'">
|
|
<xsl:text>dotted</xsl:text>
|
|
</xsl:when>
|
|
<xsl:when test="@type = 'shift'">
|
|
<xsl:text>solid</xsl:text>
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<xsl:text>dashed</xsl:text>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:with-param>
|
|
<xsl:with-param name="label">
|
|
<xsl:if test="not(@symbol = 'error')">
|
|
<xsl:value-of select="@symbol"/>
|
|
</xsl:if>
|
|
</xsl:with-param>
|
|
</xsl:call-template>
|
|
</xsl:template>
|
|
|
|
<xsl:template name="output-node">
|
|
<xsl:param name="number"/>
|
|
<xsl:param name="label"/>
|
|
<xsl:text> </xsl:text>
|
|
<xsl:value-of select="$number"/>
|
|
<xsl:text> [label="</xsl:text>
|
|
<xsl:call-template name="escape">
|
|
<xsl:with-param name="subject" select="$label"/>
|
|
</xsl:call-template>
|
|
<xsl:text>"] </xsl:text>
|
|
</xsl:template>
|
|
|
|
<xsl:template name="output-edge">
|
|
<xsl:param name="src"/>
|
|
<xsl:param name="dst"/>
|
|
<xsl:param name="style"/>
|
|
<xsl:param name="label"/>
|
|
<xsl:text> </xsl:text>
|
|
<xsl:value-of select="$src"/>
|
|
<xsl:text> -> </xsl:text>
|
|
<xsl:value-of select="$dst"/>
|
|
<xsl:text> [style=</xsl:text>
|
|
<xsl:value-of select="$style"/>
|
|
<xsl:if test="$label and $label != ''">
|
|
<xsl:text> label="</xsl:text>
|
|
<xsl:call-template name="escape">
|
|
<xsl:with-param name="subject" select="$label"/>
|
|
</xsl:call-template>
|
|
<xsl:text>"</xsl:text>
|
|
</xsl:if>
|
|
<xsl:text>] </xsl:text>
|
|
</xsl:template>
|
|
|
|
<xsl:template name="escape">
|
|
<xsl:param name="subject" required="yes"/>
|
|
<xsl:call-template name="string-replace">
|
|
<xsl:with-param name="subject">
|
|
<xsl:call-template name="string-replace">
|
|
<xsl:with-param name="subject">
|
|
<xsl:call-template name="string-replace">
|
|
<xsl:with-param name="subject" select="$subject"/>
|
|
<xsl:with-param name="search" select="'\'"/>
|
|
<xsl:with-param name="replace" select="'\\'"/>
|
|
</xsl:call-template>
|
|
</xsl:with-param>
|
|
<xsl:with-param name="search" select="'"'"/>
|
|
<xsl:with-param name="replace" select="'\"'"/>
|
|
</xsl:call-template>
|
|
</xsl:with-param>
|
|
<xsl:with-param name="search" select="' '"/>
|
|
<xsl:with-param name="replace" select="'\n'"/>
|
|
</xsl:call-template>
|
|
</xsl:template>
|
|
|
|
<xsl:template name="string-replace">
|
|
<xsl:param name="subject"/>
|
|
<xsl:param name="search"/>
|
|
<xsl:param name="replace"/>
|
|
<xsl:choose>
|
|
<xsl:when test="contains($subject, $search)">
|
|
<xsl:variable name="before" select="substring-before($subject, $search)"/>
|
|
<xsl:variable name="after" select="substring-after($subject, $search)"/>
|
|
<xsl:value-of select="$before"/>
|
|
<xsl:value-of select="$replace"/>
|
|
<xsl:call-template name="string-replace">
|
|
<xsl:with-param name="subject" select="$after"/>
|
|
<xsl:with-param name="search" select="$search"/>
|
|
<xsl:with-param name="replace" select="$replace"/>
|
|
</xsl:call-template>
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<xsl:value-of select="$subject"/>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:template>
|
|
|
|
</xsl:stylesheet>
|