Exemplo n.º 1
0
  private void configure() {
    ArrayList<String> items = new ArrayList<String>();
    ArrayList<String> expr = new ArrayList<String>();

    int start = cStart;
    for (int i = start; i < cEnd; i++) {
      switch (contents[i]) {
        case '(':
        case '[':
        case '{':
        case '"':
        case '\'':
          i = ParseTools.balancedCapture(contents, i, contents[i]);
          break;

        case ':':
          items.add(ParseTools.createStringTrimmed(contents, start, i - start));
          start = i + 1;
          break;
        case ',':
          if (expr.size() != (items.size() - 1)) {
            throw new CompileException(
                "unexpected character ',' in foreach tag", contents, cStart + i);
          }
          expr.add(ParseTools.createStringTrimmed(contents, start, i - start));
          start = i + 1;
          break;
      }
    }

    if (start < cEnd) {
      if (expr.size() != (items.size() - 1)) {
        throw new CompileException("expected character ':' in foreach tag", contents, cEnd);
      }
      expr.add(ParseTools.createStringTrimmed(contents, start, cEnd - start));
    }

    item = new String[items.size()];
    int i = 0;
    for (String s : items) item[i++] = s;

    expression = new String[expr.size()];
    i = 0;
    for (String s : expr) expression[i++] = s;
  }
Exemplo n.º 2
0
  public void updateClassName(char[] name, int start, int offset, int fields) {
    this.expr = name;

    if (offset == 0 || !ParseTools.isIdentifierPart(name[start]) || isDigit(name[start])) return;

    if ((endRange = findFirst('(', start, offset, name)) == -1) {
      if ((endRange = findFirst('[', start, offset, name)) != -1) {
        className = new String(name, start, endRange - start).trim();
        int to;

        LinkedList<char[]> sizes = new LinkedList<char[]>();

        int end = start + offset;
        while (endRange < end) {
          while (endRange < end && isWhitespace(name[endRange])) endRange++;

          if (endRange == end || name[endRange] == '{') break;

          if (name[endRange] != '[') {
            throw new CompileException("unexpected token in constructor", name, endRange);
          }
          to = balancedCapture(name, endRange, start + offset, '[');
          sizes.add(subset(name, ++endRange, to - endRange));
          endRange = to + 1;
        }

        Iterator<char[]> iter = sizes.iterator();
        arraySize = new ArraySize[sizes.size()];

        for (int i = 0; i < arraySize.length; i++) arraySize[i] = new ArraySize(iter.next());

        if ((fields & COMPILE_IMMEDIATE) != 0) {
          compiledArraySize = new ExecutableStatement[arraySize.length];
          for (int i = 0; i < compiledArraySize.length; i++)
            compiledArraySize[i] = (ExecutableStatement) subCompileExpression(arraySize[i].value);
        }

        return;
      }

      className = new String(name, start, offset).trim();
    } else {
      className = new String(name, start, endRange - start).trim();
    }
  }
Exemplo n.º 3
0
  public Function parse() {
    int start = cursor;

    int startCond = 0;
    int endCond = 0;

    int blockStart;
    int blockEnd;

    int end = cursor + length;

    cursor = ParseTools.captureToNextTokenJunction(expr, cursor, end, pCtx);

    if (expr[cursor = ParseTools.nextNonBlank(expr, cursor)] == '(') {
      /**
       * If we discover an opening bracket after the function name, we check to see if this function
       * accepts parameters.
       */
      endCond =
          cursor = balancedCaptureWithLineAccounting(expr, startCond = cursor, end, '(', pCtx);
      startCond++;
      cursor++;

      cursor = ParseTools.skipWhitespace(expr, cursor, pCtx);

      if (cursor >= end) {
        throw new CompileException("incomplete statement", expr, cursor);
      } else if (expr[cursor] == '{') {
        blockEnd =
            cursor = balancedCaptureWithLineAccounting(expr, blockStart = cursor, end, '{', pCtx);
      } else {
        blockStart = cursor - 1;
        cursor = ParseTools.captureToEOS(expr, cursor, end, pCtx);
        blockEnd = cursor;
      }
    } else {
      /** This function has not parameters. */
      if (expr[cursor] == '{') {
        /** This function is bracketed. We capture the entire range in the brackets. */
        blockEnd =
            cursor = balancedCaptureWithLineAccounting(expr, blockStart = cursor, end, '{', pCtx);
      } else {
        /** This is a single statement function declaration. We only capture the statement. */
        blockStart = cursor - 1;
        cursor = ParseTools.captureToEOS(expr, cursor, end, pCtx);
        blockEnd = cursor;
      }
    }

    /** Trim any whitespace from the captured block range. */
    blockStart = ParseTools.trimRight(expr, start, blockStart + 1);
    blockEnd = ParseTools.trimLeft(expr, start, blockEnd);

    cursor++;

    /** Check if the function is manually terminated. */
    if (splitAccumulator != null && ParseTools.isStatementNotManuallyTerminated(expr, cursor)) {
      /** Add an EndOfStatement to the split accumulator in the parser. */
      splitAccumulator.add(new EndOfStatement());
    }

    /** Produce the funciton node. */
    return new Function(
        name,
        expr,
        startCond,
        endCond - startCond,
        blockStart,
        blockEnd - blockStart,
        fields,
        pCtx == null ? pCtx = AbstractParser.getCurrentThreadParserContext() : pCtx);
  }