many1 function
Creates State that generates source code that will accumulate the
results of the state
computations in a list. If at least one result is
available, computation will return a list of those results, otherwise
computation will fail.
Implementation
State many1(State state) {
const template = '''
final {{list}} = <{{type}}>[];
while (true) {
{{@state}}
}
if ({{list}}).isNotEmpty {
{{@accept}}
}
{{@reject}}
''';
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;
}