boolean assertEqual(String value1, String value2) { if (!value1.equals(value2)) return throwException(new ParseException("Start statement and ending block names do not match")); else return true; }
boolean assertEqual(String value1, String value2) { if (!value1.equals(value2)) return throwException(new ParseException("Start statement and ending block names do not match")); else return true; }
public static ValueList create(Constant init, Constant end) { ValueList valueList = new ValueList(); if (init.isInstanceOf(Integer.class)) { if (!end.isInstanceOf(Integer.class)) throw new ParseBypassException(new ParseException("Expected an integer for the end of the comprehension list")); int initValue = Integer.class.cast(init.getValue()); //(int) init.as(Integer.class); int endValue = Integer.class.cast(end.getValue()); //(int) end.as(Integer.class); if (initValue < endValue) { for (int i = initValue; i <= endValue; i++) valueList.add(new Constant<Integer>(i)); } else { for (int i = endValue; i >= initValue; i--) valueList.add(new Constant<Integer>(i)); } } else if (init.isInstanceOf(Character.class)) { if (!end.isInstanceOf(Character.class)) throw new ParseBypassException(new ParseException("Expected a character for the end of the comprehension list")); char initValue = Character.class.cast(init.getValue()); //(char) init.as(Character.class); char endValue = Character.class.cast(end.getValue()); //(char) end.as(Character.class); if (initValue < endValue) { for (char i = initValue; i <= endValue; i++) valueList.add(new Constant<Character>(i)); } else { for (char i = endValue; i >= initValue; i--) valueList.add(new Constant<Character>(i)); } } else throw new ParseBypassException(new ParseException("Only integers and characters are allowed in comprehension lists")); return valueList; }
public static ValueList create(Constant init, Constant end) { ValueList valueList = new ValueList(); if (init.isInstanceOf(Integer.class)) { if (!end.isInstanceOf(Integer.class)) throw new ParseBypassException(new ParseException("Expected an integer for the end of the comprehension list")); int initValue = Integer.class.cast(init.getValue()); //(int) init.as(Integer.class); int endValue = Integer.class.cast(end.getValue()); //(int) end.as(Integer.class); if (initValue < endValue) { for (int i = initValue; i <= endValue; i++) valueList.add(new Constant<Integer>(i)); } else { for (int i = endValue; i >= initValue; i--) valueList.add(new Constant<Integer>(i)); } } else if (init.isInstanceOf(Character.class)) { if (!end.isInstanceOf(Character.class)) throw new ParseBypassException(new ParseException("Expected a character for the end of the comprehension list")); char initValue = Character.class.cast(init.getValue()); //(char) init.as(Character.class); char endValue = Character.class.cast(end.getValue()); //(char) end.as(Character.class); if (initValue < endValue) { for (char i = initValue; i <= endValue; i++) valueList.add(new Constant<Character>(i)); } else { for (char i = endValue; i >= initValue; i--) valueList.add(new Constant<Character>(i)); } } else throw new ParseBypassException(new ParseException("Only integers and characters are allowed in comprehension lists")); return valueList; }
public static JtwigDocument parse (JtwigResource input) throws ParseException { try { ReportingParseRunner<Object> runner = new ReportingParseRunner<Object>(createParser(JtwigParser.class).start()); ParsingResult<Object> result = runner.run(FileUtils.readAllText(input.retrieve(), Charset.defaultCharset())); return (JtwigDocument) result.resultValue; } catch (ParserRuntimeException e) { if (e.getCause() instanceof ParseBypassException) { ParseException innerException = ((ParseBypassException) e.getCause()).getInnerException(); innerException.setExpression(e.getMessage()); throw innerException; } else throw new ParseException(e); } catch (ResourceException e) { throw new ParseException(e); } }
public static JtwigDocument parse (JtwigResource input) throws ParseException { try { ReportingParseRunner<Object> runner = new ReportingParseRunner<Object>(createParser(JtwigParser.class).start()); ParsingResult<Object> result = runner.run(FileUtils.readAllText(input.retrieve(), Charset.defaultCharset())); return (JtwigDocument) result.resultValue; } catch (ParserRuntimeException e) { if (e.getCause() instanceof ParseBypassException) { ParseException innerException = ((ParseBypassException) e.getCause()).getInnerException(); innerException.setExpression(e.getMessage()); throw innerException; } else throw new ParseException(e); } catch (ResourceException e) { throw new ParseException(e); } }
Rule output() { return Sequence( symbol(OPEN_OUTPUT), mandatory( Sequence( expressionParser.expression(), push(new Output(expressionParser.pop())), basicParser.symbol(JtwigSymbol.CLOSE_OUTPUT) ), new ParseException("Wrong output syntax") ) ); }
Rule output() { return Sequence( symbol(OPEN_OUTPUT), mandatory( Sequence( expressionParser.expression(), push(new Output(expressionParser.pop())), basicParser.symbol(JtwigSymbol.CLOSE_OUTPUT) ), new ParseException("Wrong output syntax") ) ); }
Rule unary(Rule innerRule, Operator... operators) { return Sequence( firstOperatorOf(operators), push(new OperationUnary(((Constant<Operator>) pop()).getValue())), mandatory( Sequence( innerRule, ((OperationUnary) peek(1)).setOperand(simplify(pop())) ), new ParseException("Wrong unary operator syntax") ) ); }
Rule unary(Rule innerRule, Operator... operators) { return Sequence( firstOperatorOf(operators), push(new OperationUnary(((Constant<Operator>) pop()).getValue())), mandatory( Sequence( innerRule, ((OperationUnary) peek(1)).setOperand(simplify(pop())) ), new ParseException("Wrong unary operator syntax") ) ); }
Rule set() { return Sequence( openCode(), keyword(SET), mandatory( Sequence( expressionParser.variable(), push(new SetVariable((Variable) expressionParser.pop())), symbol(ATTR), expressionParser.expression(), ((SetVariable) peek(1)).setAssignment(expressionParser.pop()), closeCode() ), new ParseException("Wrong set syntax") ) ); }
Rule set() { return Sequence( openCode(), keyword(SET), mandatory( Sequence( expressionParser.variable(), push(new SetVariable((Variable) expressionParser.pop())), symbol(ATTR), expressionParser.expression(), ((SetVariable) peek(1)).setAssignment(expressionParser.pop()), closeCode() ), new ParseException("Wrong set syntax") ) ); }
Rule functionWithBrackets() { return Sequence( variable(), symbol(OPEN_PARENT), push(new FunctionElement(popVariableName())), mandatory( Sequence( expression(), ((FunctionElement) peek(1)).add(pop()), ZeroOrMore( symbol(COMMA), expression(), ((FunctionElement) peek(1)).add(pop()) ), symbol(CLOSE_PARENT) ), new ParseException("Wrong function syntax") ) ); }
closeCode() ), new ParseException("Wrong for each syntax")
closeCode() ), new ParseException("Wrong for each syntax")
Rule functionWithBrackets() { return Sequence( variable(), symbol(OPEN_PARENT), push(new FunctionElement(popVariableName())), mandatory( Sequence( expression(), ((FunctionElement) peek(1)).add(pop()), ZeroOrMore( symbol(COMMA), expression(), ((FunctionElement) peek(1)).add(pop()) ), symbol(CLOSE_PARENT) ), new ParseException("Wrong function syntax") ) ); }
Rule block() { return Sequence( openCode(), keyword(BLOCK), mandatory( Sequence( expressionParser.variable(), push(new Block(((Variable) expressionParser.pop()).getIdentifier())), closeCode(), content(), (((Block) peek(1)).setContent(pop())), openCode(), keyword(ENDBLOCK), Optional( expressionParser.variable(), assertEqual( ((Block)peek()).getName(), ((Variable) expressionParser.pop()).getIdentifier() ) ), closeCode() ), new ParseException("Wrong block syntax") ) ); }
Rule block() { return Sequence( openCode(), keyword(BLOCK), mandatory( Sequence( expressionParser.variable(), push(new Block(((Variable) expressionParser.pop()).getIdentifier())), closeCode(), content(), (((Block) peek(1)).setContent(pop())), openCode(), keyword(ENDBLOCK), Optional( expressionParser.variable(), assertEqual( ((Block)peek()).getName(), ((Variable) expressionParser.pop()).getIdentifier() ) ), closeCode() ), new ParseException("Wrong block syntax") ) ); }
closeCode() ), new ParseException("Wrong if syntax")
closeCode() ), new ParseException("Wrong if syntax")