platform/packages/combinator/lib/src/error.dart

24 lines
553 B
Dart
Raw Normal View History

2021-03-17 23:04:36 +00:00
import 'package:source_span/source_span.dart';
class SyntaxError implements Exception {
final SyntaxErrorSeverity severity;
2021-03-18 00:00:56 +00:00
final String? message;
final FileSpan? span;
String? _toolString;
2021-03-17 23:04:36 +00:00
SyntaxError(this.severity, this.message, this.span);
2021-03-18 00:00:56 +00:00
String? get toolString {
2021-03-17 23:04:36 +00:00
if (_toolString != null) return _toolString;
var type = severity == SyntaxErrorSeverity.warning ? 'warning' : 'error';
2021-03-18 00:00:56 +00:00
return _toolString = '$type: ${span!.start.toolString}: $message';
2021-03-17 23:04:36 +00:00
}
}
enum SyntaxErrorSeverity {
warning,
error,
info,
hint,
}