Rule content() { return Sequence( push(new JtwigContent()), ZeroOrMore( FirstOf( addToContent(output()), addToContent(block()), addToContent(include()), addToContent(forEach()), addToContent(ifCondition()), addToContent(set()), addToContent(verbatim()), Sequence( openCode(), throwException(new ParseException("Unknown tag")) ), addToContent(text())
Rule text() { return Sequence( push(new Text()), OneOrMore( FirstOf( Sequence("{#", ZeroOrMore(TestNot("#}"), ANY), "#}"), Sequence( basicParser.escape(), ((Text) peek()).append(match()) ), Sequence( TestNot( FirstOf( basicParser.symbol(OPEN_OUTPUT), basicParser.symbol(OPEN_CODE) ) ), ANY, ((Text) peek()).append(match()) ) ) ).suppressSubnodes() ); }
public Rule start() { return FirstOf( extendTemplate(), normalTemplate() ); }
Rule mandatory(Rule rule, ParseException exception) { return FirstOf( rule, throwException(exception) ); }
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 extendTemplate() { return Sequence( basicParser.spacing(), Sequence( openCode(), keyword(EXTENDS), mandatory( Sequence( basicParser.stringLiteral(), basicParser.spacing(), closeCode(), push(new JtwigExtendsDocument(new Extends(basicParser.pop()))), ZeroOrMore( basicParser.spacing(), block(), ((JtwigExtendsDocument) peek(1)).add((Block) pop()) ), basicParser.spacing(), EOI ), new ParseException("Wrong include syntax") ) ) ); }
Rule keyword(JtwigKeyword keyword) { return Sequence( basicParser.keyword(keyword), basicParser.spacing() ); }
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") ) ); }