TreeBuilder implements TermTransformation<TreeBuilder.State<T>, TreeBuilder.State<T>, RuntimeException>,
                                ProductionTransformation<Void, TreeBuilder.State<T>, RuntimeException> { private static <T> State<T> repeat( Node.Tree node, int times, Grammar.Term term, T context, State<T> next ) { return new StateRepetition<>( node, times, term, context, next ).get(); } TreeBuilder( Choices choice, Supplier<T> context, Map<String, ProductionReplacement<T>> replacements ); @Override State<T> transformProduction( Void param, Production production ); @Override State<T> transformAlternatives( State<T> current, Alternatives alternatives ); @Override State<T> transformSequence( State<T> current, Sequence sequence ); @Override State<T> transformLiteral( State<T> current, Literal value ); @Override State<T> transformNonTerminal( State<T> current, NonTerminal nonTerminal ); @Override State<T> transformOptional( State<T> current, Optional optional ); @Override State<T> transformRepetition( State<T> current, Repetition repetition ); @Override State<T> transformEpsilon( State<T> current ); @Override State<T> transformCharacters( State<T> current, CharacterSet characters );  }
@Test public void shouldTransformRepetition() throws Exception { random.repeat( 3, onRepetition( 1 ) ); TreeBuilder.State<Void> next = generate( oneOrMore( literal( "hej" ) ) ); Node.Tree expected = tree(); assertEquals( expected, actual ); assertNotNull( next ); next = generate( next ); expected.literal( "hej" ); assertEquals( expected, actual ); assertNotNull( next ); next = generate( next ); expected.literal( "hej" ); assertEquals( expected, actual ); assertNotNull( next ); next = generate( next ); expected.literal( "hej" ); assertEquals( expected, actual ); assertNull( next ); }