pattern function Null safety

Parser<String> pattern(
  1. String element,
  2. [String? message]
)

Returns a parser that accepts a single character of a given character set provided as a string.

Characters match themselves. A dash - between two characters matches the range of those characters. A caret ^ at the beginning negates the pattern.

For example, the parser pattern('aou') accepts the character 'a', 'o', or 'u', and fails for any other input. The parser pattern('1-3') accepts either '1', '2', or '3'; and fails for any other character. The parser `pattern('^aou') accepts any character, but fails for the characters 'a', 'o', or 'u'.

Implementation

Parser<String> pattern(String element, [String? message]) => CharacterParser(
    _pattern.parse(element).value,
    message ?? '[${toReadableString(element)}] expected');