/** * Throw an exception if the expression passed in is a String Literal */ private void notStringLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof StringLiteral) { throw new ParseException( "Found string literal: " + exp + ". Expecting: " + expected, exp); } }
void checkCurrentOutputFormatCanEscape(Token start) throws ParseException { if (!(outputFormat instanceof MarkupOutputFormat)) { throw new ParseException("The current output format can't do escaping: " + outputFormat, template, start); } }
private void checkLoopVariableBuiltInLHO(String loopVarName, Expression lhoExp, Token biName) throws ParseException { int size = iteratorBlockContexts != null ? iteratorBlockContexts.size() : 0; for (int i = size - 1; i >= 0; i--) { ParserIteratorBlockContext ctx = iteratorBlockContexts.get(i); if (loopVarName.equals(ctx.loopVarName) || loopVarName.equals(ctx.loopVar2Name)) { if (ctx.kind == ITERATOR_BLOCK_KIND_USER_DIRECTIVE) { throw new ParseException( "The left hand operand of ?" + biName.image + " can't be the loop variable of an user defined directive: " + loopVarName, lhoExp); } return; // success } } throw new ParseException( "The left hand operand of ?" + biName.image + " must be a loop variable, " + "but there's no loop variable in scope with this name: " + loopVarName, lhoExp); }
/** * Throw an exception if the expression passed in is a boolean Literal */ private void notBooleanLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof BooleanLiteral) { throw new ParseException("Found: " + exp.getCanonicalForm() + ". Expecting " + expected, exp); } }
String fetchKeyword() throws ParseException { String w = fetchWord(); if (w.startsWith("'") || w.startsWith("\"")) { throw new ParseException( "Keyword expected, but a string value found: " + w, 0, 0); } return w; }
/** * Throw an exception if the expression passed in is a Hash Literal */ private void notHashLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof HashLiteral) { throw new ParseException( "Found hash literal: " + exp.getCanonicalForm() + ". Expecting " + expected, exp); } }
/** * Throw an exception if the expression passed in is a List Literal */ private void notListLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof ListLiteral) { throw new ParseException( "Found list literal: " + exp.getCanonicalForm() + ". Expecting " + expected, exp); } }
/** * Throw an exception if the expression passed in is a Number Literal */ private void notNumberLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof NumberLiteral) { throw new ParseException( "Found number literal: " + exp.getCanonicalForm() + ". Expecting " + expected, exp); } }
protected ParseException newArgumentCountException(String ordinalityDesc, Token openParen, Token closeParen) { return new ParseException( "?" + key + "(...) " + ordinalityDesc + " parameters", this.getTemplate(), openParen.beginLine, openParen.beginColumn, closeParen.endLine, closeParen.endColumn); }
final public FallbackInstruction FallBack() throws ParseException {Token tok; tok = jj_consume_token(FALLBACK); if (!inMacro) { {if (true) throw new ParseException("Cannot fall back outside a macro.", template, tok);} } FallbackInstruction result = new FallbackInstruction(); result.setLocation(template, tok, tok); {if ("" != null) return result;} throw new Error("Missing return statement in function"); }
ArrayList parseAsList() throws ParseException { char c; ArrayList seq = new ArrayList(); while (true) { c = skipWS(); if (c == ' ') break; seq.add(fetchStringValue()); c = skipWS(); if (c == ' ') break; if (c != ',') throw new ParseException( "Expected \",\" or the end of text but " + "found \"" + c + "\"", 0, 0); p++; } return seq; }
final public NoEscapeBlock NoEscape() throws ParseException {Token start, end; TemplateElements children; start = jj_consume_token(NOESCAPE); if (escapes.isEmpty()) { {if (true) throw new ParseException("#noescape with no matching #escape encountered.", template, start);} } Object escape = escapes.removeFirst(); children = MixedContentElements(); end = jj_consume_token(END_NOESCAPE); escapes.addFirst(escape); NoEscapeBlock result = new NoEscapeBlock(children); result.setLocation(template, start, end); {if ("" != null) return result;} throw new Error("Missing return statement in function"); }
/** * Production used to skip an iteration in a loop. */ final public ContinueInstruction Continue() throws ParseException {Token start; start = jj_consume_token(CONTINUE); if (continuableDirectiveNesting < 1) { {if (true) throw new ParseException(start.image + " must be nested inside a directive that supports it: " + " #list with \"as\", #items (or the deprecated " + forEachDirectiveSymbol() + ")", template, start);} } ContinueInstruction result = new ContinueInstruction(); result.setLocation(template, start, start); {if ("" != null) return result;} throw new Error("Missing return statement in function"); }
/** * Production used to break out of a loop or a switch block. */ final public BreakInstruction Break() throws ParseException {Token start; start = jj_consume_token(BREAK); if (breakableDirectiveNesting < 1) { {if (true) throw new ParseException(start.image + " must be nested inside a directive that supports it: " + " #list with \"as\", #items, #switch (or the deprecated " + forEachDirectiveSymbol() + ")", template, start);} } BreakInstruction result = new BreakInstruction(); result.setLocation(template, start, start); {if ("" != null) return result;} throw new Error("Missing return statement in function"); }
public ParseException toParseException(Template template) { return new ParseException(getDetail(), template, getLineNumber() != null ? getLineNumber().intValue() : 0, getColumnNumber() != null ? getColumnNumber().intValue() : 0, getEndLineNumber() != null ? getEndLineNumber().intValue() : 0, getEndColumnNumber() != null ? getEndColumnNumber().intValue() : 0); }
final public Expression IdentifierOrStringLiteral() throws ParseException {Expression exp; switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case ID:{ exp = Identifier(); break; } case STRING_LITERAL: case RAW_STRING:{ exp = StringLiteral(false); break; } default: jj_la1[14] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if ("" != null) return exp;} throw new Error("Missing return statement in function"); }
/** * Production to terminate potentially empty elements. Either a ">" or "/>" */ final public Token LooseDirectiveEnd() throws ParseException {Token t; switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case DIRECTIVE_END:{ t = jj_consume_token(DIRECTIVE_END); break; } case EMPTY_DIRECTIVE_END:{ t = jj_consume_token(EMPTY_DIRECTIVE_END); break; } default: jj_la1[86] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if ("" != null) return t;} throw new Error("Missing return statement in function"); }
final public Expression BooleanLiteral() throws ParseException {Token t; Expression result; switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case FALSE:{ t = jj_consume_token(FALSE); result = new BooleanLiteral(false); break; } case TRUE:{ t = jj_consume_token(TRUE); result = new BooleanLiteral(true); break; } default: jj_la1[19] = jj_gen; jj_consume_token(-1); throw new ParseException(); } result.setLocation(template, t, t); {if ("" != null) return result;} throw new Error("Missing return statement in function"); }
final public Expression UnaryPlusMinusExpression() throws ParseException {Expression exp, result; boolean isMinus = false; Token t; switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case PLUS:{ t = jj_consume_token(PLUS); break; } case MINUS:{ t = jj_consume_token(MINUS); isMinus = true; break; } default: jj_la1[5] = jj_gen; jj_consume_token(-1); throw new ParseException(); } exp = PrimaryExpression(); result = new UnaryPlusMinusExpression(exp, isMinus); result.setLocation(template, t, exp); {if ("" != null) return result;} throw new Error("Missing return statement in function"); }
final public StopInstruction Stop() throws ParseException {Token start = null; Expression exp = null; switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case HALT:{ start = jj_consume_token(HALT); break; } case STOP:{ start = jj_consume_token(STOP); exp = Expression(); LooseDirectiveEnd(); break; } default: jj_la1[39] = jj_gen; jj_consume_token(-1); throw new ParseException(); } StopInstruction result = new StopInstruction(exp); result.setLocation(template, start, start); {if ("" != null) return result;} throw new Error("Missing return statement in function"); }