1<!-- 2// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan. 3// 4// TagSoup is licensed under the Apache License, 5// Version 2.0. You may obtain a copy of this license at 6// http://www.apache.org/licenses/LICENSE-2.0 . You may also have 7// additional legal rights not granted by this license. 8// 9// TagSoup is distributed in the hope that it will be useful, but 10// unless required by applicable law or agreed to in writing, TagSoup 11// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 12// OF ANY KIND, either express or implied; not even the implied warranty 13// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14--> 15 16<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 17 xmlns:stml="http://www.ccil.org/~cowan/XML/tagsoup/stml" 18 version="1.0"> 19 20 <xsl:output method="text"/> 21 22 <xsl:strip-space elements="*"/> 23 24 <!-- The main template. Generates declarations for states and 25 actions, then the statetable itself, and then a comment (used for 26 manual checking) listing all the actions compactly. --> 27 <xsl:template match="stml:statetable"> 28 <xsl:apply-templates select="stml:state"> 29 <xsl:sort select="@id"/> 30 </xsl:apply-templates> 31 32 <xsl:apply-templates select="stml:action"> 33 <xsl:sort select="@id"/> 34 </xsl:apply-templates> 35 36 <xsl:text>	private static int[] statetable = {
</xsl:text> 37 <xsl:apply-templates select="stml:state/stml:tr"> 38 <xsl:sort select="../@id"/> 39 <xsl:sort select="@symbol"/> 40 <xsl:sort select="@char"/> 41 </xsl:apply-templates> 42 <xsl:text>
	};
</xsl:text> 43 44 <xsl:text>	private static final String[] debug_actionnames = { ""</xsl:text> 45 <xsl:apply-templates select="stml:action" mode="debug"> 46 <xsl:sort select="@id"/> 47 </xsl:apply-templates> 48 <xsl:text>};
</xsl:text> 49 50 <xsl:text>	private static final String[] debug_statenames = { ""</xsl:text> 51 <xsl:apply-templates select="stml:state" mode="debug"> 52 <xsl:sort select="@id"/> 53 </xsl:apply-templates> 54 <xsl:text>};
</xsl:text> 55 56 <xsl:text>
</xsl:text> 57 </xsl:template> 58 59 <!-- Generate a single state declaration. --> 60 <xsl:template match="stml:state"> 61 <xsl:text>	private static final int </xsl:text> 62 <xsl:value-of select="@id"/> 63 <xsl:text> = </xsl:text> 64 <xsl:value-of select="position()"/> 65 <xsl:text>;
</xsl:text> 66 </xsl:template> 67 68 <!-- Generate a single action declaration. --> 69 <xsl:template match="stml:action"> 70 <xsl:text>	private static final int </xsl:text> 71 <xsl:value-of select="@id"/> 72 <xsl:text> = </xsl:text> 73 <xsl:value-of select="position()"/> 74 <xsl:text>;
</xsl:text> 75 </xsl:template> 76 77 <!-- Generate a single row of the statetable. --> 78 <xsl:template match="stml:tr"> 79 <xsl:choose> 80 <xsl:when test="@symbol = 'EOF'"> 81 <xsl:call-template name="dump-tr"> 82 <xsl:with-param name="char" select=""-1""/> 83 </xsl:call-template> 84 </xsl:when> 85 <xsl:when test="@symbol = 'LF'"> 86 <xsl:call-template name="dump-tr"> 87 <xsl:with-param name="char" select=""'\n'""/> 88 </xsl:call-template> 89 </xsl:when> 90 <xsl:when test="@symbol = 'default'"> 91 <xsl:call-template name="dump-tr"> 92 <xsl:with-param name="char" select=""0""/> 93 </xsl:call-template> 94 </xsl:when> 95 <xsl:when test="@char = "'""> 96 <xsl:call-template name="dump-tr"> 97 <xsl:with-param name="char" select=""'\''""/> 98 </xsl:call-template> 99 </xsl:when> 100 <xsl:when test="@symbol = 'S'"> 101 <xsl:call-template name="dump-tr"> 102 <xsl:with-param name="char" select=""' '""/> 103 </xsl:call-template> 104 <xsl:call-template name="dump-tr"> 105 <xsl:with-param name="char" select=""'\n'""/> 106 </xsl:call-template> 107 <xsl:call-template name="dump-tr"> 108 <xsl:with-param name="char" select=""'\t'""/> 109 </xsl:call-template> 110 </xsl:when> 111 <xsl:otherwise> 112 <xsl:call-template name="dump-tr"> 113 <xsl:with-param name="char" 114 select="concat("'", @char, "'")"/> 115 </xsl:call-template> 116 </xsl:otherwise> 117 </xsl:choose> 118 </xsl:template> 119 120 <!-- This is a subroutine used to do the actual printing. --> 121 <xsl:template name="dump-tr"> 122 <xsl:param name="char"/> 123 <xsl:text>		</xsl:text> 124 <xsl:value-of select="../@id"/> 125 <xsl:text>, </xsl:text> 126 <xsl:value-of select="$char"/> 127 <xsl:text>, </xsl:text> 128 <xsl:value-of select="@action"/> 129 <xsl:text>, </xsl:text> 130 <xsl:value-of select="@newstate"/> 131 <xsl:text>,
</xsl:text> 132 </xsl:template> 133 134 <!-- Generate a single action name in the "Actions:" comment. 135 The mode is used to keep XSLT from confusing this with the 136 regular actions template that does the action declarations. --> 137 <xsl:template match="stml:action" mode="debug"> 138 <xsl:text>, "</xsl:text> 139 <xsl:value-of select="@id"/> 140 <xsl:text>"</xsl:text> 141 </xsl:template> 142 143 <!-- Generate a single stat debug name. --> 144 <xsl:template match="stml:state" mode="debug"> 145 <xsl:text>, "</xsl:text> 146 <xsl:value-of select="@id"/> 147 <xsl:text>"</xsl:text> 148 </xsl:template> 149 150</xsl:transform> 151