1  <?xml version="1.0"?>
  2  <xsl:stylesheet version="1.0"
  3      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4      xmlns:xalan="http://xml.apache.org/xalan"
  5      xmlns:redirect="http://xml.apache.org/xalan/redirect"
  6      xmlns:sablecc="sablecc-extension"
  7      extension-element-prefixes="redirect sablecc">
  8
  9    <xsl:template name="make_prods">
 10
 11    <!-- the first proudction name that goes into Start -->
 12    <xsl:param name="baseprod" select="productions/production/@ename"/>
 13
 14      <!-- generate all production files -->
 15      <xsl:for-each select="productions/production">
 16        <redirect:write select="concat($basedir, '/node/',@ename,'.java')" mkdirs="true">
 17  /* This file was generated by SableCC (http://www.sablecc.org/). */
 18
 19  package <xsl:value-of select="/parser/@package"/>.node;
 20
 21  public abstract class <xsl:value-of select="@ename"/> extends Node
 22  {
 23  }
 24        </redirect:write>
 25      </xsl:for-each>
 26
 27      <!-- generate all alternative files -->
 28      <xsl:for-each select="productions/production/alt">
 29        <redirect:write select="concat($basedir, '/node/',@ename,'.java')" mkdirs="true">
 30  /* This file was generated by SableCC (http://www.sablecc.org/). */
 31
 32  package <xsl:value-of select="/parser/@package"/>.node;
 33
 34  import java.util.*;
 35  import <xsl:value-of select="/parser/@package"/>.analysis.*;
 36
 37  public final class <xsl:value-of select="@ename"/> extends <xsl:value-of select="../@ename"/>
 38  {
 39  <!-- define subnodes -->
 40  <xsl:for-each select="elem">
 41    <xsl:if test="@is_list">
 42      private final List _<xsl:value-of select="@name"/>_ = new TypedList(new <xsl:value-of select="@ename"/>_Cast());
 43    </xsl:if>
 44
 45    <xsl:if test="not(@is_list)">
 46      private <xsl:value-of select="@etype"/> _<xsl:value-of select="@name"/>_;
 47    </xsl:if>
 48  </xsl:for-each>
 49
 50  <!-- define default empty constructor -->
 51  <xsl:if test="elem">
 52      public <xsl:value-of select="@ename"/> ()
 53      {
 54      }
 55  </xsl:if>
 56
 57  <!-- define constructor -->
 58      public <xsl:value-of select="@ename"/> (
 59  <xsl:for-each select="elem">
 60    <xsl:if test="@is_list">
 61              List _<xsl:value-of select="@name"/>_
 62    </xsl:if>
 63
 64    <xsl:if test="not(@is_list)">
 65              <xsl:value-of select="@etype"/> _<xsl:value-of select="@name"/>_
 66    </xsl:if>
 67    <xsl:if test="position()!=last()">,</xsl:if>
 68  </xsl:for-each>
 69      )
 70      {
 71  <xsl:for-each select="elem">
 72    <xsl:if test="@is_list">
 73          this._<xsl:value-of select="@name"/>_.clear();
 74          this._<xsl:value-of select="@name"/>_.addAll(_<xsl:value-of select="@name"/>_);
 75    </xsl:if>
 76
 77    <xsl:if test="not(@is_list)">
 78          set<xsl:value-of select="@ename"/> (_<xsl:value-of select="@name"/>_);
 79    </xsl:if>
 80  </xsl:for-each>
 81      }
 82
 83  <!-- define clone() -->
 84      public Object clone()
 85      {
 86          return new <xsl:value-of select="@ename"/> (
 87  <xsl:for-each select="elem">
 88    <xsl:if test="@is_list">
 89              cloneList (_<xsl:value-of select="@name"/>_)
 90    </xsl:if>
 91
 92    <xsl:if test="not(@is_list)">
 93              (<xsl:value-of select="@etype"/>)cloneNode (_<xsl:value-of select="@name"/>_)
 94    </xsl:if>
 95    <xsl:if test="position()!=last()">,</xsl:if>
 96  </xsl:for-each>
 97          );
 98      }
 99
100  <!-- define apply() -->
101      public void apply(Switch sw)
102      {
103          ((Analysis) sw).case<xsl:value-of select="@ename"/>(this);
104      }
105
106  <!-- define accessors -->
107  <xsl:for-each select="elem">
108    <xsl:if test="@is_list">
109      public List get<xsl:value-of select="@ename"/> ()
110      {
111          return _<xsl:value-of select="@name"/>_;
112      }
113
114      public void set<xsl:value-of select="@ename"/> (List list)
115      {
116          _<xsl:value-of select="@name"/>_.clear();
117          _<xsl:value-of select="@name"/>_.addAll(list);
118      }
119    </xsl:if>
120
121    <xsl:if test="not(@is_list)">
122      public <xsl:value-of select="@etype"/> get<xsl:value-of select="@ename"/> ()
123      {
124          return _<xsl:value-of select="@name"/>_;
125      }
126
127      public void set<xsl:value-of select="@ename"/> (<xsl:value-of select="@etype"/> node)
128      {
129          if(_<xsl:value-of select="@name"/>_ != null)
130          {
131              _<xsl:value-of select="@name"/>_.parent(null);
132          }
133
134          if(node != null)
135          {
136              if(node.parent() != null)
137              {
138                  node.parent().removeChild(node);
139              }
140
141              node.parent(this);
142          }
143
144          _<xsl:value-of select="@name"/>_ = node;
145      }
146    </xsl:if>
147  </xsl:for-each>
148
149  <!-- define toString() -->
150      public String toString()
151      {
152          return ""
153  <xsl:for-each select="elem">
154              + toString (_<xsl:value-of select="@name"/>_)
155  </xsl:for-each>
156          ;
157      }
158
159  <!-- define removeChild() -->
160      void removeChild(Node child)
161      {
162  <xsl:for-each select="elem">
163    <xsl:if test="@is_list">
164          if ( _<xsl:value-of select="@name"/>_.remove(child))
165          {
166              return;
167          }
168    </xsl:if>
169
170    <xsl:if test="not(@is_list)">
171          if ( _<xsl:value-of select="@name"/>_ == child )
172          {
173              _<xsl:value-of select="@name"/>_ = null;
174              return;
175          }
176    </xsl:if>
177  </xsl:for-each>
178      }
179
180  <!-- define replaceChild() -->
181      void replaceChild(Node oldChild, Node newChild)
182      {
183  <xsl:for-each select="elem">
184    <xsl:if test="@is_list">
185          for(ListIterator i = _<xsl:value-of select="@name"/>_.listIterator(); i.hasNext();)
186          {
187              if(i.next() == oldChild)
188              {
189                  if(newChild != null)
190                  {
191                      i.set(newChild);
192                      oldChild.parent(null);
193                      return;
194                  }
195
196                  i.remove();
197                  oldChild.parent(null);
198                  return;
199              }
200          }
201    </xsl:if>
202
203    <xsl:if test="not(@is_list)">
204          if ( _<xsl:value-of select="@name"/>_ == oldChild )
205          {
206              set<xsl:value-of select="@ename"/> ((<xsl:value-of select="@etype"/>) newChild);
207              return;
208          }
209    </xsl:if>
210  </xsl:for-each>
211      }
212
213  <!-- define cast inner classes for any list elements -->
214  <xsl:for-each select="elem[@is_list]">
215      private class <xsl:value-of select="@ename"/>_Cast implements Cast
216      {
217          public Object cast(Object o)
218          {
219              <xsl:value-of select="@etype"/> node = (<xsl:value-of select="@etype"/>) o;
220
221              if((node.parent() != null) &amp;&amp;
222                  (node.parent() != <xsl:value-of select="../@ename"/>.this))
223              {
224                  node.parent().removeChild(node);
225              }
226
227              if((node.parent() == null) ||
228                  (node.parent() != <xsl:value-of select="../@ename"/>.this))
229              {
230                  node.parent(<xsl:value-of select="../@ename"/>.this);
231              }
232
233              return node;
234          }
235
236          public Object unCast(Object o)
237          {
238              <xsl:value-of select="@etype"/> node = (<xsl:value-of select="@etype"/>) o;
239              if ( node.parent() == <xsl:value-of select="../@ename"/>.this )
240                  node.parent(null);
241              return node;
242          }
243      }
244  </xsl:for-each>
245  }
246        </redirect:write>
247      </xsl:for-each>
248
249      <!-- generate node/Start.java -->
250      <redirect:write select="concat($basedir,'/node/','Start.java')" mkdirs="true">
251  /* This file was generated by SableCC (http://www.sablecc.org/). */
252
253  package <xsl:value-of select="/parser/@package"/>.node;
254
255  import <xsl:value-of select="/parser/@package"/>.analysis.*;
256
257  public final class Start extends Node
258  {
259      private <xsl:value-of select="$baseprod"/> _base_;
260      private EOF _eof_;
261
262      public Start()
263      {
264      }
265
266      public Start(
267          <xsl:value-of select="$baseprod"/> _base_,
268          EOF _eof_)
269      {
270          set<xsl:value-of select="$baseprod"/>(_base_);
271          setEOF(_eof_);
272      }
273
274      public Object clone()
275      {
276          return new Start(
277              (<xsl:value-of select="$baseprod"/>) cloneNode(_base_),
278              (EOF) cloneNode(_eof_));
279      }
280
281      public void apply(Switch sw)
282      {
283          ((Analysis) sw).caseStart(this);
284      }
285
286      public <xsl:value-of select="$baseprod"/> get<xsl:value-of select="$baseprod"/>()
287      {
288          return _base_;
289      }
290      public void set<xsl:value-of select="$baseprod"/>(<xsl:value-of select="$baseprod"/> node)
291      {
292          if(_base_ != null)
293          {
294              _base_.parent(null);
295          }
296
297          if(node != null)
298          {
299              if(node.parent() != null)
300              {
301                  node.parent().removeChild(node);
302              }
303
304              node.parent(this);
305          }
306
307          _base_ = node;
308      }
309
310      public EOF getEOF()
311      {
312          return _eof_;
313      }
314      public void setEOF(EOF node)
315      {
316          if(_eof_ != null)
317          {
318              _eof_.parent(null);
319          }
320
321          if(node != null)
322          {
323              if(node.parent() != null)
324              {
325                  node.parent().removeChild(node);
326              }
327
328              node.parent(this);
329          }
330
331          _eof_ = node;
332      }
333
334      void removeChild(Node child)
335      {
336          if(_base_ == child)
337          {
338              _base_ = null;
339              return;
340          }
341
342          if(_eof_ == child)
343          {
344              _eof_ = null;
345              return;
346          }
347      }
348      void replaceChild(Node oldChild, Node newChild)
349      {
350          if(_base_ == oldChild)
351          {
352              set<xsl:value-of select="$baseprod"/>((<xsl:value-of select="$baseprod"/>) newChild);
353              return;
354          }
355
356          if(_eof_ == oldChild)
357          {
358              setEOF((EOF) newChild);
359              return;
360          }
361      }
362
363      public String toString()
364      {
365          return "" +
366              toString(_base_) +
367              toString(_eof_);
368      }
369  }
370      </redirect:write>
371    </xsl:template>
372
373  </xsl:stylesheet>
374

Generated with vim2html
Copyright © 2003 by Chip Cuccio <http://norlug.org/~chipster/?finger>