Skip to content

Commit

Permalink
pretty-printer working closer to perfection
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@487 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Feb 22, 2009
1 parent 5c6e85a commit b3ad64b
Showing 1 changed file with 25 additions and 47 deletions.
72 changes: 25 additions & 47 deletions shared/xsl/bgf2bnf.xslt
Expand Up @@ -34,7 +34,10 @@
<xsl:when test="./bgf:expression/sequence">
<xsl:text>
</xsl:text>
<xsl:apply-templates select="./bgf:expression/sequence/*"/>
<xsl:for-each select="./bgf:expression/sequence/*">
<xsl:apply-templates select="."/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:when>
Expand All @@ -53,85 +56,57 @@
</xsl:template>

<xsl:template match="marked">
<xsl:text><![CDATA[<]]> </xsl:text>
<xsl:text><![CDATA[<]]></xsl:text>
<xsl:apply-templates select="./*"/>
<xsl:text><![CDATA[>]]> </xsl:text>
<xsl:text><![CDATA[>]]></xsl:text>
</xsl:template>

<xsl:template match="plus">
<xsl:choose>
<xsl:when test="./bgf:expression/sequence">
<xsl:text>( </xsl:text>
<xsl:apply-templates select="./bgf:expression/sequence/*"/>
<xsl:text>)+ </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="./*"/>
<xsl:text>+ </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="./*"/>
<xsl:text>+</xsl:text>
</xsl:template>

<xsl:template match="star">
<xsl:choose>
<xsl:when test="./bgf:expression/sequence">
<xsl:text>( </xsl:text>
<xsl:apply-templates select="./bgf:expression/sequence/*"/>
<xsl:text>)* </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="./*"/>
<xsl:text>* </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="./*"/>
<xsl:text>*</xsl:text>
</xsl:template>

<xsl:template match="optional">
<xsl:choose>
<xsl:when test="./bgf:expression/sequence">
<xsl:text>( </xsl:text>
<xsl:apply-templates select="./bgf:expression/sequence/*"/>
<xsl:text>)? </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="./*"/>
<xsl:text>? </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="./*"/>
<xsl:text>?</xsl:text>
</xsl:template>

<xsl:template match="terminal">
<xsl:text>"</xsl:text>
<xsl:value-of select="."/>
<xsl:text>" </xsl:text>
<xsl:text>"</xsl:text>
</xsl:template>

<xsl:template match="value">
<xsl:choose>
<xsl:when test=". = 'string'">
<xsl:text>STRING </xsl:text>
<xsl:text>STRING</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>INT </xsl:text>
<xsl:text>INT</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="epsilon">
<xsl:text>EPSILON </xsl:text>
<xsl:text>EPSILON</xsl:text>
</xsl:template>

<xsl:template match="empty">
<xsl:text>EMPTY </xsl:text>
<xsl:text>EMPTY</xsl:text>
</xsl:template>

<xsl:template match="any">
<xsl:text>ANY </xsl:text>
<xsl:text>ANY</xsl:text>
</xsl:template>

<xsl:template match="nonterminal">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:template>

<xsl:template match="selectable">
Expand All @@ -142,8 +117,11 @@

<xsl:template match="sequence">
<xsl:text>( </xsl:text>
<xsl:apply-templates select="./*"/>
<xsl:text>) </xsl:text>
<xsl:for-each select="./*">
<xsl:apply-templates select="."/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:template>

<!-- top level choices - one per line -->
Expand All @@ -166,7 +144,7 @@
<xsl:text>| </xsl:text>
<xsl:apply-templates select="./*"/>
</xsl:for-each>
<xsl:text>) </xsl:text>
<xsl:text>)</xsl:text>
</xsl:template>


Expand Down

0 comments on commit b3ad64b

Please sign in to comment.