errors method
Implementation
List<GrammarParserError> errors() {
if (success) {
return <GrammarParserError>[];
}
String escape(int c) {
switch (c) {
case 10:
return r"\n";
case 13:
return r"\r";
case 09:
return r"\t";
case -1:
return "";
}
return new String.fromCharCode(c);
}
String getc(int position) {
if (position < _inputLen) {
return "'${escape(_input[position])}'";
}
return "end of file";
}
var errors = <GrammarParserError>[];
if (_failurePos >= _cursor) {
var set = new Set<GrammarParserError>();
set.addAll(_errors);
for (var error in set) {
if (error.position >= _failurePos) {
errors.add(error);
}
}
var names = Set<String?>();
names.addAll(_expected);
if (names.contains(null)) {
var string = getc(_failurePos);
var message = "Unexpected $string";
var error = new GrammarParserError(
GrammarParserError.UNEXPECTED, _failurePos, _failurePos, message);
errors.add(error);
} else {
var found = getc(_failurePos);
var list = names.toList();
list.sort();
var message = "Expected ${list.join(", ")} but found $found";
var error = new GrammarParserError(
GrammarParserError.EXPECTED, _failurePos, _failurePos, message);
errors.add(error);
}
}
errors.sort((a, b) => a.position.compareTo(b.position));
return errors;
}