Package org.mvel2

Examples of org.mvel2.CompileException


        try {
          return lastNode = new LiteralNode(typeDescriptor.getClassReference(pCtx), pCtx);
        }
        catch (ClassNotFoundException e) {
          throw new CompileException("could not resolve class: " + typeDescriptor.getClassName(), expr, st);
        }
      }
    }

    lastWasIdentifier = true;
View Full Code Here


            splitAccumulator.add(new ProtoVarNode(expr, st, cursor - st, fields | ASTNode.ASSIGN, (Proto)
                stk.pop(), pCtx));
          }
        }
        else {
          throw new CompileException("unknown class or illegal statement: " + lastNode.getLiteralValue(), expr, cursor);
        }
      }
      else {
        throw new CompileException("unknown class or illegal statement: " + lastNode.getLiteralValue(), expr, cursor);
      }

      skipWhitespace();
      if (cursor < end && expr[cursor] == ',') {
        st = ++cursor;
View Full Code Here

        int st = cursor;

        captureToNextTokenJunction();

        if (cursor == end) {
          throw new CompileException("unexpected end of statement", expr, st);
        }

        /**
         * Check to see if the name is legal.
         */
        if (isReservedWord(name = createStringTrimmed(expr, st, cursor - st))
            || isNotValidNameorLabel(name))
          throw new CompileException("illegal function name or use of reserved word", expr, cursor);

        if (pCtx == null) pCtx = getParserContext();

        FunctionParser parser = new FunctionParser(name, cursor, end - cursor, expr, fields, pCtx, splitAccumulator);
        Function function = parser.parse();
        cursor = parser.getCursor();

        return lastNode = function;
      }
      case PROTO: {
        if (ProtoParser.isUnresolvedWaiting()) {
          if (pCtx == null) pCtx = getParserContext();
          ProtoParser.checkForPossibleUnresolvedViolations(expr, cursor, pCtx);
        }

        int st = cursor;
        captureToNextTokenJunction();

        if (isReservedWord(name = createStringTrimmed(expr, st, cursor - st))
            || isNotValidNameorLabel(name))
          throw new CompileException("illegal prototype name or use of reserved word", expr, cursor);

        if (expr[cursor = nextNonBlank()] != '{') {
          throw new CompileException("expected '{' but found: " + expr[cursor], expr, cursor);
        }

        cursor = balancedCaptureWithLineAccounting(expr, st = cursor + 1, end, '{', pCtx);

        if (pCtx == null) pCtx = getParserContext();

        ProtoParser parser = new ProtoParser(expr, st, cursor, name, pCtx, fields, splitAccumulator);
        Proto proto = parser.parse();

        if (pCtx == null) pCtx = getParserContext();

        pCtx.addImport(proto);

        proto.setCursorPosition(st, cursor);
        cursor = parser.getCursor();

        ProtoParser.notifyForLateResolution(proto);

        return lastNode = proto;
      }
      case STACKLANG: {
        if (expr[cursor = nextNonBlank()] != '{') {
          throw new CompileException("expected '{' but found: " + expr[cursor], expr, cursor);
        }
        int st;
        cursor = balancedCaptureWithLineAccounting(expr, st = cursor + 1, end, '{', pCtx);
        if (pCtx == null) pCtx = getParserContext();

        Stacklang stacklang = new Stacklang(expr, st, cursor - st, fields, pCtx);
        cursor++;

        return lastNode = stacklang;

      }
      default:
        if (cond) {
          if (expr[cursor] != '(') {
            throw new CompileException("expected '(' but encountered: " + expr[cursor], expr, cursor);
          }

          /**
           * This block is an: IF, FOREACH or WHILE node.
           */

          endCond = cursor = balancedCaptureWithLineAccounting(expr, startCond = cursor, end, '(', pCtx);

          startCond++;
          cursor++;
        }
    }

    skipWhitespace();

    if (cursor >= end) {
      throw new CompileException("unexpected end of statement", expr, end);
    }
    else if (expr[cursor] == '{') {
      blockEnd = cursor = balancedCaptureWithLineAccounting(expr, blockStart = cursor, end, '{', pCtx);
    }
    else {
      blockStart = cursor - 1;
      captureToEOSorEOL();
      blockEnd = cursor + 1;
    }

    if (type == ASTNode.BLOCK_IF) {
      IfNode ifNode = (IfNode) node;

      if (node != null) {
        if (!cond) {
          return ifNode.setElseBlock(expr, st = trimRight(blockStart + 1), trimLeft(blockEnd) - st, pCtx);
        }
        else {
          return ifNode.setElseIf((IfNode) createBlockToken(startCond, endCond, trimRight(blockStart + 1),
              trimLeft(blockEnd), type));
        }
      }
      else {
        return createBlockToken(startCond, endCond, blockStart + 1, blockEnd, type);
      }
    }
    else if (type == ASTNode.BLOCK_DO) {
      cursor++;
      skipWhitespace();
      st = cursor;
      captureToNextTokenJunction();

      if ("while".equals(name = new String(expr, st, cursor - st))) {
        skipWhitespace();
        startCond = cursor + 1;
        endCond = cursor = balancedCaptureWithLineAccounting(expr, cursor, end, '(', pCtx);
        return createBlockToken(startCond, endCond, trimRight(blockStart + 1), trimLeft(blockEnd), type);
      }
      else if ("until".equals(name)) {
        skipWhitespace();
        startCond = cursor + 1;
        endCond = cursor = balancedCaptureWithLineAccounting(expr, cursor, end, '(', pCtx);
        return createBlockToken(startCond, endCond, trimRight(blockStart + 1), trimLeft(blockEnd),
            ASTNode.BLOCK_DO_UNTIL);
      }
      else {
        throw new CompileException("expected 'while' or 'until' but encountered: " + name, expr, cursor);
      }
    }
    // DON"T REMOVE THIS COMMENT!
    // else if (isFlag(ASTNode.BLOCK_FOREACH) || isFlag(ASTNode.BLOCK_WITH)) {
    else {
View Full Code Here

        case '*':
          if (lookAhead() == '=') return;
          else break;
      }

      throw new CompileException("expected end of statement but encountered: "
          + (cursor == end ? "<end of stream>" : expr[cursor]), expr, cursor);
    }
  }
