tryMatch method

  1. @override
bool tryMatch(
  1. InlineParser parser, [
  2. int? startMatchPos
])
override

Tries to match at the parser's current position.

The parser's position can be overriden with startMatchPos. Returns whether or not the pattern successfully matched.

Implementation

@override
bool tryMatch(InlineParser parser, [int? startMatchPos]) {
  if (parser.pos > 0 && parser.charAt(parser.pos - 1) == $backquote) {
    // Not really a match! We can't just sneak past one backtick to try the
    // next character. An example of this situation would be:
    //
    //     before ``` and `` after.
    //             ^--parser.pos
    return false;
  }

  final match = pattern.matchAsPrefix(parser.source, parser.pos);
  if (match == null) {
    return false;
  }
  parser.writeText();
  if (onMatch(parser, match)) parser.consume(match.match.length);
  return true;
}