toString method

  1. @override
String toString({
  1. bool elemAreChar = false,
  2. Vocabulary? vocabulary,
})
override

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Implementation

@override
String toString({bool elemAreChar = false, Vocabulary? vocabulary}) {
  if (intervals.isEmpty) {
    return '{}';
  }

  final elemStr = intervals.map((Interval I) {
    final buf = StringBuffer();
    final a = I.a;
    final b = I.b;
    if (a == b) {
      if (vocabulary != null) {
        buf.write(elementName(vocabulary, a));
      } else {
        if (a == Token.EOF) {
          buf.write('<EOF>');
        } else if (elemAreChar) {
          buf.write("'");
          buf.writeCharCode(a);
          buf.write("'");
        } else {
          buf.write(a);
        }
      }
    } else {
      if (vocabulary != null) {
        for (var i = a; i <= b; i++) {
          if (i > a) buf.write(', ');
          buf.write(elementName(vocabulary, i));
        }
      } else {
        if (elemAreChar) {
          buf.write("'");
          buf.writeCharCode(a);
          buf.write("'..'");
          buf.writeCharCode(b);
          buf.write("'");
        } else {
          buf.write(a);
          buf.write('..');
          buf.write(b);
        }
      }
    }
    return buf;
  }).join(', ');
  if (length > 1) {
    return '{$elemStr}';
  }
  return elemStr;
}