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 / grm2xgrm.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  2.8 KB  |  81 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/grammar/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.   <grammar><xsl:comment>This file was generated! Don't edit!</xsl:comment>
  28.    <priority>
  29.     <xsl:apply-templates select="st:token_decls/st:token_decl" mode="priority"/>
  30.    </priority>
  31.    <xsl:apply-templates select="st:token_decls/st:token_decl" mode="associativity"/>
  32.    <xsl:apply-templates select="st:production_decls"/>
  33.    <xsl:apply-templates select="st:token_decls/st:start_decl"/>
  34.   </grammar>
  35.  </xsl:template>
  36.  
  37.  <xsl:template match="st:token_decl" mode="priority">
  38.   <terminal symbol="{st:id}"/>
  39.  </xsl:template>
  40.  
  41.  <xsl:template match="st:token_decl" mode="associativity">
  42.   <xsl:if test="st:token_decl = '%left'">
  43.    <associativity symbol="{st:id}" type="left"/>
  44.   </xsl:if>
  45.   <xsl:if test="st:token_decl = '%right'">
  46.    <associativity symbol="{st:id}" type="right"/>
  47.   </xsl:if>
  48.  </xsl:template>
  49.  
  50.  <xsl:template match="st:production_decls" >
  51.   <xsl:for-each select="st:production_decl/st:production_defs/st:production_def">
  52.    <production>
  53.     <xsl:attribute name="symbol"><xsl:value-of select="../../st:id"/></xsl:attribute>
  54.      
  55.     <xsl:if test="st:prec_decl">
  56.      <xsl:attribute name="precedence"><xsl:value-of select="st:prec_decl/st:id"/></xsl:attribute>
  57.     </xsl:if>
  58.  
  59.     <xsl:apply-templates select="st:ids/st:id"/>
  60.    </production>
  61.   </xsl:for-each>
  62.  </xsl:template>
  63.  
  64.  <xsl:template match="st:id" >
  65.   <xsl:variable name="symbol" select="text()"/>
  66.   <xsl:choose>
  67.    <xsl:when test="/st:output/st:grammar/st:token_decls/st:token_decl/st:id[.=$symbol]">
  68.     <terminal symbol="{.}"/>
  69.    </xsl:when>
  70.    <xsl:otherwise>
  71.     <nonterminal symbol="{.}"/>
  72.    </xsl:otherwise>
  73.   </xsl:choose>
  74.  </xsl:template>
  75.  
  76.  <xsl:template match="st:start_decl" >
  77.   <start symbol="{st:id}"/>
  78.  </xsl:template>
  79.  
  80. </xsl:stylesheet>
  81.