Permalink
Browse files

Renamed satisfy to filter to match the common function name.

  • Loading branch information...
1 parent f0ab824 commit 7c44e482f1850c63b4f4bda4cadd0d248f04dab9 @panesofglass panesofglass committed Mar 6, 2011
@@ -6,6 +6,7 @@ open NUnit.Framework
open FsUnit
open Cashel
+open Cashel.ListPrimitives
[<Test>]
let test_token () =
@@ -32,17 +33,14 @@ let test_listify_with_token () =
listify token !!"test" |> should equal exp
[<Test>]
-let test_satisy_simple_predicate () =
+let test_filter_simple_predicate () =
let exp = Some('t', !!"est")
- satisfy token (fun x -> x = 't') !!"test" |> should equal exp
+ filter token (fun x -> x = 't') !!"test" |> should equal exp
[<Test>]
-let test_satisy_failure_predicate () =
- satisfy token (fun x -> x = 'e') !!"test" |> should equal None
+let test_filter_failure_predicate () =
+ filter token (fun x -> x = 'e') !!"test" |> should equal None
-
-open Cashel.ListPrimitives
-
[<Test>]
let test_any_success_predicate () =
any ['q'..'v'] !!"test" |> should equal (Some('t', !!"est"))
@@ -1,6 +1,8 @@
namespace Cashel
+
module CharListPrimitives =
open Cashel
+ open Cashel.ListPrimitives
//-------------------------char list primitives-------------------------------------------
@@ -19,5 +21,5 @@ module CharListPrimitives =
let letter = lowercase +++ uppercase
let digit = any ['0'..'9']
let digitval = digit >>= (fun d -> result (int d - int '0'))
- let space = satisfy token (System.Char.IsWhiteSpace)
+ let space = filter token (System.Char.IsWhiteSpace)
let skipSpace = repeat space |> forget
@@ -1,6 +1,5 @@
namespace Cashel
-[<AutoOpen>]
module ListPrimitives =
open Cashel
@@ -20,10 +19,10 @@ module ListPrimitives =
| _ -> None
///any checks the value at the start of the input is in the list of tokens l
- let any l = satisfy token (fun x -> l |> List.exists (fun y -> x = y))
+ let any l = filter token (fun x -> l |> List.exists (fun y -> x = y))
///matchToken checks the value at the start of the input matches the value v
- let matchToken v = satisfy token (fun x -> x = v)
+ let matchToken v = filter token (fun x -> x = v)
///matchTokens recursively uses matchToken to check to see if a list of values l matches the start of the input
let rec matchTokens l =
View
@@ -6,7 +6,7 @@ module Primitives =
//-------------------------Basic primitives----------------------------------------------------
//These primitives make no assumption as to the basic types of the parser input or result types
-
+
///Custom bind operator >>! binds parser p to result v, ignoring the return value of p
let (>>!) p v = p >>= (fun _ -> result v)
@@ -21,10 +21,10 @@ module Primitives =
///listify turns the result of parsing function p into a single item list
let listify p = p >>= (fun x -> result [x])
-
- ///satisfy checks the value returned from item against the predicate function p
- let satisfy parser pred = parser >>= (fun x -> if pred x then result x else zero)
+ ///filter checks the value returned from item against the predicate function f
+ let filter p f = p >>= (fun x -> if f x then result x else zero)
+
///repeat looks for zero or more instances of the parsing function p
let rec repeat p = (repeat1 p) +++ (result [])

0 comments on commit 7c44e48

Please sign in to comment.