View Full Code Here

  /**
   * Capture to the end of the current identifier under the cursor.
   */
  protected void captureIdentifier() {
    boolean captured = false;
    if (cursor == end) throw new CompileException("unexpected end of statement: EOF", expr, cursor);
    while (cursor != end) {
      switch (expr[cursor]) {
        case ';':
          return;

        default: {
          if (!isIdentifierPart(expr[cursor])) {
            if (captured) return;
            throw new CompileException("unexpected symbol (was expecting an identifier): " + expr[cursor],
                expr, cursor);
          }
          else {
            captured = true;
          }
View Full Code Here

      switch (expr[cursor]) {
        case '(':
        case '[':
        case '{':
          if ((cursor = balancedCaptureWithLineAccounting(expr, cursor, end, expr[cursor], pCtx)) == -1) {
            throw new CompileException("unbalanced braces", expr, cursor);
          }
          break;

        case '*':
        case '/':
View Full Code Here

   *
   * @return cursor position
   */
  public int nextNonBlank() {
    if ((cursor + 1) >= end) {
      throw new CompileException("unexpected end of statement", expr, st);
    }
    int i = cursor;
    while (i != end && isWhitespace(expr[i])) i++;
    return i;
  }
View Full Code Here

   *
   * @param c character
   */
  public void expectNextChar_IW(char c) {
    nextNonBlank();
    if (cursor == end) throw new CompileException("unexpected end of statement", expr, st);
    if (expr[cursor] != c)
      throw new CompileException("unexpected character ('" + expr[cursor] + "'); was expecting: " + c, expr, st);
  }
View Full Code Here

            }
          }
        }
      }
      else if (!tk.isOperator()) {
        throw new CompileException("unexpected token: " + tk.getName(), expr, st);
      }
      else {
        reduce();
        splitAccumulator.push(tk);
      }
View Full Code Here

        default:
          reduceNumeric(operator);
      }
    }
    catch (ClassCastException e) {
      throw new CompileException("syntax error or incompatable types", expr, st, e);
    }
    catch (ArithmeticException e) {
      throw new CompileException("arithmetic error: " + e.getMessage(), expr, st, e);
    }
    catch (Exception e) {
      throw new CompileException("failed to subEval expression", expr, st, e);
    }
  }
View Full Code Here

TOP

Related Classes of org.mvel2.CompileException

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.