getErrorMessage method

  1. @override
ErrorMessage getErrorMessage(
  1. Object? input,
  2. int? offset
)
override

Implementation

@override
ErrorMessage getErrorMessage(Object? input, int? offset) {
  var argument = '<?>';
  var char = this.char;
  if (offset != null && offset >= 0) {
    if (input is String) {
      if (offset < input.length) {
        char = input.runeAt(offset);
      } else {
        argument = '<EOF>';
      }
    } else if (input is ChunkedParsingSink) {
      if (offset >= input.start && offset < input.end) {
        final index = offset - input.start;
        char = input.data.runeAt(index);
      } else if (input.isClosed && offset >= input.end) {
        argument = '<EOF>';
      }
    }
  }

  if (char != null) {
    final hexValue = char.toRadixString(16);
    final value = ParseError.escape(char);
    argument = '$value (0x$hexValue)';
  }

  return ErrorMessage(0, ErrorUnexpectedCharacter.message, [argument]);
}