many function
Creates State that generates source code that will accumulate the
results of the state
computations in a list. Returns a list of those
results even if the result list is empty.
Implementation
State many(State state) {
const template = '''
final {{list}} = <{{type}}>[];
while (true) {
{{@state}}
}
{{@accept}}
''';
const automaton = Automaton(
accept: '{{list}}.add({{0}});\ncontinue;',
reject: 'break;',
result: '{{list}}',
template: template,
);
final elementType = state.type;
final type = 'List<$elementType>';
const generator = AutomatonGenerator(automaton);
final start = generator.generate(type, state, values: {'type': elementType});
return start;
}