Package anvil.script.expression

Examples of anvil.script.expression.ConstantNode


      char ch;
      for(int i=0; i<n; i++) {
        ch = image.charAt(i);
        if ((i+2<n) && (ch == '$') && (image.charAt(i+1) == '{')) {
          if (buffer.length()>0) {
            sections.add(new ConstantNode(Conversions.unescape(buffer.toString(), false)));
          }
          buffer.setLength(0);
         
          boolean singleQuote = false;
          boolean doubleQuote = false;
          int nesting = 1;
          int startIndex = i + 2;

          i++;
          while(i+1<n && nesting>0) {
            ch = image.charAt(++i);
            switch(ch) {
            case '{':
              if (!singleQuote || !doubleQuote) {
                nesting++;
              }
              buffer.append(ch);
              break;
            case '}':
              if (!singleQuote || !doubleQuote) {
                nesting--;
              }
              if (nesting>0) {
                buffer.append(ch);
              }
              break;
            case '\\':
              if (i+1<n) {
                char ch2 = image.charAt(++i);
                if (ch2 == '}' || ch2 == '{') {
                  buffer.append(ch2);
                } else {
                  buffer.append(ch);
                  buffer.append(ch2);
                }
              }
              break;
            case '\'':
              if (doubleQuote == false) {
                singleQuote = !singleQuote;
              }
              buffer.append(ch);
              break;
            case '"':
              if (singleQuote == false) {
                doubleQuote = !doubleQuote;
              }
              buffer.append(ch);
              break;
             
            default:
              buffer.append(ch);
            }
          }
         
          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);
         
        } else {
          buffer.append(ch);
        }
      }
     
      if (buffer.length()>0) {
        sections.add(new ConstantNode(Conversions.unescape(buffer.toString(), false)));
      }
     
      n = sections.size();
      ExpressionList list = new ExpressionList(n);
      for(int i=0; i<n; i++) {
        list.setChild(i, (Node)sections.get(i));
      }
      return new StringBufferNode(list);
     
    } else {
      return new ConstantNode(Conversions.unescape(image, false));
    }
   
  }
View Full Code Here


      }
      if (value != null) {
        Node node = ConstantNode.UNDEFINED;
        switch(attr.getType()) {
        case Attribute.TYPE_STRING:
          node = new ConstantNode(Any.create(value));
          break;

        case Attribute.TYPE_DOUBLE:
          try {
            node = new ConstantNode(Any.create(Double.parseDouble(value)));
          } catch (NumberFormatException nfe) {
            parser.error(parser.getLocation(), "Value of attribute '"+name+"' is not a floating point number");
          }
          break;

        case Attribute.TYPE_INT:
          try {
            node = new ConstantNode(Any.create(anvil.util.Conversions.parseNumberUnsafe(value)));
          } catch (NumberFormatException nfe) {
            parser.error(parser.getLocation(), "Value of attribute '"+name+"' is not an integer");
          }
          break;
         
        case Attribute.TYPE_BOOLEAN:
          node = new ConstantNode(Any.create(Any.IS_BOOLEAN, value));
          break;
           
        case Attribute.TYPE_EXPR:
          value = value.trim();
          if (value.length() > 0) {
            ExpressionParser p = new ExpressionParser(parser, parser.getLocation(), value);
            node = p.parseExpression(p.TYPE_VALUE).getChild();
          } else {
            node = ConstantNode.UNDEFINED;
          }
          break;
        }
        nodes.add(new MappingNode(new ConstantNode(name), node));
      }
    }
    if (_tagdef.allowAnyAttributes()) {
      Iterator iter = _tag.getAttributes();
      while(iter.hasNext()) {
        anvil.parser.Attribute attr = (anvil.parser.Attribute)iter.next();
        String name = attr.getName();
        if (!_tagdef.hasAttribute(name)) {
          nodes.add(new MappingNode(
            new ConstantNode(name),
            new ConstantNode(attr.getValue())));
        }
      }
    }

    int n = nodes.size();
    ExpressionList childs = new ExpressionList(n);
    for(int i=0; i<n; i++) {
      childs.setChild(i, (Node)nodes.get(i));
    }

    Location location = getLocation();
   
    _init = buildExpr(location,
      _tagdef.getInitHandler(),
      null,
      new ExpressionList(
        new ParentNode(), new ConstantNode(_name),
        new ArrayNode(childs)));
       
    _start = buildExpr(location,
      _tagdef.getStartHandler(),
      _tagdef.getStartMethod(),
View Full Code Here

  public Expression createStaticInitializer()
  {
    Location location = _expression.getLocation();
    AssignmentNode assignment = new AssignmentNode(location, 2);
    assignment.setChild(0, new StaticVariableNode(this));
    assignment.setChild(1, new ConstantNode(getValue()));
    return new Expression(assignment, location);
  }
View Full Code Here

            break label_21;
          }
          jj_consume_token(COMMA);
            spaces.append(' ');
        }
          list.add(new Expression(new ConstantNode(spaces.toString()), toLocation(t)));
        break;
      default:
        jj_la1[58] = jj_gen;
        ;
      }
