Package anvil.script.expression

Examples of anvil.script.expression.Expression


            default:
              buffer.append(ch);
            }
          }
         
          Expression expr = Grammar.parseExpression(buffer.toString(), getLocation(), parser);
          if (expr.isConstant()) {
            addChild(new CharacterDataStatement(this, parser.getLocation(), expr.eval().toString()));
          } else {
            addChild(new PrintStatement(this, parser.getLocation(), expr));
          }
          buffer.setLength(0);
         
View Full Code Here


      }
      parameters = new ExpressionList(size);
      int c = 0;
      for (int i=0; i<n; i++) {
        if (tag.getName(i).equalsIgnoreCase("param")) {
          Expression expression = Grammar.parseExpression(tag.getValue(i), location, parser);
          parameters.setChild(c++, expression);
        }
      }
    }

    String from = tag.getValue("from");
    String method = tag.getValue("method");
    boolean is_super = tag.contains("super");

    if ((method != null) && !Grammar.isValidIdentifier(method)) {
      parser.error(location, "Method '"+method+"' is invalid");
      return;
    }

    if (is_super) {
      if (method == null) {
        // super(params, ...)
        Statement parent = getParentStatement();
        FunctionStatement function = getFunctionStatement();
        if (function.getType() == Type.CONSTRUCTOR) {
          BlockStatement block = function.getBlockStatement();
          if (parent == function && block.isEmpty()) {
            _expression = new Expression(new LinkNode(this, location,
              new Name().add(Name.SUPER, "super"), parameters, LinkNode.SUPER), location);

          } else {
            parser.error(location, "Superclass constructor invoke must appear as a first statement (characters between tags are considered statements)");
          }
        } else {
          parser.error(location, "Superclass constructor invoke may only appear in constructor");
        }
       
      } else {
        // super.method(params, ...)
        _expression = new Expression(new LinkNode(this, location,
            new Name().add(Name.SUPER, "super").add(method), parameters, LinkNode.GET), location);
           
      }
     
    } else {
      if (method == null) {
        parser.error(location, "Attribute 'method' not given");
        return;
      }
     
      if (from == null) {
        // method(params, ...)
        _expression = new Expression(new LinkNode(this, location,
            new Name().add(method), parameters, LinkNode.GET), location);
           
      } else {
        // expr.method(params, ...)
        Expression self = Grammar.parseExpression(from, location, parser);
        _expression = new Expression(new InvokeNode(self, method, parameters), location);

      }
    }
  }
View Full Code Here

  {
    Parameter[] params = _params;
    int n = _size;
    for(int i=0; i<n; i++) {
      Parameter param = params[i];
      Expression expr = param.expression;
      if (expr != null) {
        expr.check(context);
        if (expr.isConstant()) {
          param.value = expr.eval();
        } else {
          context.error(expr.getLocation(), "Default value for parameter '"+param.name+"' is not a constant");
        }
      }
    }
  }
View Full Code Here

  public void check(ErrorListener context)
  {
    if (_index != null) {
      int n = _index.length;
      for(int i=0; i<n; i++) {
        Expression expr = _index[i];
        expr.check(context);
        if (!expr.isAssignable()) {
          context.error(getLocation(), "Index expression #"+(i+1)+" is not assignable");
        }
      }
    }
    if (_key != null) {
      int n = _key.length;
      for(int i=0; i<n; i++) {
        Expression expr = _key[i];
        expr.check(context);
        if (!expr.isAssignable()) {
          context.error(getLocation(), "Key expression #"+(i+1)+" is not assignable");
        }
      }
    }
    if (_value != null) {
      int n = _value.length;
      for(int i=0; i<n; i++) {
        Expression expr = _value[i];
        expr.check(context);
        if (!expr.isAssignable()) {
          context.error(getLocation(), "Value expression  #"+(i+1)+" is not assignable");
        }
      }
    }
    _expression.check(context);
View Full Code Here

          }
         
          NestedParser expressionParser =
            new NestedParser(parser, location, buffer.toString(), startIndex);
           
          Expression expression = expressionParser.parseExpression();
         
          if (expression.isConstant()) {
            sections.add(new ConstantNode(expression.eval().toString()));
          } else {
            Node child = expression.getChild(0);
            if (child != null) {
              sections.add(child);
            }
          }
          buffer.setLength(0);
View Full Code Here

  private Expression buildExpr(Location location, String handler, String method, ExpressionList args)
  {
    if (handler != null) {
      handler = handler.trim();
      return new Expression(new LinkNode(this, location,
        new Name().add(_namespace).add(handler), args,
        LinkNode.GET) ,location);
       
    } else if (method != null) {
      return new Expression(new InvokeNode(FRAME, method, EMPTY_ARGS), location);
     
    } else {
      return null;
    }
  }
View Full Code Here

  private Expression buildExpr(Location location, String handler, String method, ExpressionList args)
  {
    if (handler != null) {
      handler = handler.trim();
      return new Expression(new LinkNode(this, location,
        new Name().add(_namespace).add(handler), args,
        LinkNode.GET) ,location);
       
    } else if (method != null) {
      return new Expression(new InvokeNode(FRAME, method, EMPTY_ARGS), location);
     
    } else {
      return null;
    }
  }
View Full Code Here

      ExpressionParser p = new ExpressionParser(parser, getLocation(), expr);
      ExpressionList list = p.parseExpressionList();
      int n = list.childs();
      _expressions = new Expression[n];
      for(int i=0; i<n; i++) {
        _expressions[i] = new Expression(list.getChild(i), getLocation());
      }
    }

    int n = tag.getLength();
    String name;
View Full Code Here

  public void compile(ByteCompiler context)
  {
    Code code = context.getCode();
    if (_expressions != null) {
      Expression expr;
      int n = _expressions.length;
      if (n>0) {
        for(int i=0; i<n; i++) {
          expr = _expressions[i];
          boolean newline = _newline && i==n-1;

          if (expr.isConstant()) {
            context.text(code, _converters.convert(expr.constant().toString()), newline);
          } else {
            if (expr.needLineNumbers()) {
              context.location(expr.getLocation());     
            }
            code.aload_first();
            if (_conversions == 0) {
              expr.compile(context, Expression.GET);
              code.invokevirtual(code.getPool().addMethodRef(context.TYPE_CONTEXT,
                newline ? "println" : "print" , "(Lanvil/core/Any;)V"));
            } else {
              _converters.compile(context, expr);
              code.invokevirtual(code.getPool().addMethodRef(context.TYPE_CONTEXT,
View Full Code Here

  {
    String s = tag.getValue("value");
    if (s == null) {
      s = tag.getValue("of");
    }
    Expression value = Grammar.parseExpression(s, parser.getLocation(), parser);
    return onCase(parser, value);
  }
View Full Code Here

TOP

Related Classes of anvil.script.expression.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.