<!--
xml2dot.xsl - transform Bison XML Report into DOT.
- $Id$
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007-2012 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
-->
<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:bison="http://www.gnu.org/software/bison/">
+
+<xsl:import href="bison.xsl"/>
<xsl:output method="text" encoding="UTF-8" indent="no"/>
<xsl:template match="/">
</xsl:template>
<xsl:template match="bison-xml-report">
- <xsl:apply-templates select="automaton"/>
+ <xsl:text>// Generated by GNU Bison </xsl:text>
+ <xsl:value-of select="@version"/>
+ <xsl:text>. </xsl:text>
+ <xsl:text>// Report bugs to <</xsl:text>
+ <xsl:value-of select="@bug-report"/>
+ <xsl:text>>. </xsl:text>
+ <xsl:text>// Home page: <</xsl:text>
+ <xsl:value-of select="@url"/>
+ <xsl:text>>. </xsl:text>
+ <xsl:apply-templates select="automaton">
+ <xsl:with-param name="filename" select="filename"/>
+ </xsl:apply-templates>
</xsl:template>
<xsl:template match="automaton">
- <xsl:text>digraph Automaton { </xsl:text>
+ <xsl:param name="filename"/>
+ <xsl:text>digraph "</xsl:text>
+ <xsl:call-template name="escape">
+ <xsl:with-param name="subject" select="$filename"/>
+ </xsl:call-template>
+ <xsl:text>" { </xsl:text>
<xsl:apply-templates select="state"/>
<xsl:text>} </xsl:text>
</xsl:template>
<xsl:with-param name="number" select="@number"/>
<xsl:with-param name="label">
<xsl:value-of select="@number"/>
- <xsl:apply-templates select="itemset/rule"/>
+ <xsl:apply-templates select="itemset/item"/>
</xsl:with-param>
</xsl:call-template>
<xsl:apply-templates select="actions/transitions"/>
<xsl:apply-templates select="transition"/>
</xsl:template>
+<xsl:template match="item">
+ <xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)">
+ <xsl:with-param name="point" select="@point"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates select="lookaheads"/>
+</xsl:template>
+
<xsl:template match="rule">
- <xsl:text>\n</xsl:text>
+ <xsl:param name="point"/>
+ <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:if test="$point = 0">
+ <xsl:text> .</xsl:text>
+ </xsl:if>
+ <xsl:for-each select="rhs/symbol|rhs/empty">
+ <xsl:apply-templates select="."/>
+ <xsl:if test="$point = position()">
+ <xsl:text> .</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
</xsl:template>
<xsl:template match="symbol">
<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="empty"/>
<xsl:template match="lookaheads">
<xsl:text>[</xsl:text>
<xsl:text> </xsl:text>
<xsl:value-of select="$number"/>
<xsl:text> [label="</xsl:text>
- <xsl:call-template name="string-replace">
+ <xsl:call-template name="escape">
<xsl:with-param name="subject" select="$label"/>
- <xsl:with-param name="search" select="'"'"/>
- <xsl:with-param name="replace" select="'\"'"/>
</xsl:call-template>
<xsl:text>"] </xsl:text>
</xsl:template>
<xsl:value-of select="$style"/>
<xsl:if test="$label and $label != ''">
<xsl:text> label="</xsl:text>
- <xsl:call-template name="string-replace">
+ <xsl:call-template name="escape">
<xsl:with-param name="subject" select="$label"/>
- <xsl:with-param name="search" select="'"'"/>
- <xsl:with-param name="replace" select="'\"'"/>
</xsl:call-template>
<xsl:text>"</xsl:text>
</xsl:if>
<xsl:text>] </xsl:text>
</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:template name="escape">
+ <xsl:param name="subject"/> <!-- required -->
+ <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>