Kiln » babybearparser
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

tip An example of making the parser more robust with alternation.

Changeset bf5f58b35044

Parent c381bb2b7e39

by Profile picture of User 138Hao Lian <hao@fogcreek.com>

Changes to 2 files · Browse files at bf5f58b35044 Showing diff from parent c381bb2b7e39 Diff from another changeset...

 
45
46
47
48
 
49
50
51
 
45
46
47
 
48
49
50
51
@@ -45,7 +45,7 @@
 let filterName = ["author"; "file"; "project"; "repo"] |> Seq.map pstring |> choice  let regularFilter =   (filterName |>> findFilter) - .>> (pchar ':') + .>>? (pchar ':')   .>>. (phrase <|> word <?> "filter argument")   |>> pipeline  let dateWord = many1Chars <| noneOf ". "
 
90
91
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
 
@@ -90,3 +90,16 @@
  member this.TestsInvalidDate() =   let f () = parse "date:\"many moons ago\"..today eggs" |> ignore   throwsParseError f "Unrecognized date" + + [<TestMethod>] + member this.TestsFilterAlternation() = + equals (parse "projects") [KeywordAtom <| Word "projects"] + + [<TestMethod>] + member this.TestsFilterAlternation2() = + equals (parse "proj") [KeywordAtom <| Word "proj"] + + [<TestMethod>] + member this.TestsEmptyFilter2() = + let f () = parse "project:" |> ignore + throwsParseError f "filter argument" \ No newline at end of file