1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.millscript.loaders;
22
23 import org.millscript.millscript.expr.ConstantExpr;
24 import org.millscript.millscript.expr.IndexExpr;
25 import org.millscript.millscript.expr.NameExpr;
26
27 /**
28 * This class compiles a shortcut argument element in a MillScript XHTML
29 * template. A shortcut argument element has a name begining with
30 * <code>arg</code> and has a single digit after that, e.g. <code>arg1</code>
31 * is a shortcut for <code><arg n="1" /></code>.
32 */
33 public class ShortcutArgName implements SpecialTemplateName {
34
35 /**
36 * The argument number.
37 */
38 private final Integer argumentNumber;
39
40 /**
41 * The loader we will insert our expressions into.
42 */
43 private final BasicTemplateLoader basicTemplateLoader;
44
45 /**
46 * Constructs a new shortcut argument element handler, to insert
47 * expressions for the specified argument number into the specified loader.
48 *
49 * @param btl the loader to insert expressions into
50 * @param n the argument number of this shortcut
51 */
52 public ShortcutArgName( final BasicTemplateLoader btl, final int n ) {
53 this.argumentNumber = new Integer( n );
54 this.basicTemplateLoader = btl;
55 }
56
57 /**
58 * @see org.millscript.millscript.loaders.SpecialTemplateName#handle()
59 */
60 public void handle() {
61
62
63 this.basicTemplateLoader.tokenVisitor.parentTokenVisitor.pushChildElement(
64 IndexExpr.make(
65 new NameExpr( "arg" ),
66 new ConstantExpr(
67 this.argumentNumber
68 )
69 )
70 );
71 }
72
73 }