Added ClosedInterval variant of ParsecType.oneOf()

Allows more natural expression of character range matches, and paired with either allows for matches like "a"..."z", "A"..."Z", "0"..."9"
This commit is contained in:
Mark Onyschuk
2016-01-05 14:32:47 -05:00
committed by David Dufresne
parent dd466162d2
commit 3f5e23ee44

View File

@@ -52,6 +52,19 @@ public extension ParsecType where Stream.Element == Character, Result == Charact
}
/// Return a parser that succeeds if the current character is in the supplied interval of characters. It returns the parsed character.
///
/// let digit = StringParser.oneOf("0"..."9")
///
/// - parameter interval: A `ClosedInterval` of possible characters to match.
/// - returns: A parser that succeeds if the current character is in the supplied interval of characters.
/// - SeeAlso: `GenericParser.satisfy(predicate: Character -> Bool) -> GenericParser`
public static func oneOf(interval: ClosedInterval<Character>) -> GenericParser<Stream, UserState, Result> {
return satisfy(interval.contains)
}
/// Return a parser that succeeds if the current character is _not_ in the supplied list of characters. It returns the parsed character.
///
/// let consonant = StringParser.noneOf("aeiou")