@Override public void process(Token token, BuilderState state, TemplateEnvironment environment) { switch (token.getTokenType()) { case TEXT: if (!token.getTokenString().isEmpty()) { state.currentNode().appendChild(new TextModel(token)); } return; case LINE_BREAK: state.currentNode().appendChild(new LineBreakModel()); return; case IDENTIFIER: switch (token.getTokenString()) { case "include": state.pushParserState(INCLUDE_TAG); state.pushNode(new IncludeModel(token)); return; case "if": state.pushParserState(IF_TAG); state.pushNode(new IfModel(token)); return; case "with": state.pushParserState(WITH_TAG); state.pushNode(new WithModel(token)); return; case "for": state.pushParserState(FOR_TAG); state.pushNode(new ForModel(token)); return; default: state.pushParserState(VARIABLE_TAG); state.pushNode(new VariableModel(token)); state.setPendingToken(token); return; } case SLASH: state.pushParserState(CLOSE_TAG_START); return; case STRING_LITERAL: case INTEGER_LITERAL: case DOUBLE_LITERAL: case PARENTHESIS_OPEN: case PLUS: case HYPHEN: state.pushParserState(VARIABLE_TAG); state.pushNode(new VariableModel(token)); state.setPendingToken(token); return; default: state.currentNode().appendChild(new SyntaxErrorModel(token)); } }
@Override public void process(Token token, BuilderState state, TemplateEnvironment environment) { switch (token.getTokenType()) { case PARENTHESIS_OPEN: state.currentNode().appendChild(new ParenthesisModel(token)); state.popParserState(); state.pushParserState(EXPRESSION_OPEN); return; case STRING_LITERAL: state.currentNode().appendChild(new StringLiteralModel(token)); state.popParserState(); state.pushParserState(EXPRESSION_VALUE); return; case INTEGER_LITERAL: state.currentNode().appendChild(new IntegerLiteralModel(token)); state.popParserState(); state.pushParserState(EXPRESSION_VALUE); return; case DOUBLE_LITERAL: state.currentNode().appendChild(new DoubleLiteralModel(token)); state.popParserState(); state.pushParserState(EXPRESSION_VALUE); return; case IDENTIFIER: state.currentNode().appendChild(new IdentifierModel(token)); state.popParserState(); state.pushParserState(EXPRESSION_VALUE); return; default: state.popParserState(); state.popNode(); state.setPendingToken(token); } }
@Override public void process(Token token, BuilderState state, TemplateEnvironment environment) { switch (token.getTokenType()) { case TEXT: case LINE_BREAK: state.popParserState(); state.popNode(); state.setPendingToken(token); return; case IDENTIFIER: if (token.getTokenString().equals("else")) { state.popParserState(); state.pushParserState(IF_TAG_INLINE_CLOSE); state.popNode(); state.pushNode(new ElseModel(token)); state.pushNode(new ExpressionModel()); state.pushParserState(EXPRESSION_OPEN); return; } startSyntaxErrorMode(token, state); return; default: startSyntaxErrorMode(token, state); } }
@Override public void process(Token token, BuilderState state, TemplateEnvironment environment) { switch (token.getTokenType()) { case TEXT: case LINE_BREAK: state.setPendingToken(token); state.popParserState(); return; default: state.currentNode().appendChild(new SyntaxErrorModel(token)); } }
@Override public void process(Token token, BuilderState state, TemplateEnvironment environment) { switch (token.getTokenType()) { case PARENTHESIS_CLOSE: state.currentNode().appendChild(new ParenthesisModel(token)); state.popParserState(); state.pushParserState(EXPRESSION_NEXT); return; case PLUS: case HYPHEN: case SLASH: case MOD: case MULTIPLIER: state.currentNode().appendChild(new OperatorModel(token)); state.popParserState(); state.pushParserState(EXPRESSION_OPERATOR); return; default: state.popParserState(); state.popNode(); state.setPendingToken(token); } }
protected void startExpressionMode(Token token, BuilderState state) { state.setPendingToken(token); state.pushNode(new ExpressionModel()); state.pushParserState(EXPRESSION_OPEN); }
protected void startSyntaxErrorMode(Token token, BuilderState state) { state.setPendingToken(token); state.popParserState(); state.pushParserState(SYNTAX_ERROR_IN_TAG); }
protected void breakTag(Token token, BuilderState state) { state.setPendingToken(token); state.popParserState(); }
@Override public void process(Token token, BuilderState state, TemplateEnvironment environment) { state.setPendingToken(token); state.popNode(); state.popParserState(); }