Debian Codegraph @

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

raw
1 <?xml version="1.0"?>
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 <!-- $Id: javacc.xsl,v 1.8 2004/06/02 13:46:25 sboag Exp $ -->
16
17 <!-- Use spec=xpath to generate an XQuery grammar rather
18 than an XQuery grammar. -->
19
20 <!-- ============== CHANGE LOG: ==============
21 $Log: javacc.xsl,v $
22 Revision 1.8 2004/06/02 13:46:25 sboag
23 Tweak to handle double quotes in strings.
24
25 Revision 1.7 2004/05/31 18:29:58 sboag
26 Latest grammar changes, part of last call comments response. (Sorry for lack
27 of fine-grained detail, but CVS has been down for a week.)
28
29 Revision 1.6 2004/01/26 02:04:09 sboag
30 Removed some dead code.
31
32 Revision 1.5 2004/01/25 22:16:51 sboag
33 Updata language proposal integrated. Note that the language conditional mechanism has changed a bit.
34
35 Revision 1.4 2003/09/10 17:38:45 sboag
36 Items from http://lists.w3.org/Archives/Member/w3c-query-editors/2003Sep/0028.html all addressed. Some fixes for construction of AST. Build target for test with formal XQuery test suite.
37
38 Revision 1.4 2003/09/02 03:55:21 sboag
39 Make isStep into a global, in order to make it possible for "dot" to be treated as a path expression (though it is now a primary expression). Basic smoke test passes now, which is not to say I expect deeper testing to pass.
40
41 Revision 1.3 2003/09/01 19:55:55 sboag
42 Incremental checkin: basic PathExpressions seem to work (based only on test of foo/baz and foo()).
43
44 Revision 1.2 2003/08/26 15:12:26 sboag
45 On Lionel's advice, am removing the src directory and associated bat files.
46
47 Revision 1.3 2003/07/08 16:03:49 sboag
48 Add handling of exposition-only attribute.
49
50 Revision 1.2 2003/04/18 19:27:46 sboag
51 Fix problem with curly brace state transition for computed element and attribute constructors.
52
53 Revision 1.1 2003/04/07 22:18:01 sboag
54 Initial checkin of language build and parser build.
55
56 Revision 1.19 2003/03/20 12:48:04 sboag
57 no message
58
59 Revision 1.18 2003/03/05 15:33:00 sboag
60 Major changes for new SequenceType, etc.
61
62 Revision 1.17 2003/02/10 23:01:33 sboag
63 Implemented new alias-for attribute, which makes a token act as a sort of a
64 proxy for another definition. In the JavaCC transformation, this token acts as
65 a true token for the sake of state transitioning. In the BNF, the token is converted
66 to the token it is acting as an alias for.
67
68 Revision 1.16 2003/01/15 04:41:01 sboag
69 Major update to redo the structure of the lexical specification in xpath-grammar.xml
70 to make maintenence easier. Also, fixed up the DTD so xpath-grammar.xml now
71 validates.
72
73 Revision 1.15 2002/11/29 17:20:57 sboag
74 Minor changes for pathx1 parser.
75
76 Revision 1.14 2002/11/06 07:42:25 sboag
77 1) I did some work on BNF production numbering. At least it is consecutive
78 now in regards to the defined tokens.
79
80 2) (XQuery only) I added URL Literal to the main list of literals, and added a
81 short note that it is defined equivalently to string literal. URL Literal has to
82 exist right now for relatively esoteric purposes for transitioning the lexical
83 state (to DEFAULT rather than OPERATOR as StringLiteral does). It is
84 used in DefaultCollationDecl, NamespaceDecl, SubNamespaceDecl, and
85 DefaultNamespaceDecl. To be clear, URL Literal was already in the August
86 draft, I just added it to the list of literals in the main doc.
87
88 Revision 1.13 2002/10/22 16:51:08 sboag
89 New Grammar Issues List. New productions:
90 OrderBy, ComputedTextConstructor, PositionVar, Castable, As (TypeDecl).
91 Removed:
92 unordered, SortExpr
93 Fixed reserved word bugs with:
94 empty, stable
95 Other minor "fixes":
96 Change precedence of UnaryExpr to be looser binding than UnionExpr
97 Change RangeExpr to only allow one "to".
98
99 Revision 1.12 2002/07/28 19:54:13 sboag
100 Fixed problems with import, '*', '?', and ',', reported by Jonathan and Dana.
101
102 Revision 1.11 2002/07/18 01:17:39 sboag
103 Fixed some bugs.
104
105 Revision 1.10 2002/07/15 07:25:47 sboag
106 Bug fixes, added match patterns, and responses to
107 Don's email http://lists.w3.org/Archives/Member/w3c-xml-query-wg/2002Jul/0156.html.
108
109 Revision 1.9 2002/06/28 09:02:07 sboag
110 Merged Don's latest work with new grammar proposal. Changes too numerous
111 to detail.
112
113 Revision 1.8 2002/03/17 21:31:08 sboag
114 Made new grammar element, <next/> for use in primary or prefix expressions,
115 to control when the next element is going to be called. Somewhat experemental.
116
117 Changed javacc stylesheet and bnf stylesheets to handle g:next.
118
119 Fixed bugs with child::text(), by adding text, comment, etc., tokens to after forward
120 or reverse axis. (note: have to do the same to names after @). This is yet
121 another bad hack.
122
123 Fixed bug with @type, by adding At token to lexical stateswitch into QNAME state
124 for XQuery.
125
126 Revision 1.7 2002/03/13 15:45:05 sboag
127 Don changes (XPathXQuery.xml, introduction.xml, fragment.xml):
128 I have attempted to update these files with the latest terminology
129 (mainly changing "simple value" to "atomic value" and related changes.)
130
131 Grammar changes:
132 Moral equal of Philip Wadler's structural changes of 02/05/2002.
133 Make lookahead(2) so that ElementNameOrFunctionCall can be broken up
134 without using long tokens.
135 Integrated Robie's SequenceType productions.
136 Added Add Validate Production.
137 Reviewed and tweaked changes against Named Typing proposal.
138 Fixed Dana's bug about ContentElementConstructor and
139 ContentAttributeConstructor in ElementContent.
140 Allow multiple variable binding for some/every.
141 Lift restrictions of "." and "..".
142 add XmlComment and XmlProcessingInstruction and also CdataSection to the
143 Constructor production.
144 Remove The Ref and Colon tokens.
145 Made multiply & star one token for XQuery, in spite of the fact that this causes
146 ambiguity.
147 Remove XQUERY_COMMENT state that is never entered.
148 Add QNAME lexical state for qnames following explicit axes, i.e. child::div.
149 BUG: child::text() will fail in XQuery.
150 BUG: Validate does not work so well for XPath.
151
152 Revision 1.6 2002/03/06 12:40:55 sboag
153 Tweak to make it possible to have prefix productions with optional suffixes.
154
155 Revision 1.5 2001/12/09 22:07:16 sboag
156 Fixed problem with comments from previous checkin.
157
158 -sb 10/29/01 Make parser productions extensible by an importing stylesheet.
159 ============== END CHANGE LOG ============== -->
160
161 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
162 xmlns:g="http://www.w3.org/2001/03/XPath/grammar">
163
164 <xsl:param name="spec" select="'xquery'"/>
165
166 <xsl:strip-space elements="*"/>
167 <!-- workaround for Xalan bug. -->
168 <xsl:preserve-space elements="g:char"/>
169
170 <xsl:output method="text" encoding="iso-8859-1"/>
171
172 <xsl:key name="ref" match="g:token|g:production"
173 use="@name"/>
174
175 <xsl:template match="g:*"
176 priority="-2000"/>
177
178 <xsl:template match="g:*[@exposition-only='yes']"
179 priority="+2000"/>
180
181 <xsl:template name="parser">
182 PARSER_BEGIN(XPath)
183
184 public class XPath {
185 boolean isStep = false;
186 public static void main(String args[]) throws ParseException {
187 XPath parser = new XPath(System.in);
188 parser.Input();
189 }
190 }
191
192 PARSER_END(XPath)
193 </xsl:template>
194
195 <!-- Action templates for overrides from derived stylesheets -->
196
197 <xsl:template name="action-production">
198 </xsl:template>
199
200 <xsl:template name="action-production-end">
201 </xsl:template>
202
203 <xsl:template name="action-exprProduction">
204 </xsl:template>
205
206 <xsl:template name="action-exprProduction-label">
207 </xsl:template>
208
209 <xsl:template name="action-exprProduction-end">
210 </xsl:template>
211
212 <xsl:template name="action-level">
213 </xsl:template>
214
215 <xsl:template name="action-level-jjtree-label"></xsl:template>
216 <xsl:template name="binary-action-level-jjtree-label"></xsl:template>
217
218 <xsl:template name="action-level-start">
219 </xsl:template>
220
221 <xsl:template name="action-level-end">
222 </xsl:template>
223
224 <xsl:template name="action-token-ref">
225 </xsl:template>
226
227 <!-- Begin LV -->
228 <xsl:template name="user-action-ref-start">
229 </xsl:template>
230
231 <xsl:template name="user-action-ref-end">
232 </xsl:template>
233 <!-- End LV -->
234
235 <xsl:template name="javacc-options">
236 STATIC = false;
237 LOOKAHEAD = 1;
238 </xsl:template>
239
240 <xsl:template name="input">
241 void Input() :
242 {}
243 {
244 <xsl:value-of select="g:start/@name"/>()&lt;EOF&gt;
245 }
246 </xsl:template>
247
248 <xsl:template match="g:grammar">options {
249 <xsl:call-template name="javacc-options"/>
250 }
251
252 <xsl:call-template name="parser"/>
253
254 TOKEN_MGR_DECLS : {
255 private Stack stateStack = new Stack();
256 // private Vector persistentLexStates = new Vector();
257 static final int PARENMARKER = 2000;
258
259 /**
260 * Push the current state onto the state stack.
261 */
262 private void pushState()
263 {
264 // System.err.println("pushing: "+curLexState); printLinePos();
265 stateStack.addElement(new Integer(curLexState));
266 }
267
268 /**
269 * Push the given state onto the state stack.
270 * @param state Must be a valid state.
271 */
272 private void pushState(int state)
273 {
274 stateStack.push(new Integer(state));
275 }
276
277 /**
278 * Pop the state on the state stack, and switch to that state.
279 */
280 private void popState()
281 {
282 if (stateStack.size() == 0)
283 {
284 printLinePos();
285 }
286
287 int nextState = ((Integer) stateStack.pop()).intValue();
288 // System.err.println("pop "+nextState); printLinePos();
289 if(nextState == PARENMARKER)
290 printLinePos();
291 SwitchTo(nextState);
292 }
293
294 /**
295 * Push the given state onto the state stack.
296 * @param state Must be a valid state.
297 */
298 private boolean isState(int state)
299 {
300 for (int i = 0; i &lt; stateStack.size(); i++) {
301 if(((Integer) stateStack.elementAt(i)).intValue() == state)
302 {
303 return true;
304 }
305 }
306 return false;
307 }
308
309 /**
310 * Push a parenthesis state. This pushes, in addition to the
311 * lexical state value, a special marker that lets
312 * resetParenStateOrSwitch(int state)
313 * know if it should pop and switch. Used for the comma operator.
314 */
315 private void pushParenState(int commaState, int rparState)
316 {
317 stateStack.push(new Integer(rparState));
318 stateStack.push(new Integer(commaState));
319 stateStack.push(new Integer(PARENMARKER));
320 SwitchTo(commaState);
321 }
322
323
324 /**
325 * Print the current line position.
326 */
327 public void printLinePos()
328 {
329 System.err.println("Line: " + input_stream.getEndLine());
330 }
331 }
332
333 <xsl:call-template name="input"/>
334
335 <xsl:apply-templates select="*"/>
336 </xsl:template>
337
338 <xsl:template match="g:state-list"/>
339
340 <!-- END SB CHANGE: Make parser productions extensible by an importing stylesheet -->
341
342
343 <xsl:template match="g:token|g:special">
344
345 <xsl:variable name="tname" select="@name"/>
346 <xsl:variable name="otoken" select="."/>
347 <xsl:variable name="trefs"
348 select="/g:grammar/g:state-list//g:tref[@name=$tname]"/>
349
350 <!-- At this time, flag an error if the token is not defined in the
351 transition tables! -->
352 <xsl:if test="not($trefs)">
353 <xsl:message terminate="yes">
354 <xsl:text>Transition not defined: </xsl:text>
355 <xsl:value-of select="@name"/>
356 </xsl:message>
357 </xsl:if>
358
359 <xsl:variable name="token" select="key('ref', @alias-for)|self::*[not(@alias-for)]"/>
360
361 <xsl:for-each select="$token">
362 <xsl:for-each select="$trefs">
363 <!-- Assert that this token occurs only once in this state! -->
364 <xsl:variable name="state" select="ancestor::g:state"/>
365 <xsl:if test="count($state//g:tref[@name=$tname]) > 1">
366 <xsl:message terminate="yes">
367 <xsl:text>Token multiply defined in same state: </xsl:text>
368 <xsl:value-of select="$tname"/>
369 </xsl:message>
370 </xsl:if>
371 <!-- JavaCC won't let us define a token per state, so test if this is
372 the first tref, then process the rest of the trefs to make a
373 comma delimited list per token. -->
374 <xsl:variable name="allTRefsOfName"
375 select="/g:grammar/g:state-list/g:state//g:tref[@name=$tname]"/>
376 <xsl:variable name="isFirstOccurance"
377 select="$allTRefsOfName[(position() = 1)
378 and (ancestor::g:state/@name = $state/@name)]"/>
379 <xsl:if test="$isFirstOccurance">
380 <xsl:text>&#10;</xsl:text>
381 <xsl:if test="not($state/@name='ANY')">
382 <xsl:text>&lt;</xsl:text>
383 <xsl:for-each select="$allTRefsOfName">
384 <xsl:value-of select="ancestor::g:state/@name"/>
385 <xsl:if test="last()!=position()">
386 <xsl:text>, </xsl:text>
387 </xsl:if>
388 </xsl:for-each>
389
390 <xsl:text>&gt;&#10;</xsl:text>
391 </xsl:if>
392 <xsl:choose>
393 <xsl:when test="($token/@more='yes') or $otoken/@more='yes'">
394 <xsl:text>MORE </xsl:text>
395 </xsl:when>
396 <xsl:when test="($token/@special='yes') or $otoken/@special='yes'">
397 <xsl:text>SPECIAL_TOKEN </xsl:text>
398 </xsl:when>
399 <xsl:when test="$token/@skip='yes' or $otoken/@skip='yes'">
400 <xsl:text>SKIP </xsl:text>
401 </xsl:when>
402 <xsl:otherwise>
403 <xsl:text>TOKEN </xsl:text>
404 </xsl:otherwise>
405 </xsl:choose>
406
407 <xsl:text>:&#10;{&#10; &lt; </xsl:text>
408 <xsl:if test="$state/@name='ANY'">#</xsl:if>
409
410 <xsl:value-of select="$tname"/>
411 <xsl:text> : </xsl:text>
412 <xsl:for-each select="$token">
413 <xsl:call-template name="space"/>
414 </xsl:for-each>
415 <xsl:text> &gt;</xsl:text>
416 <xsl:variable name="action" select="$trefs/ancestor::g:transition/@action"/>
417 <!-- assert correctness -->
418 <xsl:if test="$action and count($action) &gt; 1">
419 <xsl:for-each select="$trefs[ancestor::g:transition/@action]">
420 <xsl:if test="ancestor::g:transition/@action != $action[1]">
421 <xsl:message terminate="yes">
422 <xsl:text>Error! Actions of transitions are not consistent! </xsl:text>
423 <xsl:value-of select="$tname"/>
424 </xsl:message>
425 </xsl:if>
426 </xsl:for-each>
427 </xsl:if>
428 <xsl:choose>
429 <xsl:when test="contains($action, '(')">
430 <xsl:text> { </xsl:text>
431 <xsl:value-of select="$action"/>
432 <xsl:text>; }</xsl:text>
433 </xsl:when>
434 <xsl:when test="normalize-space($action) = 'input_stream.backup'">
435 <xsl:message>$action(2): <xsl:value-of select="$action"/></xsl:message>
436 <xsl:text> { </xsl:text>
437 <!-- xsl:text>System.out.println("lengthOfMatch: "+lengthOfMatch);</xsl:text -->
438 <xsl:value-of select="$action"/>
439 <xsl:text>(</xsl:text>
440 <xsl:text>lengthOfMatch</xsl:text>
441 <xsl:text>)</xsl:text>
442 <xsl:text>; }</xsl:text>
443 </xsl:when>
444 <xsl:when test="$action">
445 <xsl:text> { </xsl:text>
446 <xsl:value-of select="$action"/>
447 <xsl:text>(); }</xsl:text>
448 </xsl:when>
449 </xsl:choose>
450
451 <xsl:variable name="nextLexState"
452 select="$trefs/ancestor::g:transition/@next-state"/>
453
454 <!-- assert correctness -->
455 <xsl:if test="$nextLexState and count($nextLexState) &gt; 1">
456 <xsl:for-each select="$trefs[ancestor::g:transition/@next-state]">
457 <xsl:if test="ancestor::g:transition/@next-state != $nextLexState[1]">
458 <xsl:message terminate="yes">
459 <xsl:text>Error! Next-state of transitions are not consistent! </xsl:text>
460 <xsl:value-of select="$tname"/>
461 </xsl:message>
462 </xsl:if>
463 </xsl:for-each>
464 </xsl:if>
465
466 <xsl:if test="$nextLexState">
467 <xsl:text> : </xsl:text>
468 <xsl:value-of select="$nextLexState"/>
469 </xsl:if>
470 <xsl:text>&#10;}&#10;</xsl:text>
471 </xsl:if>
472 </xsl:for-each>
473 </xsl:for-each>
474 </xsl:template>
475
476 <xsl:template match="g:skip">
477 <xsl:if test="@recognize">
478 <xsl:text>&lt;</xsl:text>
479 <xsl:call-template name="replace-char">
480 <xsl:with-param name="string" select="@recognize"/>
481 <xsl:with-param name="from" select="' '"/>
482 <xsl:with-param name="to" select="', '"/>
483 </xsl:call-template>
484 <xsl:text>&gt;</xsl:text>
485 </xsl:if>
486 SKIP:
487 {
488 &lt; &lt;skip_&gt;&gt;
489 }
490
491 TOKEN :
492 {
493 &lt; #skip_ : <xsl:call-template name="space"/> &gt;
494 }
495
496 </xsl:template>
497
498 <xsl:template match="g:char|g:string">
499 <xsl:if test="@complement='yes'">
500 <xsl:text>~</xsl:text>
501 </xsl:if>
502 <xsl:text>"</xsl:text>
503 <xsl:call-template name="replace-char">
504 <xsl:with-param name="string" select="."/>
505 <xsl:with-param name="from" select="'&quot;'"/>
506 <xsl:with-param name="to" select="'\&quot;'"/>
507 </xsl:call-template>
508 <xsl:text>"</xsl:text>
509 </xsl:template>
510
511 <!-- For some reason, the JavaCC generated lexer produces a lexical error for a "]" if
512 we use ]]> as a single token. -->
513 <xsl:template match="g:string[.=']]&gt;']">
514 <xsl:text>("]" "]" ">")</xsl:text>
515 </xsl:template>
516
517 <xsl:template match="g:string[@ignoreCase]">
518 <xsl:text>(</xsl:text>
519 <xsl:call-template name="ignore-case">
520 <xsl:with-param name="string" select="."/>
521 </xsl:call-template>
522 <xsl:text>)</xsl:text>
523 </xsl:template>
524
525 <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
526 <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
527
528 <xsl:template name="ignore-case">
529 <xsl:param name="string" select="''"/>
530 <xsl:if test="$string">
531 <xsl:variable name="c" select="substring($string,1,1)"/>
532 <xsl:variable name="uc" select="translate($c,$lower,$upper)"/>
533 <xsl:variable name="lc" select="translate($c,$upper,$lower)"/>
534 <xsl:choose>
535 <xsl:when test="$lc=$uc">
536 <xsl:text>"</xsl:text>
537 <xsl:value-of select="$c"/>
538 <xsl:text>"</xsl:text>
539 </xsl:when>
540 <xsl:otherwise>
541 <xsl:text>["</xsl:text>
542 <xsl:value-of select="$uc"/>
543 <xsl:text>", "</xsl:text>
544 <xsl:value-of select="$lc"/>
545 <xsl:text>"]</xsl:text>
546 </xsl:otherwise>
547 </xsl:choose>
548 <xsl:if test="substring($string,2)">
549 <xsl:text xml:space="preserve"> </xsl:text>
550 </xsl:if>
551 <xsl:call-template name="ignore-case">
552 <xsl:with-param name="string" select="substring($string,2)"/>
553 </xsl:call-template>
554 </xsl:if>
555 </xsl:template>
556
557 <xsl:template match="g:eof">&lt;EOF&gt;</xsl:template>
558
559 <xsl:template match="g:charCode">
560 <xsl:text>"</xsl:text>
561 <xsl:choose>
562 <xsl:when test="@value='000A'">
563 <xsl:text>\n</xsl:text>
564 </xsl:when>
565 <xsl:when test="@value='000D'">
566 <xsl:text>\r</xsl:text>
567 </xsl:when>
568 <xsl:when test="@value='0009'">
569 <xsl:text>\t</xsl:text>
570 </xsl:when>
571 <xsl:when test="@value='0020'">
572 <xsl:text xml:space="preserve"> </xsl:text>
573 </xsl:when>
574 <xsl:otherwise>
575 <xsl:text>\u</xsl:text>
576 <xsl:value-of select="@value"/>
577 </xsl:otherwise>
578 </xsl:choose>
579 <xsl:text>"</xsl:text>
580 </xsl:template>
581
582 <xsl:template match="g:charClass">
583 <xsl:text>[</xsl:text>
584 <xsl:for-each select="*">
585 <xsl:if test="position()!=1">
586 <xsl:text>, </xsl:text>
587 </xsl:if>
588 <xsl:apply-templates select="."/>
589 </xsl:for-each>
590 <xsl:text>]</xsl:text>
591 </xsl:template>
592
593 <xsl:template match="g:charRange">
594 <xsl:text>"</xsl:text>
595 <xsl:value-of select="@minChar"/>
596 <xsl:text>" - "</xsl:text>
597 <xsl:value-of select="@maxChar"/>
598 <xsl:text>"</xsl:text>
599 </xsl:template>
600
601 <xsl:template match="g:charCodeRange">
602 <xsl:text>"\u</xsl:text>
603 <xsl:value-of select="@minValue"/>
604 <xsl:text>" - "\u</xsl:text>
605 <xsl:value-of select="@maxValue"/>
606 <xsl:text>"</xsl:text>
607 </xsl:template>
608
609 <xsl:template match="g:complement">~<xsl:apply-templates/></xsl:template>
610
611 <xsl:template match="g:production">
612 <xsl:text>void </xsl:text>
613 <xsl:value-of select="@name"/>
614 <xsl:text>() </xsl:text>
615 <xsl:choose>
616 <xsl:when test="@is-binary='yes'">
617 <xsl:call-template name="action-level-jjtree-label"/>
618 </xsl:when>
619 <xsl:when test="@node-type">
620 <xsl:call-template name="action-level-jjtree-label">
621 <xsl:with-param name="label" select="@node-type"/>
622 <xsl:with-param name="condition" select="@condition"/>
623 </xsl:call-template>
624 </xsl:when>
625 <!-- Begin LV -->
626 <xsl:when test="@condition">
627 <xsl:call-template name="action-level-jjtree-label">
628 <xsl:with-param name="label" select="@name"/>
629 <xsl:with-param name="condition" select="@condition"/>
630 </xsl:call-template>
631 </xsl:when>
632 <!-- End LV -->
633 <xsl:otherwise>
634 </xsl:otherwise>
635 </xsl:choose>
636 <xsl:text> :</xsl:text>
637 {<xsl:call-template name="action-production"/>}
638 {
639 <xsl:call-template name="space"/>
640 <xsl:call-template name="action-production-end"/>
641 }
642
643 </xsl:template>
644
645 <xsl:template match="g:exprProduction">
646 <xsl:variable name="name"
647 select="@name"/>void <xsl:value-of select="$name"/>() <xsl:call-template name="action-exprProduction-label"/> :
648 {<xsl:call-template name="action-exprProduction"/>}
649 {
650 <xsl:variable name="levels" select="g:level[*]"/>
651 <xsl:variable name="nextProd" select="concat($levels[1]/*/@name,'()')"/>
652 <xsl:value-of select="$nextProd"/>
653 <xsl:call-template name="action-exprProduction-end"/>
654 }
655
656 <xsl:for-each select="g:level[*]">
657 <!-- xsl:variable name="thisProd" select="concat($name,'_',position(),'()')"/>
658 <xsl:variable name="nextProd" select="concat($name,'_',position()+1,'()')"
659 / -->
660 <xsl:variable name="thisProd" select="concat(*/@name,'()')"/>
661 <xsl:variable name="levels" select="../g:level[*]"/>
662 <xsl:variable name="position" select="position()"/>
663
664 <xsl:variable name="nextProd" select="concat($levels[$position+1]/*/@name,'()')"
665 />void <xsl:value-of select="$thisProd"/>
666 <xsl:call-template name="action-level-jjtree-label">
667 <xsl:with-param name="label">
668 <xsl:choose>
669 <xsl:when test="@node-type">
670 <xsl:value-of select="@node-type"/>
671 </xsl:when>
672 <xsl:otherwise>
673 <xsl:choose>
674 <!-- <xsl:when test="not(g:binary) and */g:sequence"> SMPG -->
675 <xsl:when test="g:binary or */g:sequence">
676 <xsl:value-of select="*/@name"/>
677 <!-- xsl:text>void</xsl:text -->
678 </xsl:when>
679 <xsl:otherwise>
680 <xsl:text>void</xsl:text>
681 </xsl:otherwise>
682 </xsl:choose>
683 </xsl:otherwise>
684 </xsl:choose>
685 </xsl:with-param>
686
687 <!-- Begin SMPG -->
688 <xsl:with-param name="condition">
689 <xsl:choose>
690 <xsl:when test="g:binary or */g:sequence or */g:choice">
691 <xsl:value-of select="*/@condition"/>
692 </xsl:when>
693 <xsl:otherwise/>
694 </xsl:choose>
695 </xsl:with-param>
696 <!-- End SMPG -->
697
698 <xsl:with-param name="thisProd" select="$thisProd"/>
699 <xsl:with-param name="nextProd" select="$nextProd"/>
700 </xsl:call-template> :
701 {<xsl:call-template name="action-level">
702 <xsl:with-param name="thisProd" select="$thisProd"/>
703 <xsl:with-param name="nextProd" select="$nextProd"/>
704 </xsl:call-template>}
705 {
706 <xsl:call-template name="action-level-start"/>
707 <xsl:choose>
708 <xsl:when test="g:binary and g:postfix">
709 <xsl:value-of select="$nextProd"/>
710 <xsl:text> ((</xsl:text>
711
712 <xsl:call-template name="outputChoices">
713 <xsl:with-param name="choices"
714 select="g:binary"/>
715 <xsl:with-param name="lookahead" select="ancestor-or-self::*/@lookahead"/>
716 </xsl:call-template>
717 <xsl:text xml:space="preserve"> </xsl:text>
718 <xsl:value-of select="$nextProd"/>
719 <!-- xsl:value-of select="concat($name,'_1')"/><xsl:text>()</xsl:text -->
720
721 <xsl:call-template name="binary-action-level-jjtree-label">
722 <xsl:with-param name="label" select="*/@name"/>
723 <xsl:with-param name="which" select="1"/>
724 </xsl:call-template>
725
726 <xsl:text>) | </xsl:text>
727
728 <xsl:call-template name="outputChoices">
729 <xsl:with-param name="choices"
730 select="g:postfix"/>
731 <xsl:with-param name="lookahead" select="ancestor-or-self::*/@lookahead"/>
732 </xsl:call-template>
733 <xsl:text>)*</xsl:text>
734 </xsl:when>
735
736 <xsl:when test="g:binary">
737 <xsl:value-of select="$nextProd"/>
738 <xsl:text> (</xsl:text>
739 <xsl:call-template name="outputChoices">
740 <xsl:with-param name="choices"
741 select="g:binary"/>
742 <xsl:with-param name="lookahead" select="ancestor-or-self::*/@lookahead"/>
743 </xsl:call-template>
744
745 <xsl:text xml:space="preserve"> </xsl:text>
746
747 <xsl:value-of select="$nextProd"/>
748 <xsl:call-template name="binary-action-level-jjtree-label">
749 <xsl:with-param name="label" select="*/@name"/>
750 <xsl:with-param name="which" select="2"/>
751 </xsl:call-template>
752 <!-- xsl:value-of select="concat($name,'_1')"/><xsl:text>()</xsl:text -->
753
754 <!--
755 <xsl:variable name="thisName" select="g:binary/@name"/>
756 <xsl:text>(</xsl:text>
757 <xsl:for-each select="../g:level[*]">
758 <xsl:variable name="theExprName" select="concat($name,'_',position(),'()')"/>
759 <xsl:if test="not(*/@name = $thisName)">
760 <xsl:value-of select="$theExprName"/>
761 <xsl:if test="not(last()=position())"> | </xsl:if>
762 </xsl:if>
763 </xsl:for-each>
764 <xsl:text>)</xsl:text>
765 -->
766
767 <xsl:text>)</xsl:text>
768 <xsl:choose>
769 <xsl:when test="g:binary/@prefix-seq-type">
770 <xsl:value-of select="g:binary/@prefix-seq-type"/>
771 </xsl:when>
772 <xsl:otherwise>
773 <xsl:text>*</xsl:text>
774 </xsl:otherwise>
775 </xsl:choose>
776
777 </xsl:when>
778 <xsl:when test="g:postfix">
779 <xsl:if test="following-sibling::g:level">
780 <xsl:value-of select="$nextProd"/>
781 </xsl:if>
782 <xsl:text xml:space="preserve"> </xsl:text>
783 <xsl:call-template name="outputChoices">
784 <xsl:with-param name="choices"
785 select="g:postfix"/>
786 </xsl:call-template>
787 <xsl:choose>
788 <xsl:when test="g:postfix/@prefix-seq-type">
789 <xsl:value-of select="g:postfix/@prefix-seq-type"/>
790 </xsl:when>
791 <xsl:otherwise>
792 <xsl:text>*</xsl:text>
793 </xsl:otherwise>
794 </xsl:choose>
795
796 </xsl:when>
797 <xsl:when test="g:prefix">
798 <xsl:choose>
799 <xsl:when test="g:prefix/@suffix-optional='yes'">
800 <xsl:text>(</xsl:text>
801 <xsl:call-template name="outputChoices">
802 <xsl:with-param name="choices"
803 select="g:prefix"/>
804 </xsl:call-template>
805 <xsl:text>(</xsl:text>
806 <xsl:value-of select="$nextProd"/>
807 <xsl:text>)</xsl:text>
808 <xsl:text>? </xsl:text>
809 <xsl:value-of select="$nextProd"/>
810 <xsl:text>)</xsl:text>
811
812 <xsl:text> | </xsl:text>
813 <xsl:if test="not(g:prefix//g:next)">
814 <xsl:value-of select="$nextProd"/>
815 </xsl:if>
816 </xsl:when>
817 <xsl:otherwise>
818 <xsl:call-template name="outputChoices">
819 <xsl:with-param name="choices"
820 select="g:prefix"/>
821 </xsl:call-template>
822 <xsl:choose>
823 <xsl:when test="g:prefix/@prefix-seq-type">
824 <xsl:value-of select="g:prefix/@prefix-seq-type"/>
825 </xsl:when>
826 <xsl:otherwise>
827 <xsl:text>*</xsl:text>
828 </xsl:otherwise>
829 </xsl:choose>
830 <xsl:text> </xsl:text>
831 <xsl:if test="not(g:prefix//g:next)">
832 <xsl:value-of select="$nextProd"/>
833 </xsl:if>
834 </xsl:otherwise>
835 </xsl:choose>
836 </xsl:when>
837 <xsl:when test="g:primary">
838 <xsl:call-template name="outputChoices">
839 <xsl:with-param name="choices"
840 select="g:primary"/>
841 </xsl:call-template>
842 <xsl:if test="g:primary/following-sibling::g:level | following-sibling::g:level">
843 <xsl:text> | </xsl:text>
844 <xsl:value-of select="$nextProd"/>
845 </xsl:if>
846 </xsl:when>
847 <xsl:otherwise>
848 </xsl:otherwise>
849 </xsl:choose>
850 <xsl:call-template name="action-level-end"/>
851 }
852
853 </xsl:for-each>
854 </xsl:template>
855
856 <xsl:template name="outputChoices">
857 <xsl:param name="choices" select="/.."/>
858 <xsl:param name="lookahead" select="ancestor-or-self::*/@lookahead"/>
859
860 <xsl:if test="count($choices)>1">(</xsl:if>
861 <xsl:for-each select="$choices">
862 <xsl:if test="position()!=1"> | </xsl:if>
863 <xsl:if test="count(*)>1">(</xsl:if>
864 <xsl:for-each select="*">
865 <xsl:if test="position()!=1" xml:space="preserve"> </xsl:if>
866 <xsl:apply-templates select="."><xsl:with-param name="lookahead" select="$lookahead"/></xsl:apply-templates>
867 </xsl:for-each>
868 <xsl:if test="count(*)>1">)</xsl:if>
869 </xsl:for-each>
870 <xsl:if test="count($choices)>1">)</xsl:if>
871 </xsl:template>
872
873 <xsl:template match="g:optional">[<xsl:call-template name="lookahead"/>
874 <xsl:call-template name="space"/>]</xsl:template>
875
876 <xsl:template match="g:token//g:optional">(<xsl:call-template name="space"/>)?</xsl:template>
877 <xsl:template match="g:zeroOrMore">(<xsl:call-template name="lookahead"/>
878 <xsl:call-template name="space"/>)*</xsl:template>
879
880 <xsl:template match="g:oneOrMore">(<xsl:call-template name="lookahead"/>
881 <xsl:call-template name="space"/>)+ </xsl:template>
882
883 <xsl:template match="g:sequence">(<xsl:call-template name="lookahead"/>
884 <xsl:call-template name="space"/>)</xsl:template>
885
886 <xsl:template match="g:ref[@notational-only='yes']">
887 </xsl:template>
888
889 <xsl:template match="g:ref">
890 <xsl:choose>
891 <xsl:when test="key('ref',@name)/self::g:token">
892 <xsl:text>&lt;</xsl:text>
893 <xsl:value-of select="@name"/>
894 <xsl:text>&gt;</xsl:text>
895 <!-- show when a token match is a success. -sb -->
896 <xsl:if test="ancestor::g:level | ancestor::g:production">
897 <xsl:call-template name="action-token-ref"/>
898 <xsl:if test="ancestor::g:binary">
899 <!-- xsl:value-of select="$nextProd"/ -->
900
901 <!-- Awww... it's not so bad... -sb -->
902 <xsl:if test="false()">
903 <xsl:variable name="levels" select="ancestor::g:exprProduction/g:level[*]"/>
904 <xsl:variable name="position" select="count(ancestor::g:level/preceding-sibling::g:level[*])+1"/>
905 <xsl:variable name="nextProd" select="concat($levels[$position+1]/*/@name,'()')"/>
906
907 <!-- xsl:variable name="nextProd" select="concat(ancestor::g:exprProduction/@name,
908 '_', count(ancestor::g:level/preceding-sibling::g:level[*])+2,'()')"/ -->
909
910 <!-- xsl:value-of select="concat(ancestor::g:exprProduction/@name,'_1')"/ -->
911 <!-- xsl:text>()</xsl:text -->
912 <xsl:value-of select="$nextProd"/>
913
914 <xsl:call-template name="binary-action-level-jjtree-label">
915 <xsl:with-param name="which" select="3"/>
916 </xsl:call-template>
917 <xsl:text>
918 </xsl:text>
919 </xsl:if>
920 </xsl:if>
921 </xsl:if>
922 </xsl:when>
923 <xsl:otherwise>
924 <!-- Begin LV -->
925 <xsl:call-template name="user-action-ref-start"/>
926 <!-- End LV -->
927
928 <xsl:value-of select="@name"/>
929 <xsl:text>()</xsl:text>
930
931 <!-- Begin LV -->
932 <xsl:call-template name="user-action-ref-end"/>
933 <!-- End LV -->
934 </xsl:otherwise>
935 </xsl:choose>
936 </xsl:template>
937
938 <xsl:template match="g:next">
939 <!-- The assumption is this we're in a exprProduction,
940 in a prefix, primary, etc., and want to call the next level. -->
941 <xsl:variable name="levels" select="ancestor::g:exprProduction[1]/g:level[*]"/>
942 <xsl:variable name="position">
943 <xsl:variable name="uniqueIdOfThisLevel" select="generate-id(ancestor::g:level[1])"/>
944 <xsl:for-each select="$levels">
945 <xsl:if test="generate-id(.) = $uniqueIdOfThisLevel">
946 <xsl:value-of select="position()"/>
947 </xsl:if>
948 </xsl:for-each>
949 </xsl:variable>
950 <xsl:variable name="nextProd" select="concat($levels[$position+1]/*/@name,'()')"/>
951 <xsl:value-of select="$nextProd"/>
952 <!-- xsl:text>()</xsl:text -->
953 </xsl:template>
954
955 <xsl:template match="g:choice">
956 <xsl:variable name="lookahead" select="ancestor-or-self::*/@lookahead"/>
957 <xsl:if test="$lookahead > 0">LOOKAHEAD(<xsl:value-of select="$lookahead"/>) </xsl:if>
958 <xsl:text>(</xsl:text>
959 <xsl:for-each select="*[not(@notational-only='yes')]">
960 <xsl:if test="position()!=1">
961 <xsl:text> | </xsl:text>
962 </xsl:if>
963 <xsl:apply-templates select=".">
964 <xsl:with-param name="lookahead" select="$lookahead"/>
965 </xsl:apply-templates>
966
967 </xsl:for-each>
968 <xsl:text>)</xsl:text>
969 </xsl:template>
970
971 <!-- xsl:template match="g:choice" mode="binary">
972 <xsl:param name="name"/>
973 <xsl:text>(</xsl:text>
974 <xsl:for-each select="*">
975 <xsl:if test="position()!=1">
976 <xsl:text> | </xsl:text>
977 </xsl:if>
978 <xsl:apply-templates select="."/>
979 <xsl:value-of select="$name"/><xsl:text>()</xsl:text>
980 </xsl:for-each>
981 <xsl:text>)</xsl:text>
982 </xsl:template -->
983
984 <xsl:template match="g:requiredSkip">
985 <xsl:text>(&lt;skip_&gt;)+</xsl:text>
986 </xsl:template>
987
988 <xsl:template match="g:optionalSkip">
989 <xsl:text>(&lt;skip_&gt;)*</xsl:text>
990 </xsl:template>
991
992 <xsl:template name="lookahead" match="lookahead">
993 <xsl:if test="@lookahead">
994 <xsl:text>LOOKAHEAD(</xsl:text>
995 <xsl:value-of select="@lookahead"/>
996 <xsl:text>) </xsl:text>
997 </xsl:if>
998 </xsl:template>
999
1000 <xsl:template name="space">
1001 <xsl:for-each select="*">
1002 <xsl:if test="position()!=1">
1003 <xsl:text> </xsl:text>
1004 </xsl:if>
1005 <xsl:apply-templates select="."/>
1006 </xsl:for-each>
1007 </xsl:template>
1008
1009 <xsl:template name="replace-char">
1010 <xsl:param name="from" select="''"/>
1011 <xsl:param name="to" select="''"/>
1012 <xsl:param name="string" select="''"/>
1013 <xsl:if test="$string">
1014 <xsl:choose>
1015 <xsl:when test="substring($string,1,1)=$from">
1016 <!-- Added this to avoid empty commas in sequences of
1017 spaces. -sb -->
1018 <xsl:if test="not(substring($string,2,1)=$from and $from=' ')">
1019 <xsl:value-of select="$to"/>
1020 </xsl:if>
1021 </xsl:when>
1022 <xsl:otherwise>
1023 <xsl:value-of select="substring($string,1,1)"/>
1024 </xsl:otherwise>
1025 </xsl:choose>
1026 <xsl:call-template name="replace-char">
1027 <xsl:with-param name="string" select="substring($string, 2)"/>
1028 <xsl:with-param name="to" select="$to"/>
1029 <xsl:with-param name="from" select="$from"/>
1030 </xsl:call-template>
1031 </xsl:if>
1032 </xsl:template>
1033
1034 </xsl:stylesheet>