run method
Launching machine with a given StubbleContext
Implementation
String run(StubbleContext context) {
_stack.clear();
_stack.add(RootState());
_res = '';
if (_template != null && _template!.isNotEmpty) {
final lines = _template!.split('\n');
for (var l = 0; l < lines.length; l++) {
_line = l + 1;
final line = lines[l];
for (var i = 0; i < line.length; i++) {
//print('Current state is: ${_stack.last}');
_symbol = i;
final charCode = line.codeUnitAt(i);
//print("char: ${line[i]}");
context.symbol = _symbol;
context.line = _line;
_process(ProcessMessage(charCode: charCode), context);
}
if (l < lines.length - 1) {
_process(ProcessMessage(charCode: enter), context);
}
}
_process(ProcessMessage(charCode: eos), context);
if (_stack.last is! RootState) {
throw Exception(
'Something go wrong: please check your template for issues.');
}
}
return _res;
}