Package com.floreysoft.jmte.token

Examples of com.floreysoft.jmte.token.Token


  public Object getValue(Map<String, Object> model, String expression) {
    String[] split = expression.split("\\.");
    List<String> segments = Arrays.asList(split);
    ErrorHandler errorHandler = new NoLogErrorHandler();
    Token token = new InvalidToken();
    Object value = traverse(segments, model, errorHandler, token);
    return value;
  }
View Full Code Here


   */
  public Token pop() {
    if (scopes.isEmpty()) {
      return null;
    } else {
      Token token = scopes.remove(scopes.size() - 1);
      return token;
    }
  }
View Full Code Here

   */
  public Token peek() {
    if (scopes.isEmpty()) {
      return null;
    } else {
      Token token = scopes.get(scopes.size() - 1);
      return token;
    }
  }
View Full Code Here

  /**
   * Gets the first element of the given type from the stack without removing it.
   */
  public <T extends Token> T peek(Class<T> type) {
    for (int i = scopes.size() - 1; i >= 0; i--) {
      Token token = scopes.get(i);
      if (token.getClass().equals(type)) {
        return (T) token;
      }
    }
    return null;
  }
View Full Code Here

    try {

      // in case we do not want to evaluate the body, we just do a quick
      // scan until the matching end
      if (inheritedSkip || !feToken.iterator().hasNext()) {
        Token contentToken;
        while ((contentToken = tokenStream.currentToken()) != null
            && !(contentToken instanceof EndToken)) {
          content(true);
        }
        if (contentToken == null) {
          engine.getErrorHandler().error("missing-end", feToken);
        } else {
          tokenStream.consume();
          context.notifyProcessListener(contentToken, Action.END);
        }
      } else {

        while (feToken.iterator().hasNext()) {

          context.model.put(feToken.getVarName(), feToken.advance());
          addSpecialVariables(feToken, context.model);

          // for each iteration we need to rewind to the beginning
          // of the for loop
          tokenStream.rewind(feToken);
          Token contentToken;
          while ((contentToken = tokenStream.currentToken()) != null
              && !(contentToken instanceof EndToken)) {
            content(false);
          }
          if (contentToken == null) {
View Full Code Here

        localSkip = true;
      } else {
        localSkip = !(Boolean) ifToken.evaluate(context);
      }

      Token contentToken;
      while ((contentToken = tokenStream.currentToken()) != null
          && !(contentToken instanceof EndToken)
          && !(contentToken instanceof ElseToken)) {
        content(localSkip);
      }
View Full Code Here

      context.pop();
    }
  }

  private void content(boolean skip) {
    Token token = tokenStream.currentToken();
    context.notifyProcessListener(token, skip ? Action.SKIP : Action.EVAL);
    if (token instanceof PlainTextToken) {
      tokenStream.consume();
      if (!skip) {
        output.append(token.getText());
      }
    } else if (token instanceof StringToken) {
      tokenStream.consume();
      if (!skip) {
        String expanded = (String) token.evaluate(context);
        output.append(expanded);
      }
    } else if (token instanceof ForEachToken) {
      foreach(skip);
    } else if (token instanceof IfToken) {
      condition(skip);
    } else if (token instanceof ElseToken) {
      tokenStream.consume();
      engine.getErrorHandler().error("else-out-of-scope", token);
    } else if (token instanceof EndToken) {
      tokenStream.consume();
      engine.getErrorHandler().error("unmatched-end", token);
    } else if (token instanceof InvalidToken) {
      tokenStream.consume();
      engine.getErrorHandler().error("invalid-expression", token);
    } else {
      tokenStream.consume();
      // what ever else there may be, we just evaluate it
      String evaluated = (String) token.evaluate(context);
      output.append(evaluated);
    }

  }
View Full Code Here

    Label tryEndLabel = new Label();

    codeGenerateForeachBlockStart(feToken, loopStart, loopEnd, tryEndLabel);

    addUsedVariableIfNotLocal(feToken.getExpression());
    Token contentToken;
    while ((contentToken = tokenStream.currentToken()) != null
        && !(contentToken instanceof EndToken)) {
      content();
    }
    if (contentToken == null) {
View Full Code Here

    codeGenerateIfBlockStart(ifToken, tryEndLabel, elseLabel);

    String variableName = ifToken.getExpression();
    addUsedVariableIfNotLocal(variableName);
    Token contentToken;

    codeGenerateIfBranchStart();
    while ((contentToken = tokenStream.currentToken()) != null
        && !(contentToken instanceof EndToken)
        && !(contentToken instanceof ElseToken)) {
View Full Code Here

    codeGenerateIfBlockEnd(tryEndLabel, finalLabel);
  }

  private void content() {
    Token token = tokenStream.currentToken();
    if (token instanceof PlainTextToken) {
      PlainTextToken plainTextToken = (PlainTextToken) token;
      tokenStream.consume();
      String text = plainTextToken.getText();
      codeGenerateText(text);
View Full Code Here

TOP

Related Classes of com.floreysoft.jmte.token.Token

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.