diff --git a/CHANGELOG.md b/CHANGELOG.md index c7665eed..8968ab3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ * Improve error output, particularly for errors that cover multiple lines. +* Improve source locations for some parse errors. Rather than pointing to the + next token that wasn't what was expected, they point *after* the previous + token. This should generally provide more context for the syntax error. + ### Command-Line Interface * The new error output uses non-ASCII Unicode characters by default. Add a diff --git a/lib/src/parse/parser.dart b/lib/src/parse/parser.dart index 93bea527..009c6960 100644 --- a/lib/src/parse/parser.dart +++ b/lib/src/parse/parser.dart @@ -10,6 +10,7 @@ import 'package:string_scanner/string_scanner.dart'; import '../exception.dart'; import '../logger.dart'; import '../util/character.dart'; +import '../utils.dart'; /// The abstract base class for all parsers. /// @@ -627,7 +628,7 @@ abstract class Parser { return callback(); } on SourceSpanFormatException catch (error) { var span = error.span as FileSpan; - if (error.message.startsWith("Expected") && span.length == 0) { + if (startsWithIgnoreCase(error.message, "expected") && span.length == 0) { var startPosition = _firstNewlineBefore(span.start.offset); if (startPosition != span.start.offset) { span = span.file.span(startPosition, startPosition);