replace method

  1. @override
void replace(
  1. Parser source,
  2. 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(Parser source, Parser target) {
  super.replace(source, target);
  if (parser1 == source) parser1 = target as Parser<R1>;
  if (parser2 == source) parser2 = target as Parser<R2>;
  if (parser3 == source) parser3 = target as Parser<R3>;
  if (parser4 == source) parser4 = target as Parser<R4>;
}