Debian Codegraph @

jackrabbit-spi-commons/src/main/javacc/xpath/jjtree.xsl

raw
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!--
4 * Copyright (c) 2002 World Wide Web Consortium,
5 * (Massachusetts Institute of Technology, Institut National de
6 * Recherche en Informatique et en Automatique, Keio University). All
7 * Rights Reserved. This program is distributed under the W3C's Software
8 * Intellectual Property License. This program is distributed in the
9 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 * PURPOSE.
12 * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
13 -->
14
15 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
16 xmlns:g="http://www.w3.org/2001/03/XPath/grammar">
17 <xsl:import href="javacc.xsl"/>
18
19 <xsl:template name="javacc-options">
20 <!-- xsl:apply-imports/ -->
21 STATIC = false;
22 MULTI=false;
23 VISITOR=true ; // invokes the JJTree Visitor support
24 NODE_SCOPE_HOOK=false;
25 NODE_USES_PARSER=true;
26 </xsl:template>
27
28 <xsl:template name="input">
29 SimpleNode <xsl:choose>
30 <xsl:when test="$spec='xquery'">XPath2</xsl:when>
31 <xsl:when test="$spec='xpath'">XPath2</xsl:when>
32 <xsl:when test="$spec='pathx1'">XPath2</xsl:when>
33 <xsl:otherwise>XPath2</xsl:otherwise>
34 </xsl:choose>() :
35 {}
36 {
37 <xsl:value-of select="g:start/@name"/>()&lt;EOF&gt;
38 { return jjtThis ; }
39 }
40 <xsl:if test="$spec='xpath' or $spec='pathx1'">
41 SimpleNode <xsl:choose>
42 <xsl:when test="$spec='xpath'">MatchPattern</xsl:when>
43 <xsl:when test="$spec='pathx1'">MatchPattern</xsl:when>
44 <xsl:otherwise>MatchPattern</xsl:otherwise>
45 </xsl:choose>() :
46 {m_isMatchPattern = true;}
47 {
48 <xsl:value-of select="g:start[contains(@if,'xslt-patterns')]/@name"/>()&lt;EOF&gt;
49 { return jjtThis ; }
50 }
51 </xsl:if>
52 </xsl:template>
53
54 <xsl:template name="extra-parser-code"/>
55
56 <xsl:template name="parser">
57 <xsl:variable name="parser-class">
58 <xsl:choose>
59 <xsl:when test="$spec='xpath'">XPath</xsl:when>
60 <xsl:when test="$spec='pathx1'">XPath</xsl:when>
61 <xsl:otherwise>XPath</xsl:otherwise>
62 </xsl:choose>
63 </xsl:variable>
64 PARSER_BEGIN(<xsl:value-of select="$parser-class"/>)
65
66 <xsl:call-template name="set-parser-package"/>
67 import java.io.*;
68 import java.util.Stack;
69 import java.util.Vector;
70
71 public class <xsl:value-of select="$parser-class"/> {
72 <xsl:call-template name="extra-parser-code"/>
73
74 boolean m_isMatchPattern = false;
75 boolean isStep = false;
76
77 Stack binaryTokenStack = new Stack();
78
79 public Node createNode(int id) {
80 return null;
81 }
82
83
84
85 public static void main(String args[])
86 throws Exception
87 {
88 int numberArgsLeft = args.length;
89 int argsStart = 0;
90 boolean isMatchParser = false;
91 if(numberArgsLeft > 0)
92 {
93 if(args[argsStart].equals("-match"))
94 {
95 isMatchParser = true;
96 System.out.println("Match Pattern Parser");
97 argsStart++;
98 numberArgsLeft--;
99 }
100 }
101 if(numberArgsLeft > 0)
102 {
103 try
104 {
105 final boolean dumpTree = true;
106 if(args[0].endsWith(".xquery"))
107 {
108 System.out.println("Running test for: "+args[0]);
109 File file = new File(args[0]);
110 FileInputStream fis = new FileInputStream(file);
111 XPath parser = new XPath(fis);
112 SimpleNode tree = parser.XPath2();
113 if(dumpTree)
114 tree.dump("|") ;
115 }
116 else
117 {
118 for(int i = argsStart; i &lt; args.length; i++)
119 {
120 System.out.println();
121 System.out.println("Test["+i+"]: "+args[i]);
122 XPath parser = new XPath(new java.io.StringBufferInputStream(args[i]));
123 SimpleNode tree;
124 if(isMatchParser)
125 {
126 tree = parser.<xsl:choose>
127 <xsl:when test="$spec='xquery'">XPath2</xsl:when>
128 <xsl:when test="$spec='xpath'">MatchPattern</xsl:when>
129 <xsl:when test="$spec='pathx1'">MatchPattern</xsl:when>
130 <xsl:otherwise>XPath2</xsl:otherwise>
131 </xsl:choose>();
132 }
133 else
134 {
135 tree = parser.<xsl:choose>
136 <xsl:when test="$spec='xquery'">XPath2</xsl:when>
137 <xsl:when test="$spec='xpath'">XPath2</xsl:when>
138 <xsl:when test="$spec='pathx1'">XPath2</xsl:when>
139 <xsl:otherwise>XPath2</xsl:otherwise>
140 </xsl:choose>();
141 }
142 ((SimpleNode)tree.jjtGetChild(0)).dump("|") ;
143 }
144 System.out.println("Success!!!!");
145 }
146 }
147 catch(ParseException pe)
148 {
149 System.err.println(pe.getMessage());
150 }
151 return;
152 }
153 java.io.DataInputStream dinput = new java.io.DataInputStream(System.in);
154 while(true)
155 {
156 try
157 {
158 System.err.println("Type Expression: ");
159 String input = dinput.readLine();
160 if(null == input || input.trim().length() == 0)
161 break;
162 XPath parser = new XPath(new java.io.StringBufferInputStream(input));
163 SimpleNode tree;
164 if(isMatchParser)
165 {
166 tree = parser.<xsl:choose>
167 <xsl:when test="$spec='xquery'">XPath2</xsl:when>
168 <xsl:when test="$spec='xpath'">MatchPattern</xsl:when>
169 <xsl:when test="$spec='pathx1'">MatchPattern</xsl:when>
170 <xsl:otherwise>XPath2</xsl:otherwise>
171 </xsl:choose>();
172 }
173 else
174 {
175 tree = parser.<xsl:choose>
176 <xsl:when test="$spec='xquery'">XPath2</xsl:when>
177 <xsl:when test="$spec='xpath'">XPath2</xsl:when>
178 <xsl:when test="$spec='pathx1'">XPath2</xsl:when>
179 <xsl:otherwise>XPath2</xsl:otherwise>
180 </xsl:choose>();
181 }
182 ((SimpleNode)tree.jjtGetChild(0)).dump("|") ;
183 }
184 catch(ParseException pe)
185 {
186 System.err.println(pe.getMessage());
187 }
188 catch(Exception e)
189 {
190 System.err.println(e.getMessage());
191 }
192 }
193 }
194 }
195
196 PARSER_END(<xsl:value-of select="$parser-class"/>)
197
198 </xsl:template>
199
200 <xsl:template name="action-production">
201 <!-- Begin LV -->
202 <xsl:if test="@prod-user-action">
203 <xsl:value-of select="@prod-user-action"/>
204 </xsl:if>
205 <!-- End LV -->
206 </xsl:template>
207
208 <xsl:template name="action-production-end">
209 </xsl:template>
210
211 <xsl:template name="action-exprProduction-label">
212 <xsl:if test="@node-type='void'">
213 <xsl:text> #void </xsl:text>
214 </xsl:if>
215 </xsl:template>
216
217
218 <xsl:template name="action-exprProduction">
219 </xsl:template>
220
221 <xsl:template name="action-exprProduction-end">
222 </xsl:template>
223
224 <xsl:template name="action-level">
225 <xsl:param name="thisProd"/>
226 <xsl:param name="nextProd"/>
227
228 <xsl:if test="@level-user-action">
229 <xsl:value-of select="@level-user-action"/>
230 </xsl:if>
231 <!-- xsl:text>
232 printIndent(); System.err.println("</xsl:text>
233 <xsl:value-of select="$thisProd"/>
234 <xsl:text>");
235 </xsl:text -->
236 </xsl:template>
237
238 <xsl:template name="action-level-jjtree-label">
239 <xsl:param name="label">
240 <xsl:text>void</xsl:text>
241 </xsl:param>
242 <!-- Begin SMPG -->
243 <xsl:param name="condition"></xsl:param>
244 <!-- End SMPG -->
245
246 <xsl:text> #</xsl:text>
247 <xsl:value-of select="$label"/>
248
249 <!-- Begin SMPG -->
250 <xsl:if test="$condition != ''">
251 <xsl:text>(</xsl:text>
252 <xsl:value-of select="$condition"/>
253 <xsl:text>)</xsl:text>
254 </xsl:if>
255 <!-- End SMPG -->
256 </xsl:template>
257
258 <xsl:template name="binary-action-level-jjtree-label">
259 <xsl:param name="label"/>
260 <xsl:param name="which" select="'unknown'"/>
261 <!-- xsl:message>
262 <xsl:text>In binary-action-level-jjtree-label: </xsl:text>
263 <xsl:value-of select="name(.)"/>
264 <xsl:text> (</xsl:text>
265 <xsl:value-of select="$which"/>
266 <xsl:text>)</xsl:text>
267 </xsl:message -->
268 <xsl:if test="ancestor-or-self::g:binary or self::g:level/g:binary">
269 <xsl:text>
270 {
271 try
272 {
273 jjtThis.processToken((Token)binaryTokenStack.pop());
274 }
275 catch(java.util.EmptyStackException e)
276 {
277 token_source.printLinePos();
278 e.printStackTrace();
279 throw e;
280 }
281 }
282 </xsl:text>
283 <xsl:text> #</xsl:text><xsl:value-of select="$label"/><xsl:text>(2)</xsl:text>
284 </xsl:if>
285 </xsl:template>
286
287 <xsl:template name="set-parser-package">
288 </xsl:template>
289
290 <xsl:template name="action-level-start">
291 </xsl:template>
292
293 <xsl:template name="action-level-end">
294 </xsl:template>
295
296 <xsl:template name="action-token-ref">
297 <!-- xsl:if test="ancestor::g:binary">
298 <xsl:text> #</xsl:text><xsl:value-of select="@name"/>
299 </xsl:if -->
300 <xsl:choose>
301 <xsl:when test="not(ancestor::g:binary or ancestor-or-self::g:*/@is-binary='yes')">
302 <xsl:choose>
303 <xsl:when test="key('ref',@name)/self::g:token/@node-type='void'">
304 <!-- Don't produce a node. #void doesn't seem to work here, for some reason. -->
305 </xsl:when>
306 <xsl:when test="@node-type='void'">
307 <!-- Don't produce a node. #void doesn't seem to work here, for some reason. -->
308 </xsl:when>
309 <xsl:when test="key('ref',@name)/self::g:token/@node-type">
310 <xsl:text>{</xsl:text>
311 <xsl:if test="@token-user-action">
312 <xsl:value-of select="@token-user-action"/>
313 </xsl:if>
314 <xsl:text>jjtThis.processToken(token);}</xsl:text>
315 <xsl:text> #</xsl:text>
316 <xsl:value-of select="key('ref',@name)/self::g:token/@node-type"/>
317 <!-- See JTree doc for why I do the following... -->
318 <xsl:if test="true() or following-sibling::*[1][self::g:zeroOrMore or self::g:oneOrMore]">
319 <xsl:text>(true)</xsl:text>
320 </xsl:if>
321 </xsl:when>
322 <xsl:when test="@node-type">
323 <xsl:text>{</xsl:text>
324 <xsl:if test="@token-user-action">
325 <xsl:value-of select="@token-user-action"/>
326 </xsl:if>
327 <xsl:text>jjtThis.processToken(token);}</xsl:text>
328 <xsl:text> #</xsl:text>
329 <xsl:value-of select="@node-type"/>
330 <!-- See JTree doc for why I do the following... -->
331 <xsl:if test="true() or following-sibling::*[1][self::g:zeroOrMore or self::g:oneOrMore]">
332 <xsl:text>(true)</xsl:text>
333 </xsl:if>
334 </xsl:when>
335 <xsl:otherwise>
336 <xsl:text>{</xsl:text>
337 <xsl:if test="@token-user-action">
338 <xsl:value-of select="@token-user-action"/>
339 </xsl:if>
340 <xsl:text>jjtThis.processToken(token);}</xsl:text>
341 <xsl:text> #</xsl:text>
342 <xsl:value-of select="@name"/>
343 <!-- See JTree doc for why I do the following... -->
344 <xsl:if test="true() or following-sibling::*[1][self::g:zeroOrMore or self::g:oneOrMore]">
345 <xsl:text>(true)</xsl:text>
346 </xsl:if>
347 </xsl:otherwise>
348 </xsl:choose>
349
350
351 </xsl:when>
352 <xsl:otherwise>
353 <!-- xsl:message>
354 <xsl:text>In binary-action-level-jjtree-label: </xsl:text>
355 <xsl:value-of select="name(.)"/>
356 </xsl:message -->
357 {binaryTokenStack.push(token);}
358 </xsl:otherwise>
359 </xsl:choose>
360 </xsl:template>
361
362 <!-- Begin LV -->
363 <xsl:template name="user-action-ref-start">
364 <xsl:if test="@nt-user-action-start">{<xsl:value-of select="@nt-user-action-start"/>}</xsl:if>
365 </xsl:template>
366
367 <xsl:template name="user-action-ref-end">
368 <xsl:if test="@nt-user-action-end">{<xsl:value-of select="@nt-user-action-end"/>}</xsl:if>
369 </xsl:template>
370 <!-- End LV -->
371
372 </xsl:stylesheet>