diff options
author | Akim Demaille <akim@lrde.epita.fr> | 2012-11-13 10:59:55 +0100 |
---|---|---|
committer | Akim Demaille <akim@lrde.epita.fr> | 2012-11-13 10:59:55 +0100 |
commit | 06ec0105b12cdfa2994283e345154e6720354808 (patch) | |
tree | 845bbd1beeb65fc84d85f5cb3c78e506f73464b8 /data/xslt | |
parent | 2c08dc504c9f4ed12414a130bcebff8f0d3f43df (diff) | |
parent | 05c93b7d844e59ecaa5dec3bd6d9091f5aa5d1b0 (diff) | |
download | bison-06ec0105b12cdfa2994283e345154e6720354808.tar.gz |
Merge remote-tracking branch 'origin/maint'
* origin/maint:
tests: close files in glr-regression
xml: match DOT output and xml2dot.xsl processing
xml: factor xslt space template
graph: fix a memory leak
xml: documentation
output: capitalize State
Diffstat (limited to 'data/xslt')
-rw-r--r-- | data/xslt/bison.xsl | 12 | ||||
-rw-r--r-- | data/xslt/xml2dot.xsl | 185 | ||||
-rw-r--r-- | data/xslt/xml2text.xsl | 52 |
3 files changed, 210 insertions, 39 deletions
diff --git a/data/xslt/bison.xsl b/data/xslt/bison.xsl index 353c75a0..40575efd 100644 --- a/data/xslt/bison.xsl +++ b/data/xslt/bison.xsl @@ -90,4 +90,16 @@ <xsl:value-of select="string-length(translate($conflict-data, 's', ''))"/> </xsl:template> +<xsl:template name="space"> + <xsl:param name="repeat">0</xsl:param> + <xsl:param name="fill" select="' '"/> + <xsl:if test="number($repeat) >= 1"> + <xsl:call-template name="space"> + <xsl:with-param name="repeat" select="$repeat - 1"/> + <xsl:with-param name="fill" select="$fill"/> + </xsl:call-template> + <xsl:value-of select="$fill"/> + </xsl:if> +</xsl:template> + </xsl:stylesheet> diff --git a/data/xslt/xml2dot.xsl b/data/xslt/xml2dot.xsl index 111613ce..dceb8e1e 100644 --- a/data/xslt/xml2dot.xsl +++ b/data/xslt/xml2dot.xsl @@ -55,7 +55,7 @@ <xsl:call-template name="escape"> <xsl:with-param name="subject" select="$filename"/> </xsl:call-template> - <xsl:text> { + <xsl:text>" { node [fontname = courier, shape = box, colorscheme = paired6] edge [fontname = courier] @@ -68,11 +68,87 @@ <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/item"/> </xsl:with-param> </xsl:call-template> <xsl:apply-templates select="actions/transitions"/> + <xsl:apply-templates select="actions/reductions"> + <xsl:with-param name="staten"> + <xsl:value-of select="@number"/> + </xsl:with-param> + </xsl:apply-templates> +</xsl:template> + +<xsl:template match="actions/reductions"> + <xsl:param name="staten"/> + <xsl:for-each select='reduction'> + <!-- These variables are needed because the current context can't be + refered to directly in XPath expressions. --> + <xsl:variable name="rul"> + <xsl:value-of select="@rule"/> + </xsl:variable> + <xsl:variable name="ena"> + <xsl:value-of select="@enabled"/> + </xsl:variable> + <!-- The foreach's body is protected by this, so that we are actually + going to iterate once per reduction rule, and not per lookahead. --> + <xsl:if test='not(preceding-sibling::*[@rule=$rul and @enabled=$ena])'> + <xsl:variable name="rule"> + <xsl:choose> + <!-- The acceptation state is refered to as 'accept' in the XML, but + just as '0' in the DOT. --> + <xsl:when test="@rule='accept'"> + <xsl:text>0</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="@rule"/> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> + + <!-- The edge's beginning --> + <xsl:call-template name="reduction-edge-start"> + <xsl:with-param name="state" select="$staten"/> + <xsl:with-param name="rule" select="$rule"/> + <xsl:with-param name="enabled" select="@enabled"/> + </xsl:call-template> + + <!-- The edge's tokens --> + <!-- Don't show labels for the default action. In other cases, there will + always be at least one token, so 'label="[]"' will not occur. --> + <xsl:if test='$rule!=0 and not(../reduction[@enabled=$ena and @rule=$rule and @symbol="$default"])'> + <xsl:text>label="[</xsl:text> + <xsl:for-each select='../reduction[@enabled=$ena and @rule=$rule]'> + <xsl:call-template name="escape"> + <xsl:with-param name="subject" select="@symbol"/> + </xsl:call-template> + <xsl:if test="position() != last ()"> + <xsl:text>, </xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text>]", </xsl:text> + </xsl:if> + + <!-- The edge's end --> + <xsl:text>style=solid] </xsl:text> + + <!-- The diamond representing the reduction --> + <xsl:call-template name="reduction-node"> + <xsl:with-param name="state" select="$staten"/> + <xsl:with-param name="rule" select="$rule"/> + <xsl:with-param name="color"> + <xsl:choose> + <xsl:when test='@enabled="true"'> + <xsl:text>3</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>5</xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:with-param> + </xsl:call-template> + </xsl:if> + </xsl:for-each> </xsl:template> <xsl:template match="actions/transitions"> @@ -80,17 +156,48 @@ </xsl:template> <xsl:template match="item"> + <xsl:param name="prev-rule-number" + select="preceding-sibling::item[1]/@rule-number"/> <xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)"> <xsl:with-param name="point" select="@point"/> + <xsl:with-param name="num" select="@rule-number"/> + <xsl:with-param name="prev-lhs" + select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]" + /> </xsl:apply-templates> <xsl:apply-templates select="lookaheads"/> </xsl:template> <xsl:template match="rule"> <xsl:param name="point"/> + <xsl:param name="num"/> + <xsl:param name="prev-lhs"/> <xsl:text> </xsl:text> - <xsl:value-of select="lhs"/> - <xsl:text> -></xsl:text> + <xsl:choose> + <xsl:when test="$num < 10"> + <xsl:text> </xsl:text> + </xsl:when> + <xsl:when test="$num < 100"> + <xsl:text> </xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text></xsl:text> + </xsl:otherwise> + </xsl:choose> + <xsl:value-of select="$num"/> + <xsl:text> </xsl:text> + <xsl:choose> + <xsl:when test="$prev-lhs = lhs[text()]"> + <xsl:call-template name="lpad"> + <xsl:with-param name="str" select="'|'"/> + <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="lhs"/> + <xsl:text>:</xsl:text> + </xsl:otherwise> + </xsl:choose> <xsl:if test="$point = 0"> <xsl:text> .</xsl:text> </xsl:if> @@ -110,7 +217,7 @@ <xsl:template match="empty"/> <xsl:template match="lookaheads"> - <xsl:text>[</xsl:text> + <xsl:text> [</xsl:text> <xsl:apply-templates select="symbol"/> <xsl:text>]</xsl:text> </xsl:template> @@ -122,6 +229,50 @@ </xsl:if> </xsl:template> +<xsl:template name="reduction-edge-start"> + <xsl:param name="state"/> + <xsl:param name="rule"/> + <xsl:param name="enabled"/> + + <xsl:text> </xsl:text> + <xsl:value-of select="$state"/> + <xsl:text> -> "</xsl:text> + <xsl:value-of select="$state"/> + <xsl:text>R</xsl:text> + <xsl:value-of select="$rule"/> + <xsl:if test='$enabled = "false"'> + <xsl:text>d</xsl:text> + </xsl:if> + <xsl:text>" [</xsl:text> +</xsl:template> + +<xsl:template name="reduction-node"> + <xsl:param name="state"/> + <xsl:param name="rule"/> + <xsl:param name="color"/> + + <xsl:text> "</xsl:text> + <xsl:value-of select="$state"/> + <xsl:text>R</xsl:text> + <xsl:value-of select="$rule"/> + <xsl:if test="$color = 5"> + <xsl:text>d</xsl:text> + </xsl:if> + <xsl:text>" [label="</xsl:text> + <xsl:choose> + <xsl:when test="$rule = 0"> + <xsl:text>Acc", fillcolor=1</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>R</xsl:text> + <xsl:value-of select="$rule"/> + <xsl:text>", fillcolor=</xsl:text> + <xsl:value-of select="$color"/> + </xsl:otherwise> + </xsl:choose> + <xsl:text>, shape=diamond, style=filled] </xsl:text> +</xsl:template> + <xsl:template match="transition"> <xsl:call-template name="output-edge"> <xsl:with-param name="src" select="../../../@number"/> @@ -153,10 +304,13 @@ <xsl:text> </xsl:text> <xsl:value-of select="$number"/> <xsl:text> [label="</xsl:text> + <xsl:text>State </xsl:text> + <xsl:value-of select="$number"/> + <xsl:text>\n</xsl:text> <xsl:call-template name="escape"> <xsl:with-param name="subject" select="$label"/> </xsl:call-template> - <xsl:text>"] </xsl:text> + <xsl:text>\l"] </xsl:text> </xsl:template> <xsl:template name="output-edge"> @@ -197,7 +351,7 @@ </xsl:call-template> </xsl:with-param> <xsl:with-param name="search" select="' '"/> - <xsl:with-param name="replace" select="'\n'"/> + <xsl:with-param name="replace" select="'\l'"/> </xsl:call-template> </xsl:template> @@ -223,4 +377,21 @@ </xsl:choose> </xsl:template> +<xsl:template name="lpad"> + <xsl:param name="str" select="''"/> + <xsl:param name="pad" select="0"/> + <xsl:variable name="diff" select="$pad - string-length($str)" /> + <xsl:choose> + <xsl:when test="$diff < 0"> + <xsl:value-of select="$str"/> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="space"> + <xsl:with-param name="repeat" select="$diff"/> + </xsl:call-template> + <xsl:value-of select="$str"/> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + </xsl:stylesheet> diff --git a/data/xslt/xml2text.xsl b/data/xslt/xml2text.xsl index d776bb17..8b3f5ae4 100644 --- a/data/xslt/xml2text.xsl +++ b/data/xslt/xml2text.xsl @@ -230,7 +230,7 @@ <xsl:template match="automaton/state"> <xsl:param name="pad"/> <xsl:text> </xsl:text> - <xsl:text>state </xsl:text> + <xsl:text>State </xsl:text> <xsl:value-of select="@number"/> <xsl:text> </xsl:text> <xsl:apply-templates select="itemset/item"> @@ -253,9 +253,9 @@ <xsl:text> </xsl:text> <xsl:apply-templates select="transition[@type = $type]"> <xsl:with-param name="pad"> - <xsl:call-template name="max-width-symbol"> - <xsl:with-param name="node" select="transition[@type = $type]"/> - </xsl:call-template> + <xsl:call-template name="max-width-symbol"> + <xsl:with-param name="node" select="transition[@type = $type]"/> + </xsl:call-template> </xsl:with-param> </xsl:apply-templates> </xsl:if> @@ -266,9 +266,9 @@ <xsl:text> </xsl:text> <xsl:apply-templates select="error"> <xsl:with-param name="pad"> - <xsl:call-template name="max-width-symbol"> - <xsl:with-param name="node" select="error"/> - </xsl:call-template> + <xsl:call-template name="max-width-symbol"> + <xsl:with-param name="node" select="error"/> + </xsl:call-template> </xsl:with-param> </xsl:apply-templates> </xsl:if> @@ -279,9 +279,9 @@ <xsl:text> </xsl:text> <xsl:apply-templates select="reduction"> <xsl:with-param name="pad"> - <xsl:call-template name="max-width-symbol"> - <xsl:with-param name="node" select="reduction"/> - </xsl:call-template> + <xsl:call-template name="max-width-symbol"> + <xsl:with-param name="node" select="reduction"/> + </xsl:call-template> </xsl:with-param> </xsl:apply-templates> </xsl:if> @@ -290,7 +290,7 @@ <xsl:template match="item"> <xsl:param name="pad"/> <xsl:param name="prev-rule-number" - select="preceding-sibling::item[1]/@rule-number"/> + select="preceding-sibling::item[1]/@rule-number"/> <xsl:apply-templates select="key('bison:ruleByNumber', current()/@rule-number)" > @@ -329,14 +329,14 @@ <xsl:choose> <xsl:when test="$itemset != 'true' and $prev-lhs = lhs[text()]"> <xsl:call-template name="lpad"> - <xsl:with-param name="str" select="'|'"/> - <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/> + <xsl:with-param name="str" select="'|'"/> + <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/> </xsl:call-template> </xsl:when> <xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]"> <xsl:call-template name="lpad"> - <xsl:with-param name="str" select="'|'"/> - <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/> + <xsl:with-param name="str" select="'|'"/> + <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/> </xsl:call-template> </xsl:when> <xsl:otherwise> @@ -442,7 +442,7 @@ <xsl:value-of select="@rule"/> <xsl:text> (</xsl:text> <xsl:value-of - select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"/> + select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"/> <xsl:text>)</xsl:text> </xsl:otherwise> </xsl:choose> @@ -479,9 +479,9 @@ <xsl:variable name="longest"> <xsl:for-each select="$node"> <xsl:sort data-type="number" select="string-length(@symbol)" - order="descending"/> + order="descending"/> <xsl:if test="position() = 1"> - <xsl:value-of select="string-length(@symbol)"/> + <xsl:value-of select="string-length(@symbol)"/> </xsl:if> </xsl:for-each> </xsl:variable> @@ -498,7 +498,7 @@ </xsl:when> <xsl:otherwise> <xsl:call-template name="space"> - <xsl:with-param name="repeat" select="$diff"/> + <xsl:with-param name="repeat" select="$diff"/> </xsl:call-template> <xsl:value-of select="$str"/> </xsl:otherwise> @@ -516,24 +516,12 @@ <xsl:otherwise> <xsl:value-of select="$str"/> <xsl:call-template name="space"> - <xsl:with-param name="repeat" select="$diff"/> + <xsl:with-param name="repeat" select="$diff"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> -<xsl:template name="space"> - <xsl:param name="repeat">0</xsl:param> - <xsl:param name="fill" select="' '"/> - <xsl:if test="number($repeat) >= 1"> - <xsl:call-template name="space"> - <xsl:with-param name="repeat" select="$repeat - 1"/> - <xsl:with-param name="fill" select="$fill"/> - </xsl:call-template> - <xsl:value-of select="$fill"/> - </xsl:if> -</xsl:template> - <xsl:template name="line-wrap"> <xsl:param name="line-length"/> <!-- required --> <xsl:param name="first-line-length" select="$line-length"/> |