reportError method
dynamic
reportError(
- dynamic token
Implementation
reportError(token) {
var lines = [];
var tokenDisplay =
(token['type'] != null ? token['type'] + " token: " : "") +
jsonEncode(token['value'] != null ? token['value'] : token);
lines.add(this.lexer.formatError(token, "Syntax error"));
lines.add('Unexpected ' +
tokenDisplay +
'. Instead, I was expecting to see one of the following:\n');
var lastColumnIndex = this.table.length - 2;
var lastColumn = this.table[lastColumnIndex];
var expectantStates = lastColumn!.states.where((state) {
if (state!.rule.symbols.isNotEmpty) {
var nextSymbol =
state.rule.symbols[state.dot - 1 < 0 ? 0 : state.dot - 1];
return nextSymbol != null && !(nextSymbol is String);
} else {
return false;
}
}).toList();
var stateStacks = expectantStates.map((state) {
return this.buildFirstStateStack(state, []);
}).toList();
stateStacks.forEach((stateStack) {
var state = stateStack[0];
var nextSymbol =
state.rule.symbols[state.dot - 1 < 0 ? 0 : state.dot - 1];
var symbolDisplay = this.getSymbolDisplay(nextSymbol);
lines.add('A ' + symbolDisplay + ' based on:');
this.displayStateStack(stateStack, lines);
});
lines.add("");
return lines.join("\n");
}