Skip to content

Commit

Permalink
Improved the documentation for pattern parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed Jul 5, 2019
1 parent cfb6746 commit 25c8769
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions petitparser/lib/src/core/characters/pattern.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ import 'package:petitparser/src/core/characters/range.dart';
import 'package:petitparser/src/core/parser.dart';
import 'package:petitparser/src/core/predicates/any.dart';

/// Returns a parser that accepts the given character class pattern.
/// 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'.
Parser<String> pattern(String element, [String message]) {
return CharacterParser(pattern_.parse(element).value,
message ?? '[${toReadableString(element)}] expected');
Expand All @@ -34,7 +44,7 @@ final Parser<RangeCharPredicate> range_ =
final Parser<CharacterPredicate> sequence_ = range_.or(single_).plus().map(
(predicates) => optimizedRanges(predicates.cast<RangeCharPredicate>()));

/// Parser that reads a possibly negated sequecne of predicates.
/// Parser that reads a possibly negated sequence of predicates.
final Parser<CharacterPredicate> pattern_ = char('^')
.optional()
.seq(sequence_)
Expand Down

0 comments on commit 25c8769

Please sign in to comment.