replace method

  1. @override
void replace(
  1. covariant Parser source,
  2. covariant Parser target
)
override

Changes the receiver by replacing source with target. Does nothing if source does not exist in Parser.children.

The following example creates a letter parser and then defines a parser called example that accepts one or more letters. Eventually the parser example is modified by replacing the letter parser with a new parser that accepts a digit. The resulting example parser accepts one or more digits.

final letter = letter();
final example = letter.plus();
example.replace(letter, digit());

Override this method and Parser.children in all subclasses that reference other parsers.

Implementation

@override
void replace(covariant Parser source, covariant Parser target) {
  super.replace(source, target);
  if (left == source) {
    left = target;
  }
  if (right == source) {
    right = target;
  }
}