block function
Creates State that generates source code that isolate variable names,
creating a scope for the code generated by state
.
Implementation
State block(State state) {
final type = state.type;
if (type.trim() == 'void') {
const template = '''
final {{tmp}} = false;
{{@state}}
if ({{tmp}}) {
{{@accept}}
}
{{@reject}}
''';
const automaton = Automaton(
accept: '{{tmp}} = true;',
template: template,
);
const generator = AutomatonGenerator(automaton);
final start = generator.generate(type, state);
return start;
} else {
const template = '''
var ({{type}})? {{tmp}};
{{@state}}
if ({{tmp}} != null) {
{{@accept}}
}
{{@reject}}
''';
const automaton = Automaton(
accept: '{{tmp}} = ({{0}},);',
result: '{{tmp}}.\$1',
template: template,
);
const generator = AutomatonGenerator(automaton);
final start = generator.generate(type, state, values: {'type': type});
return start;
}
}