本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}