many1 function
Creates a State that generates code that will accumulate the results of
the computation state in a list. If at least one result is available, it
will return a list of those results, otherwise it will reject.
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;
}