Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed ArraySegmentPrimitives and merged CharListPrimitives back int…

…o ListPrimitives. The idea behind ArraySegmentPrimitives proved to be flawed.
  • Loading branch information...
commit c95beda51b7400a19d231ecf5c14460e2b71a2a2 1 parent f111576
@panesofglass panesofglass authored
View
211 src/Cashel.Tests/ArraySegmentPrimitivesTest.fs
@@ -1,211 +0,0 @@
-module ArraySegmentPrimitivesTest
-open System
-
-let (!!) str = List.ofSeq str
-let (!!!) str = ArraySegment<_>(str)
-let (!!+) str offset = ArraySegment<_>(str, offset, str.Length - offset)
-let (!+) str = !!+str 1
-
-open NUnit.Framework
-open FsUnit
-
-open Cashel
-open Cashel.ArraySegmentPrimitives
-
-let inline (===>) (actual: (_ * ArraySegment<_>) option) (expected: (_ * ArraySegment<_>) option) =
- if actual.IsNone && expected.IsNone then actual |> should equal expected
- else
- let avalue, asegment = actual |> Option.get
- let evalue, esegment = expected |> Option.get
- evalue = avalue |> should be True
- asegment.Array |> should equal esegment.Array
- asegment.Offset |> should equal esegment.Offset
- asegment.Count |> should equal esegment.Count
-
-let test = "test"B
-let test_me = "test me"B
-let ttttest = "ttttest"B
-
-[<Test>]
-let test_token () =
- let exp = Some('t'B, !+test)
- token !!!test ===> exp
-
-[<Test>]
-let test_token_empty_list () =
- token !!!""B ===> None
-
-[<Test>]
-let test_token_single_token () =
- let t = "t"B
- let exp = Some('t'B, !+t)
- token !!!t ===> exp
-
-[<Test>]
-let test_ignore_with_token () =
- let exp = Some((), !+test)
- forget token !!!test ===> exp
-
-[<Test>]
-let test_listify_with_token () =
- let exp = Some(['t'B], !+test)
- listify token !!!test ===> exp
-
-[<Test>]
-let test_filter_simple_predicate () =
- let exp = Some('t'B, !+test)
- filter token (fun x -> x = 't'B) !!!test ===> exp
-
-[<Test>]
-let test_filter_failure_predicate () =
- filter token (fun x -> x = 'e'B) !!!test ===> None
-
-[<Test>]
-let test_any_success_predicate () =
- any ['q'B..'v'B] !!!test ===> (Some('t'B, !+test))
-
-[<Test>]
-let test_any_failure_predicate () =
- any ['a'B..'e'B] !!!test ===> None
-
-[<Test>]
-let test_matchToken () =
- matchToken 't'B !!!test ===> (Some('t'B, !+test))
-
-[<Test>]
-let test_matchToken_failure () =
- matchToken 'e'B !!!test ===> None
-
-[<Test>]
-let test_matchTokens () =
- matchTokens !!test !!!test_me ===> (Some(!!test, !!+test_me 4))
-
-[<Test>]
-let test_matchTokens_failue () =
- matchTokens !!test !!!"tesp me"B ===> None
-
-[<Test>]
-let test_eof () =
- eof !!!""B ===> (Some((),!!!""B))
-
-[<Test>]
-let test_eof_fails_not_at_end () =
- eof !!!test ===> None
-
-[<Test>]
-let test_repeat () =
- repeat (matchToken 't'B) !!!ttttest ===> (Some(!!"tttt"B, !!+ttttest 4))
-
-[<Test>]
-let test_repeat_one_match() =
- repeat (matchToken 't'B) !!!test ===> (Some(['t'B], !+test))
-
-[<Test>]
-let test_repeat_no_matches () =
- repeat (matchToken 'e'B) !!!ttttest ===> (Some([], !!!ttttest))
-
-[<Test>]
-let test_repeat1 () =
- repeat1 (matchToken 't'B) !!!ttttest ===> (Some(!!"tttt"B, !!+ttttest 4))
-
-[<Test>]
-let test_repeat1_one_match() =
- repeat1 (matchToken 't'B) !!!test ===> (Some(['t'B], !+test))
-
-[<Test>]
-let test_repeat1_no_matches () =
- repeat1 (matchToken 'e'B) !!!ttttest ===> None
-
-[<Test>]
-let test_repeat1While () =
- repeat1While (fun xs -> xs.Length < 4) (matchToken 't'B) !!!ttttest ===> (Some(!!"tttt"B, !!+ttttest 4))
-
-[<Test>]
-let test_repeat1While_one_match() =
- repeat1While (fun xs -> xs.Length < 4) (matchToken 't'B) !!!test ===> (Some(['t'B], !!+test 1))
-
-[<Test>]
-let test_repeat1While_no_matches () =
- repeat1While (fun xs -> xs.Length < 4) (matchToken 'e'B) !!!ttttest ===> None
-
-[<Test>]
-let test_repeat1While_too_many_matches() =
- repeat1While (fun xs -> xs.Length < 3) (matchToken 't'B) !!!ttttest ===> None
-
-[<Test>]
-let test_failure_predicate_parser_success() =
- !~ (matchToken 't'B) !!!test ===> None
-
-[<Test>]
-let test_failure_predicate_parser_fails () =
- !~ (matchToken 'e'B) !!!test ===> (Some((), !!!test))
-
-[<Test>]
-let test_Success_predicate_parser_success() =
- !& (matchToken 't'B) !!!test ===> (Some((), !!!test))
-
-[<Test>]
-let test_success_predicate_parser_fails () =
- !& (matchToken 'e'B) !!!test ===> None
-
-[<Test>]
-let test_option_predicate_one () =
- !? (matchToken 't'B) !!!test ===> (Some(Some('t'B), !+test))
-
-[<Test>]
-let test_option_predicate_zero () =
- !? (matchToken 'e'B) !!!test ===> (Some(None, !!!test))
-
-[<Test>]
-let test_ignore_left () =
- ((matchToken 't'B) .>> (matchToken 'e'B)) !!!test ===> (Some('t'B, !!+test 2))
-
-[<Test>]
-let test_ignore_left_fails () =
- ((matchToken 'e'B) .>> (matchToken 'e'B)) !!!test ===> None
-
-[<Test>]
-let test_ignore_right () =
- ((matchToken 't'B) >>. (matchToken 'e'B)) !!!test ===> (Some('e'B, !!+test 2))
-
-[<Test>]
-let test_ignore_right_fails () =
- ((matchToken 't'B) >>. (matchToken 's'B)) !!!test ===> None
-
-[<Test>]
-let test_parse_return_value () =
- ((matchToken 't'B) >>! !!"hello"B) !!!test ===> (Some(!!"hello"B, !+test))
-
-[<Test>]
-let test_parse_return_value_fails () =
- ((matchToken 'q'B) >>! !!"hello"B) !!!test ===> None
-
-[<Test>]
-let test_until () =
- (until token (matchToken 's'B)) !!!test ===> (Some(!!"te"B, !!+test 3))
-
-[<Test>]
-let test_until_fail_1 () =
- (until token (matchToken 'q'B)) !!!test ===> None
-
-[<Test>]
-let test_until_fail_2 () =
- (until (matchToken 'q'B) (matchToken 's'B)) !!!test ===> None
-
-[<Test>]
-let test_skip () =
- let exp = Some((), !+test)
- skip 't'B !!!test ===> exp
-
-[<Test>]
-let test_skip_fail () =
- skip 'e'B !!!test ===> None
-
-[<Test>]
-let test_skips () =
- let exp = Some((), !!+test 2)
- skips !!"te"B !!!test ===> exp
-
-[<Test>]
-let test_skips_fail () =
- skips !!"ts"B !!!test ===> None
View
1  src/Cashel.Tests/Cashel.Tests.fsproj
@@ -43,7 +43,6 @@
<ItemGroup>
<Compile Include="ParserTest.fs" />
<Compile Include="ListPrimitivesTest.fs" />
- <Compile Include="ArraySegmentPrimitivesTest.fs" />
<Compile Include="PegTest.fs" />
<Compile Include="Peg2Test.fs" />
<None Include="packages.config" />
View
3  src/Cashel.Tests/ListPrimitivesTest.fs
@@ -191,9 +191,6 @@ let test_skips () =
let test_skips_fail () =
skips !!"ts" !!"test" |> should equal None
-
-open Cashel.CharListPrimitives
-
[<Test>]
let test_space () =
let exp = Some (' ', !!" test")
View
46 src/Cashel/ArraySegmentPrimitives.fs
@@ -1,46 +0,0 @@
-namespace Cashel
-
-module ArraySegmentPrimitives =
- open System
- open Cashel
-
- //-------------------------ArraySegment helpers----------------------------------------------
-
- let slice (input:ArraySegment<_>) =
- match input with
- | x when x.Count = 0 -> None
- | x -> Some(x.Array.[x.Offset], ArraySegment<'a>(x.Array, x.Offset + 1, x.Count - 1))
-
- //-------------------------ArraySegment primitives-------------------------------------------
-
- ///token assumes the input is a list and returns a tuple of the head and tail
- let token : Parser<ArraySegment<'a>, 'a> = slice
-
- ///eof checks that we're at the end of the list being parsed
- let eof : Parser<ArraySegment<'a>, unit> = fun input ->
- match input with
- | x when x.Count = 0 -> Some((), x)
- | _ -> None
-
- ///any checks the value at the start of the input is in the list of items l
- let any l = filter token (fun x -> l |> List.exists (fun y -> x = y))
-
- ///item_equal checks the value at the start of the input matches the value v
- let matchToken v = filter token (fun x -> x = v)
-
- ///items_equal recursively uses item_equal to check to see if a list of values l matches the start of the input
- let rec matchTokens l =
- match l with
- | [] -> result []
- | x::xs -> matchToken x >>= (fun i -> matchTokens xs >>= (fun is -> result (i::is)))
-
- ///skip_item calls item_equal but tosses the parse value
- let skip v = matchToken v |> forget
-
- ///skip_items calls items_equal but tosses the parse value
- let skips l = matchTokens l |> forget
-
- ///listify turns the result of parsing function p into a single item list
- let listify p = p >>= (fun x -> result [x])
-
-
View
2  src/Cashel/Cashel.fsproj
@@ -47,8 +47,6 @@
<Compile Include="parser.fs" />
<Compile Include="primitives.fs" />
<Compile Include="ListPrimitives.fs" />
- <Compile Include="CharListPrimitives.fs" />
- <Compile Include="ArraySegmentPrimitives.fs" />
</ItemGroup>
<Import Project="..\..\lib\FSharp\Microsoft.FSharp.Targets" />
</Project>
View
25 src/Cashel/CharListPrimitives.fs
@@ -1,25 +0,0 @@
-namespace Cashel
-
-module CharListPrimitives =
- open Cashel
- open Cashel.ListPrimitives
-
- //-------------------------char list primitives-------------------------------------------
-
- let addLineAndCol cl =
- let rec worker cl line col =
- match cl with
- | '\r'::'\n'::tail -> ('\r', line, col)::('\n', line, (col+1))::(worker tail (line+1) 1)
- | '\n'::tail -> ('\n', line, col)::(worker tail (line+1) 1)
- | '\r'::tail -> ('\r', line, col)::(worker tail (line+1) 1)
- | head::tail -> (head, line, col)::(worker tail line (col+1))
- | [] -> []
- worker cl 1 1
-
- let lowercase = any ['a'..'z']
- let uppercase = any ['A'..'Z']
- let letter = lowercase +++ uppercase
- let digit = any ['0'..'9']
- let digitval = digit >>= (fun d -> result (int d - int '0'))
- let space = filter token (System.Char.IsWhiteSpace)
- let skipSpace = repeat space |> forget
View
19 src/Cashel/ListPrimitives.fs
@@ -35,3 +35,22 @@ module ListPrimitives =
///skips calls matchTokens but tosses the parse value
let skips l = matchTokens l |> forget
+
+ //-------------------------char list primitives-------------------------------------------
+ let addLineAndCol cl =
+ let rec worker cl line col =
+ match cl with
+ | '\r'::'\n'::tail -> ('\r', line, col)::('\n', line, (col+1))::(worker tail (line+1) 1)
+ | '\n'::tail -> ('\n', line, col)::(worker tail (line+1) 1)
+ | '\r'::tail -> ('\r', line, col)::(worker tail (line+1) 1)
+ | head::tail -> (head, line, col)::(worker tail line (col+1))
+ | [] -> []
+ worker cl 1 1
+
+ let lowercase = any ['a'..'z']
+ let uppercase = any ['A'..'Z']
+ let letter = lowercase +++ uppercase
+ let digit = any ['0'..'9']
+ let digitval = digit >>= (fun d -> result (int d - int '0'))
+ let space = filter token (System.Char.IsWhiteSpace)
+ let skipSpace = repeat space |> forget
Please sign in to comment.
Something went wrong with that request. Please try again.