當前位置: 首頁>>代碼示例>>Java>>正文


Java TokenStream.getFilename方法代碼示例

本文整理匯總了Java中com.mitchellbosecke.pebble.lexer.TokenStream.getFilename方法的典型用法代碼示例。如果您正苦於以下問題:Java TokenStream.getFilename方法的具體用法?Java TokenStream.getFilename怎麽用?Java TokenStream.getFilename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mitchellbosecke.pebble.lexer.TokenStream的用法示例。


在下文中一共展示了TokenStream.getFilename方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例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 '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

示例3: 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

示例4: 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


注:本文中的com.mitchellbosecke.pebble.lexer.TokenStream.getFilename方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。