Initial support for highlighting jam code.

[SVN r77636]
This commit is contained in:
Steven Watanabe 2012-03-29 23:46:06 +00:00
parent dd17d84274
commit aa80c5a141
3 changed files with 91 additions and 0 deletions

View File

@ -388,6 +388,12 @@
</computeroutput> </computeroutput>
</xsl:template> </xsl:template>
<xsl:template match="code[@lang='jam']" mode="annotation">
<computeroutput>
<xsl:apply-templates mode="annotation"/>
</computeroutput>
</xsl:template>
<xsl:template match="bold" mode="annotation"> <xsl:template match="bold" mode="annotation">
<emphasis role="bold"> <emphasis role="bold">
<xsl:apply-templates mode="annotation"/> <xsl:apply-templates mode="annotation"/>

View File

@ -392,6 +392,12 @@ Error: XSL template 'link-or-anchor' called with invalid link-type '<xsl:value-o
</computeroutput> </computeroutput>
</xsl:template> </xsl:template>
<xsl:template match="code[@lang='jam']">
<computeroutput>
<xsl:apply-templates mode="highlight-jam"/>
</computeroutput>
</xsl:template>
<xsl:template match="bold"> <xsl:template match="bold">
<emphasis role="bold"> <emphasis role="bold">
<xsl:apply-templates mode="annotation"/> <xsl:apply-templates mode="annotation"/>

View File

@ -435,6 +435,75 @@
</xsl:choose> </xsl:choose>
</xsl:template> </xsl:template>
<!-- Jam syntax highlighting -->
<xsl:variable name="jam-keywords" select="' actions bind case class default else for if ignore in include local module on piecemeal quietly return rule switch together updated while '"/>
<xsl:variable name="jam-operators" select="' ! != &amp; &amp;&amp; ( ) += : ; &lt; &lt;= = &gt; &gt;= ?= [ ] { | || } '"/>
<xsl:template name="highlight-jam-word">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($jam-keywords, concat(' ', $text, ' '))">
<xsl:call-template name="highlight-keyword">
<xsl:with-param name="keyword" select="$text"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($jam-operators, concat(' ', $text, ' '))">
<xsl:call-template name="highlight-special">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="jam-word-length">
<xsl:param name="text"/>
<xsl:param name="pos" select="1"/>
<xsl:choose>
<xsl:when test="string-length($text) + 1= $pos">
<xsl:value-of select="$pos - 1"/>
</xsl:when>
<xsl:when test="contains(' &#xA;&#xD;&#x9;', substring($text, $pos, 1))">
<xsl:value-of select="$pos - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="jam-word-length">
<xsl:with-param name="text" select="$text"/>
<xsl:with-param name="pos" select="$pos + 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="highlight-jam-text">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="string-length($text) = 0"/>
<xsl:when test="contains(' &#xA;&#xD;&#x9;', substring($text, 1, 1))">
<xsl:value-of select="substring($text, 1, 1)"/>
<xsl:call-template name="highlight-jam-text">
<xsl:with-param name="text" select="substring($text, 2)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="length">
<xsl:call-template name="jam-word-length">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="highlight-jam-word">
<xsl:with-param name="text" select="substring($text, 1, $length)"/>
</xsl:call-template>
<xsl:call-template name="highlight-jam-text">
<xsl:with-param name="text" select="substring($text, $length + 1)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Perform C++ syntax highlighting on the given text --> <!-- Perform C++ syntax highlighting on the given text -->
<xsl:template name="highlight-text"> <xsl:template name="highlight-text">
<xsl:param name="text" select="."/> <xsl:param name="text" select="."/>
@ -481,4 +550,14 @@
<xsl:apply-templates mode="highlight"/> <xsl:apply-templates mode="highlight"/>
</xsl:template> </xsl:template>
<xsl:template match="*" mode="highlight-jam">
<xsl:apply-templates mode="annotation"/>
</xsl:template>
<xsl:template match="text()" mode="highlight-jam">
<xsl:call-template name="highlight-jam-text">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet> </xsl:stylesheet>