From 4f1181c51ee71bd229b7815fed80ac9a564611d2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 18 Sep 2015 15:42:53 -0400 Subject: [PATCH] Add a delay combinator. --- prototype/Doubt/Parse.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/prototype/Doubt/Parse.swift b/prototype/Doubt/Parse.swift index d4a6bb1fa..c7c28a9ff 100644 --- a/prototype/Doubt/Parse.swift +++ b/prototype/Doubt/Parse.swift @@ -40,6 +40,12 @@ public func not(parser: String -> State?)(_ input: String) -> State(thunk: () -> String -> State?) -> String -> State? { + return { thunk()($0) } +} + + public func parseWhile(predicate: Character -> Bool)(_ input: String) -> State? { return input.characters.count > 0 && predicate(input.characters[input.startIndex]) ? parseWhile(predicate)(input.from(1)).map { State(rest: $0.rest, value: input.to(1) + $0.value) } ?? State(rest: input.from(1), value: input.to(1))