View Full Code Here

      case FLOATING_POINT_LITERAL:
      case INF:
      case FALSE:
      case TRUE:
      case PATTERN:
        list = PrintValueList(new Expression(new ConstantNode("<br>\n"), null));
        break;
      default:
        jj_la1[60] = jj_gen;
        ;
      }
View Full Code Here

      }
      if (image == null) {
        push(new UnaryMinusNode(child));
      } else {
        image = "-" + image;
        push(new ConstantNode(image, Conversions.parseNumber(image)));
      }
      break;
    case STAR:
      op = jj_consume_token(STAR);
      UnaryExpression();
View Full Code Here

  Token t;
  Token s = null;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case INTEGER_LITERAL:
      t = jj_consume_token(INTEGER_LITERAL);
     push(new ConstantNode(t.image, Conversions.parseNumber(t.image)));
      break;
    case FLOATING_POINT_LITERAL:
      t = jj_consume_token(FLOATING_POINT_LITERAL);
     push(new ConstantNode(Any.create(Any.IS_DOUBLE, t.image)));
      break;
    case STRING_LITERAL:
      StringBuffer buffer = new StringBuffer();
      label_50:
      while (true) {
        t = jj_consume_token(STRING_LITERAL);
       if (t.image.length()>1) {
         buffer.append(t.image.substring(1, t.image.length() - 1));
       }
       if (s == null) {
         s = t;
       }
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case STRING_LITERAL:
          ;
          break;
        default:
          jj_la1[155] = jj_gen;
          break label_50;
        }
      }
     push(Grammar.parseString(this, toLocation(s), buffer.toString()));
      break;
    case INF:
      t = jj_consume_token(INF);
     push(ConstantNode.INF);
      break;
    case FALSE:
      t = jj_consume_token(FALSE);
     push(ConstantNode.FALSE);
      break;
    case TRUE:
      t = jj_consume_token(TRUE);
     push(ConstantNode.TRUE);
      break;
    case NULL:
      t = jj_consume_token(NULL);
     push(ConstantNode.NULL);
      break;
    case UNDEFINED:
      t = jj_consume_token(UNDEFINED);
     push(ConstantNode.UNDEFINED);
      break;
    case PATTERN:
      t = jj_consume_token(PATTERN);
      int i = t.image.lastIndexOf('/');
      String image;
      String flags;
      if (i>0) {
        image = t.image.substring(1, i);
        flags = t.image.substring(i+1);
      } else {
        image = t.image;
        flags = "";
      }
      Pattern pattern = null;
      try {
        pattern = ObjectPool.createPattern(image, flags);
        push(new ConstantNode(new AnyPattern(pattern)));
      } catch (MalformedPatternException e) {
        error(toLocation(t), "Invalid regular expression: " + e.getMessage());
        push(ConstantNode.UNDEFINED);
      }
      break;
View Full Code Here

  public Expression createStaticInitializer()
  {
    Location location = _expression.getLocation();
    AssignmentNode assignment = new AssignmentNode(location, 2);
    assignment.setChild(0,new ConstantVariableNode(this));
    assignment.setChild(1, new ConstantNode(getValue()));
    return new Expression(assignment, location);
  }
View Full Code Here

TOP

Related Classes of anvil.script.expression.ConstantNode

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.