当前位置: 首页>>代码示例>>Java>>正文


Java TokenStream.next方法代码示例

本文整理汇总了Java中com.mitchellbosecke.pebble.lexer.TokenStream.next方法的典型用法代码示例。如果您正苦于以下问题:Java TokenStream.next方法的具体用法?Java TokenStream.next怎么用?Java TokenStream.next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mitchellbosecke.pebble.lexer.TokenStream的用法示例。


在下文中一共展示了TokenStream.next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {
    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip the 'parallel' token
    stream.next();

    stream.expect(Token.Type.EXECUTE_END);

    BodyNode body = parser.subparse(decideParallelEnd);

    // skip the 'endparallel' token
    stream.next();

    stream.expect(Token.Type.EXECUTE_END);
    return new ParallelNode(lineNumber, body);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:19,代码来源:ParallelTokenParser.java

示例2: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {
    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip over the tag name token
    stream.next();

    // parameter expressions will be added here
    Map<String, Expression<?>> paramExpressionMap = parseParams(stream, parser);
    Expression<?> tagBodyExpression = null;
    if(hasContent) {
        tagBodyExpression = parseBody(stream, parser);
    }
    else {
        stream.expect(Token.Type.EXECUTE_END);
    }

    return new TemplateTagNode(lineNumber, paramExpressionMap, tagBodyExpression);
}
 
开发者ID:JavaEden,项目名称:Orchid,代码行数:21,代码来源:PebbleWrapperTemplateTag.java

示例3: parseBeanAttributeExpression

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
/**
 * A bean attribute expression can either be an expression getting an
 * attribute from a variable in the context, or calling a method from a
 * variable.
 *
 * Ex. foo.bar or foo['bar'] or foo.bar('baz')
 *
 * @param node
 *            The expression parsed so far
 * @return NodeExpression The parsed subscript expression
 * @throws ParserException
 *             Thrown if a parsing error occurs.
 */
private Expression<?> parseBeanAttributeExpression(Expression<?> node) throws ParserException {
    TokenStream stream = parser.getStream();

    if (stream.current().test(Token.Type.PUNCTUATION, ".")) {

        // skip over the '.' token
        stream.next();

        Token token = stream.expect(Token.Type.NAME);

        ArgumentsNode args = null;
        if (stream.current().test(Token.Type.PUNCTUATION, "(")) {
            args = this.parseArguments();
            if (!args.getNamedArgs().isEmpty()) {
                throw new ParserException(null, "Can not use named arguments when calling a bean method", stream
                        .current().getLineNumber(), stream.getFilename());
            }
        }

        node = new GetAttributeExpression(node,
                new LiteralStringExpression(token.getValue(), token.getLineNumber()), args,
                stream.getFilename(), token.getLineNumber());

    } else if (stream.current().test(Token.Type.PUNCTUATION, "[")) {
        // skip over opening '[' bracket
        stream.next();

        node = new GetAttributeExpression(node, parseExpression(), stream.getFilename(), stream.current()
                .getLineNumber());

        // move past the closing ']' bracket
        stream.expect(Token.Type.PUNCTUATION, "]");
    }

    return node;
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:50,代码来源:ExpressionParser.java

示例4: parseArrayDefinitionExpression

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
private Expression<?> parseArrayDefinitionExpression() throws ParserException {
    TokenStream stream = parser.getStream();

    // expect the opening bracket and check for an empty array
    stream.expect(Token.Type.PUNCTUATION, "[");
    if (stream.current().test(Token.Type.PUNCTUATION, "]")) {
        stream.next();
        return new ArrayExpression(stream.current().getLineNumber());
    }

    // there's at least one expression in the array
    List<Expression<?>> elements = new ArrayList<>();
    while (true) {
        Expression<?> expr = parseExpression();
        elements.add(expr);
        if (stream.current().test(Token.Type.PUNCTUATION, "]")) {
            // this seems to be the end of the array
            break;
        }
        // expect the comma separator, until we either find a closing
        // bracket or fail the expect
        stream.expect(Token.Type.PUNCTUATION, ",");
    }

    // expect the closing bracket
    stream.expect(Token.Type.PUNCTUATION, "]");

    return new ArrayExpression(elements, stream.current().getLineNumber());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:30,代码来源:ExpressionParser.java

示例5: parseMapDefinitionExpression

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
private Expression<?> parseMapDefinitionExpression() throws ParserException {
    TokenStream stream = parser.getStream();

    // expect the opening brace and check for an empty map
    stream.expect(Token.Type.PUNCTUATION, "{");
    if (stream.current().test(Token.Type.PUNCTUATION, "}")) {
        stream.next();
        return new MapExpression(stream.current().getLineNumber());
    }

    // there's at least one expression in the map
    Map<Expression<?>, Expression<?>> elements = new HashMap<>();
    while (true) {
        // key : value
        Expression<?> keyExpr = parseExpression();
        stream.expect(Token.Type.PUNCTUATION, ":");
        Expression<?> valueExpr = parseExpression();
        elements.put(keyExpr, valueExpr);
        if (stream.current().test(Token.Type.PUNCTUATION, "}")) {
            // this seems to be the end of the map
            break;
        }
        // expect the comma separator, until we either find a closing brace
        // or fail the expect
        stream.expect(Token.Type.PUNCTUATION, ",");
    }

    // expect the closing brace
    stream.expect(Token.Type.PUNCTUATION, "}");

    return new MapExpression(elements, stream.current().getLineNumber());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:33,代码来源:ExpressionParser.java

示例6: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {

    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip over the 'include' token
    stream.next();

    Expression<?> includeExpression = parser.getExpressionParser().parseExpression();

    Token current = stream.current();
    MapExpression mapExpression = null;

    // We check if there is an optional 'with' parameter on the include tag.
    if (current.getType().equals(Token.Type.NAME) && current.getValue().equals("with")) {

        // Skip over 'with'
        stream.next();

        Expression<?> parsedExpression = parser.getExpressionParser().parseExpression();

        if (parsedExpression instanceof MapExpression) {
            mapExpression = (MapExpression) parsedExpression;
        } else {
            throw new ParserException(null, String.format("Unexpected expression '%1s'.", parsedExpression
                    .getClass().getCanonicalName()), token.getLineNumber(), stream.getFilename());
        }

    }

    stream.expect(Token.Type.EXECUTE_END);

    return new IncludeNode(lineNumber, includeExpression, mapExpression);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:36,代码来源:IncludeTokenParser.java

示例7: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {
    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip the 'extends' token
    stream.next();

    Expression<?> parentTemplateExpression = parser.getExpressionParser().parseExpression();

    stream.expect(Token.Type.EXECUTE_END);
    return new ExtendsNode(lineNumber, parentTemplateExpression);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:14,代码来源:ExtendsTokenParser.java

示例8: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {
    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip the 'filter' token
    stream.next();

    List<Expression<?>> filterInvocationExpressions = new ArrayList<>();

    filterInvocationExpressions.add(parser.getExpressionParser().parseFilterInvocationExpression());

    while(stream.current().test(Type.OPERATOR, "|")){
        // skip the '|' token
        stream.next();
        filterInvocationExpressions.add(parser.getExpressionParser().parseFilterInvocationExpression());
    }

    stream.expect(Token.Type.EXECUTE_END);

    BodyNode body = parser.subparse(endFilter);

    stream.next();
    stream.expect(Token.Type.EXECUTE_END);

    Expression<?> lastExpression = new RenderableNodeExpression(body, stream.current().getLineNumber());

    for(Expression<?> filterInvocationExpression : filterInvocationExpressions){

        FilterExpression filterExpression = new FilterExpression();
        filterExpression.setRight(filterInvocationExpression);
        filterExpression.setLeft(lastExpression);

        lastExpression = filterExpression;
    }

    return new PrintNode(lastExpression, lineNumber);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:39,代码来源:FilterTokenParser.java

示例9: parseBody

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
private Expression<?> parseBody(TokenStream stream, Parser parser) throws ParserException {
    List<Expression<?>> filterInvocationExpressions = new ArrayList<>();

    if(stream.current().test(Token.Type.PUNCTUATION, ":")) {
        stream.next();
        stream.expect(Token.Type.PUNCTUATION, ":");

        filterInvocationExpressions.add(parser.getExpressionParser().parseFilterInvocationExpression());

        while(stream.current().test(Token.Type.OPERATOR, "|")){
            // skip the '|' token
            stream.next();
            filterInvocationExpressions.add(parser.getExpressionParser().parseFilterInvocationExpression());
        }
    }

    stream.expect(Token.Type.EXECUTE_END);

    BodyNode body = parser.subparse(token -> token.test(Token.Type.NAME, "end" + name));

    stream.next();
    stream.expect(Token.Type.EXECUTE_END);

    Expression<?> lastExpression = new RenderableNodeExpression(body, stream.current().getLineNumber());

    for(Expression<?> filterInvocationExpression : filterInvocationExpressions){

        FilterExpression filterExpression = new FilterExpression();
        filterExpression.setRight(filterInvocationExpression);
        filterExpression.setLeft(lastExpression);

        lastExpression = filterExpression;
    }

    return lastExpression;
}
 
开发者ID:JavaEden,项目名称:Orchid,代码行数:37,代码来源:PebbleWrapperTemplateTag.java

示例10: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {
    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip the 'for' token
    stream.next();

    // get the iteration variable
    String iterationVariable = parser.getExpressionParser().parseNewVariableName();

    stream.expect(Token.Type.NAME, "in");

    // get the iterable variable
    Expression<?> iterable = parser.getExpressionParser().parseExpression();

    stream.expect(Token.Type.EXECUTE_END);

    BodyNode body = parser.subparse(this.decideForFork);

    BodyNode elseBody = null;

    if (stream.current().test(Token.Type.NAME, "else")) {
        // skip the 'else' token
        stream.next();
        stream.expect(Token.Type.EXECUTE_END);
        elseBody = parser.subparse(this.decideForEnd);
    }

    if (stream.current().getValue() == null) {
        throw new ParserException(
                null,
                "Unexpected end of template. Pebble was looking for the \"endfor\" tag",
                stream.current().getLineNumber(), stream.getFilename());
    }
    // skip the 'endfor' token
    stream.next();
    stream.expect(Token.Type.EXECUTE_END);

    return new ForNode(lineNumber, iterationVariable, iterable, body, elseBody);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:42,代码来源:ForTokenParser.java

示例11: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {

    TokenStream stream = parser.getStream();

    // skip over the 'macro' token
    stream.next();

    String macroName = stream.expect(Token.Type.NAME).getValue();

    ArgumentsNode args = parser.getExpressionParser().parseArguments(true);

    stream.expect(Token.Type.EXECUTE_END);

    // parse the body
    BodyNode body = parser.subparse(decideMacroEnd);

    // skip the 'endmacro' token
    stream.next();

    stream.expect(Token.Type.EXECUTE_END);

    return new MacroNode(macroName, args, body);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:25,代码来源:MacroTokenParser.java

示例12: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {
    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip the 'if' token
    stream.next();

    List<Pair<Expression<?>, BodyNode>> conditionsWithBodies = new ArrayList<>();

    Expression<?> expression = parser.getExpressionParser().parseExpression();

    stream.expect(Token.Type.EXECUTE_END);

    BodyNode body = parser.subparse(this.decideIfFork);

    conditionsWithBodies.add(new Pair<Expression<?>, BodyNode>(expression, body));

    BodyNode elseBody = null;
    boolean end = false;
    while (!end) {
        if (stream.current().getValue() == null) {
            throw new ParserException(
                    null,
                    "Unexpected end of template. Pebble was looking for the \"endif\" tag",
                    stream.current().getLineNumber(), stream.getFilename());
        }

        switch (stream.current().getValue()) {
        case "else":
            stream.next();
            stream.expect(Token.Type.EXECUTE_END);
            elseBody = parser.subparse(this.decideIfEnd);
            break;

        case "elseif":
            stream.next();
            expression = parser.getExpressionParser().parseExpression();
            stream.expect(Token.Type.EXECUTE_END);
            body = parser.subparse(this.decideIfFork);
            conditionsWithBodies.add(new Pair<Expression<?>, BodyNode>(expression, body));
            break;

        case "endif":
            stream.next();
            end = true;
            break;
        default:
            throw new ParserException(
                    null,
                    "Unexpected end of template. Pebble was looking for the following tags \"else\", \"elseif\", or \"endif\"",
                    stream.current().getLineNumber(), stream.getFilename());
        }
    }

    stream.expect(Token.Type.EXECUTE_END);
    return new IfNode(lineNumber, conditionsWithBodies, elseBody);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:59,代码来源:IfTokenParser.java

示例13: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {
    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip the 'set' token
    stream.next();

    String name = parser.getExpressionParser().parseNewVariableName();

    stream.expect(Token.Type.PUNCTUATION, "=");

    Expression<?> value = parser.getExpressionParser().parseExpression();

    stream.expect(Token.Type.EXECUTE_END);

    return new SetNode(lineNumber, name, value);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:19,代码来源:SetTokenParser.java

示例14: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {

    TokenStream stream = parser.getStream();

    // skip over the 'delay' token
    Token delayName = stream.next();

    // expect a name or string for the new block
    if (!delayName.test(Token.Type.NUMBER)) {

        // we already know an error has occurred but let's just call the
        // typical "expect" method so that we know a proper error
        // message is given to user
        stream.expect(Token.Type.NUMBER);
    }

    int delay = Integer.valueOf(delayName.getValue());

    try {
        // We sleep for the given number of milliseconds:
        Thread.sleep(delay);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }

    // skip over the delay
    stream.next();

    stream.expect(Token.Type.EXECUTE_END);

    return new RenderableNode() {

        @Override
        public void accept(NodeVisitor visitor) {
            visitor.visit(this);
        }

        @Override
        public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context)
                throws PebbleException, IOException {
            // Do nothing.
        }
    };
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:46,代码来源:TestParallelParsing.java

示例15: parse

import com.mitchellbosecke.pebble.lexer.TokenStream; //导入方法依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {

    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip over the 'flush' token
    stream.next();

    stream.expect(Token.Type.EXECUTE_END);

    return new FlushNode(lineNumber);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:14,代码来源:FlushTokenParser.java


注:本文中的com.mitchellbosecke.pebble.lexer.TokenStream.next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。