home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / grm2xlex.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  8.8 KB  |  249 lines

  1. <?xml version="1.0"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17. <xsl:stylesheet version="1.0"
  18.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  19.                 xmlns:text="http://chaperon.sourceforge.net/schema/text/1.0"
  20.                 xmlns:st="http://chaperon.sourceforge.net/schema/syntaxtree/2.0"
  21.                 xmlns="http://chaperon.sourceforge.net/schema/lexicon/1.0"
  22.                 exclude-result-prefixes="st text">
  23.  
  24.  <xsl:output indent="yes" method="xml" encoding="ASCII"/>
  25.  
  26.  <xsl:template match="st:output/st:grammar" >
  27.   <lexicon><xsl:comment>This file was generated! Don't edit!</xsl:comment>
  28.    <xsl:apply-templates select="st:token_decls/st:token_decl | st:token_decls/st:ignorabletoken_decl"/>
  29.   </lexicon>
  30.  </xsl:template>
  31.  
  32.  <xsl:template match="st:token_decl" >
  33.   <lexeme symbol="{st:id}">
  34.    <xsl:if test="st:token_decl = '%left'">
  35.     <xsl:attribute name="assoc">left</xsl:attribute>
  36.    </xsl:if>
  37.    <xsl:if test="st:token_decl = '%right'">
  38.     <xsl:attribute name="assoc">right</xsl:attribute>
  39.    </xsl:if>
  40.    <xsl:apply-templates select="st:output/st:regexexpression"/>
  41.   </lexeme>
  42.  </xsl:template>
  43.  
  44.  <xsl:template match="st:ignorabletoken_decl" >
  45.   <lexeme>
  46.    <xsl:apply-templates select="st:output/st:regexexpression"/>
  47.   </lexeme>
  48.  </xsl:template>
  49.  
  50.  <xsl:template match="st:regexexpression" >
  51.   <xsl:apply-templates select="st:regexalternation"/>
  52.  </xsl:template>
  53.  
  54.  <xsl:template match="st:regexalternation" >
  55.   <xsl:choose>
  56.    <xsl:when test="count(st:regexconcatenation)>1">
  57.     <alt>
  58.      <xsl:apply-templates select="st:regexconcatenation"/>
  59.     </alt>
  60.    </xsl:when>
  61.    <xsl:otherwise>
  62.     <xsl:apply-templates select="st:regexconcatenation"/>
  63.    </xsl:otherwise>
  64.   </xsl:choose>
  65.  </xsl:template>
  66.  
  67.  <xsl:template match="st:regexconcatenation" >
  68.   <xsl:choose>
  69.    <xsl:when test="count(st:regexquantifier)>1">
  70.     <concat>
  71.      <xsl:apply-templates select="st:regexquantifier"/>
  72.     </concat>
  73.    </xsl:when>
  74.    <xsl:otherwise>
  75.     <xsl:apply-templates select="st:regexquantifier"/>
  76.    </xsl:otherwise>
  77.   </xsl:choose>
  78.  </xsl:template>
  79.  
  80.  <xsl:template match="st:regexquantifier" >
  81.   <xsl:apply-templates select="st:regexoptional|st:regexstar|st:regexplus|st:regexterm|st:regexvar"/>
  82.  </xsl:template>
  83.  
  84.  <xsl:template match="st:regexoptional" >
  85.   <concat minOccurs="0" maxOccurs="1">
  86.    <xsl:apply-templates select="st:regexterm"/>
  87.   </concat>
  88.  </xsl:template>
  89.  
  90.  <xsl:template match="st:regexstar" >
  91.   <concat minOccurs="0" maxOccurs="*">
  92.    <xsl:apply-templates select="st:regexterm"/>
  93.   </concat>
  94.  </xsl:template>
  95.  
  96.  <xsl:template match="st:regexplus" >
  97.   <concat minOccurs="1" maxOccurs="*">
  98.    <xsl:apply-templates select="st:regexterm"/>
  99.   </concat>
  100.  </xsl:template>
  101.  
  102.  <xsl:template match="st:regexvar">
  103.   <xsl:choose>
  104.    <xsl:when test="count(st:regexmultiplicator/st:string)=2">
  105.     <concat>
  106.      <xsl:attribute name="minOccurs"><xsl:value-of select="normalize-space(st:regexmultiplicator/st:string[1])"/></xsl:attribute>
  107.      <xsl:attribute name="maxOccurs"><xsl:value-of select="normalize-space(st:regexmultiplicator/st:string[2])"/></xsl:attribute>
  108.      <xsl:apply-templates select="st:regexterm"/>
  109.     </concat>
  110.    </xsl:when>
  111.    <xsl:otherwise>
  112.     <concat>
  113.      <xsl:attribute name="minOccurs"><xsl:value-of select="normalize-space(st:regexmultiplicator/st:string)"/></xsl:attribute>
  114.      <xsl:attribute name="maxOccurs"><xsl:value-of select="normalize-space(st:regexmultiplicator/st:string)"/></xsl:attribute>
  115.      <xsl:apply-templates select="st:regexterm"/>
  116.     </concat>
  117.    </xsl:otherwise>
  118.   </xsl:choose>
  119.  </xsl:template>
  120.  
  121.  <xsl:template match="st:regexterm">
  122.   <xsl:apply-templates select="st:characterclass|st:exclusivecharacterclass|st:regexklammer|st:string|st:maskedcharacter|st:regexdot|st:regexbol|st:regexabref"/>
  123.  </xsl:template>
  124.  
  125.  <xsl:template match="st:regexklammer">
  126.   <xsl:apply-templates select="st:regexalternation"/>
  127.  </xsl:template>
  128.  
  129.  <xsl:template match="st:regexdot">
  130.   <cclass exclusive="true">
  131.    <!--<cset content=" "/>-->
  132.    <cset code="10"/>
  133.    <cset code="13"/>
  134.   </cclass>
  135.  </xsl:template>
  136.  
  137.  <xsl:template match="st:regexbol">
  138.   <bol/>
  139.  </xsl:template>
  140.  
  141.  <xsl:template match="st:regexeol">
  142.   <eol/>
  143.  </xsl:template>
  144.  
  145.  <xsl:template match="st:regexabref">
  146.   <xsl:variable name="ref" select="translate(normalize-space(st:string), ' ', '')"/>
  147.   <xsl:apply-templates select="/st:output/st:grammar/st:token_decls/st:ab_decl[st:id=$ref]/st:output/st:regexexpression"/>
  148.  </xsl:template>
  149.  
  150.  <xsl:template match="st:string" mode="name">
  151.   <xsl:for-each select="st:character"><xsl:value-of select="normalize-space(.)"/></xsl:for-each>
  152.  </xsl:template>
  153.  
  154.  <xsl:template match="st:string">
  155.   <cstring>
  156.    <xsl:attribute name="content"><xsl:apply-templates select="st:character" mode="string"/></xsl:attribute>
  157.   </cstring>
  158.  </xsl:template>
  159.  
  160.  <xsl:template match="st:characterclass">
  161.   <cclass>
  162.    <xsl:apply-templates select="st:sequence"/>
  163.   </cclass>
  164.  </xsl:template>
  165.  
  166.  <xsl:template match="st:exclusivecharacterclass" >
  167.   <cclass exclusive="true">
  168.    <xsl:apply-templates select="st:sequence"/>
  169.   </cclass>
  170.  </xsl:template>
  171.  
  172.  <xsl:template match="st:sequence">
  173.   <xsl:apply-templates select="st:character|st:maskedcharacter|st:intervall" mode="cclass"/>
  174.  </xsl:template>
  175.  
  176.  <xsl:template match="st:character" mode="cclass">
  177.   <cset>
  178.    <xsl:attribute name="content"><xsl:value-of select="translate(normalize-space(.), ' ', '')"/></xsl:attribute>
  179.   </cset>
  180.  </xsl:template>
  181.  
  182.  <xsl:template match="st:maskedcharacter" mode="cclass">
  183.   <cset>
  184.    <xsl:choose>
  185.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 'n'">
  186. <!--     <xsl:attribute name="content"><xsl:text disable-output-escaping="yes"> </xsl:text></xsl:attribute>-->
  187.      <xsl:attribute name="code">10</xsl:attribute>
  188.     </xsl:when>
  189.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 'r'">
  190. <!--     <xsl:attribute name="content"><xsl:text disable-output-escaping="yes"> </xsl:text></xsl:attribute>-->
  191.      <xsl:attribute name="code">13</xsl:attribute>
  192.     </xsl:when>
  193.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 't'">
  194. <!--     <xsl:attribute name="content"><xsl:text disable-output-escaping="yes"> </xsl:text></xsl:attribute>-->
  195.      <xsl:attribute name="code">9</xsl:attribute>
  196.     </xsl:when>
  197.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 'u'">
  198.      <xsl:attribute name="code">#<xsl:value-of select="substring(translate(normalize-space(.), ' ', ''),2,6)"/></xsl:attribute>
  199.     </xsl:when>
  200.     <xsl:when test="contains(.,'\ ')">
  201.      <xsl:attribute name="content"><xsl:text disable-output-escaping="yes"> </xsl:text></xsl:attribute>
  202.     </xsl:when>
  203.     <xsl:otherwise>
  204.      <xsl:attribute name="content"><xsl:value-of select="substring(translate(normalize-space(.), ' ', ''), 2,1)"/></xsl:attribute>
  205.     </xsl:otherwise>
  206.    </xsl:choose>
  207.   </cset>
  208.  </xsl:template>
  209.  
  210.  <xsl:template match="st:character" mode="string">
  211.   <xsl:value-of select="translate(normalize-space(.), ' ', '')"/>
  212.  </xsl:template>
  213.  
  214.  <xsl:template match="st:maskedcharacter">
  215.   <xsl:choose>
  216.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 'n'">
  217.      <!--<xsl:text disable-output-escaping="yes"> </xsl:text>-->
  218.      <cstring code="10"/>
  219.     </xsl:when>
  220.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 'r'">
  221.      <!--<xsl:text disable-output-escaping="yes"> </xsl:text>-->
  222.      <cstring code="13"/>
  223.     </xsl:when>
  224.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 't'">
  225.      <!--<xsl:text disable-output-escaping="yes"> </xsl:text>-->
  226.      <cstring code="9"/>
  227.     </xsl:when>
  228.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 'u'">
  229.      <cstring code="#{substring(translate(normalize-space(.), ' ', ''), 2,6)}"/>
  230.     </xsl:when>
  231.     <xsl:when test="contains(.,'\ ')">
  232.      <!--<xsl:text disable-output-escaping="yes"> </xsl:text>-->
  233.      <cstring content=" "/>
  234.     </xsl:when>
  235.     <xsl:otherwise>
  236.      <cstring content="{substring(translate(normalize-space(.), ' ', ''),2,1)}"/>
  237.     </xsl:otherwise>
  238.    </xsl:choose>
  239.  </xsl:template>
  240.  
  241.  <xsl:template match="st:intervall" mode="cclass">
  242.   <cinterval>
  243.    <xsl:attribute name="min"><xsl:value-of select="st:character[1]"/></xsl:attribute>
  244.    <xsl:attribute name="max"><xsl:value-of select="st:character[2]"/></xsl:attribute>
  245.   </cinterval>
  246.  </xsl:template>
  247.  
  248. </xsl:stylesheet>
  249.