01: /*
02: * $Id: CallStatement.java,v 1.21 2002/09/16 08:05:06 jkl Exp $
03: *
04: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
05: *
06: * Use is subject to license terms, as defined in
07: * Anvil Sofware License, Version 1.1. See LICENSE
08: * file, or http://njet.org/license-1.1.txt
09: */
10: package anvil.script.statements;
11:
12: import anvil.Location;
13: import anvil.parser.Tag;
14: import anvil.ErrorListener;
15: import anvil.script.compiler.ByteCompiler;
16: import anvil.script.Context;
17: import anvil.script.Name;
18: import anvil.script.Type;
19: import anvil.script.expression.LinkNode;
20: import anvil.script.expression.Expression;
21: import anvil.script.expression.ExpressionList;
22: import anvil.script.expression.Node;
23: import anvil.script.expression.Parent;
24: import anvil.script.parser.ParserBase;
25: import anvil.script.parser.ExpressionParser;
26: import anvil.script.parser.TemplateParser;
27: import anvil.script.Grammar;
28: import java.io.IOException;
29: import java.util.StringTokenizer;
30:
31: /**
32: * class CallStatement
33: *
34: * @author: Jani Lehtimäki
35: */
36: public class CallStatement extends EvalStatement {
37:
38: public CallStatement(Statement parent, Location location) {
39: super (parent, location);
40: }
41:
42: public int typeOf() {
43: return Statement.ST_CALL;
44: }
45:
46: public String name() {
47: return "call";
48: }
49:
50: public void parse(TemplateParser parser, Tag tag) {
51: Parent parameters;
52: Location location = getLocation();
53:
54: String params = tag.getValue("params");
55: if (params != null) {
56: ExpressionParser p = new ExpressionParser(parser, parser
57: .getLocation(), params);
58: parameters = p.parseParameterList();
59:
60: } else {
61: int size = 0;
62: int n = tag.getLength();
63: for (int i = 0; i < n; i++) {
64: if (tag.getName(i).equalsIgnoreCase("param")) {
65: size++;
66: }
67: }
68: parameters = new ExpressionList(size);
69: int c = 0;
70: for (int i = 0; i < n; i++) {
71: if (tag.getName(i).equalsIgnoreCase("param")) {
72: Expression expression = Grammar.parseExpression(tag
73: .getValue(i), location, parser);
74: parameters.setChild(c++, expression);
75: }
76: }
77: }
78:
79: String dottedname = tag.getValue("function");
80: if (dottedname != null) {
81: Name name = Grammar.parseDottedName(parser, location,
82: dottedname);
83: if (name != null) {
84: _expression = new Expression(new LinkNode(this ,
85: location, name, parameters, LinkNode.GET),
86: location);
87: }
88: } else {
89: parser.error(location, "Attribute 'function' not given");
90: }
91:
92: }
93:
94: }
|