module SentenceParser open Parser let period = pchar '.' "period" let word = pfun (pmany1 pletter) (fun cs -> stringify cs) "word" let upperword = pseq pupper (pmany0 pletter) (fun (x,xs) -> stringify (x::xs)) "upperword" let words0 = pmany0 (pright pws1 word) "words0" let prefix = pseq upperword words0 (fun (w,ws) -> w::ws) "sprefix" let sentence = pleft prefix period "sentence" let grammar = pleft sentence peof "grammar" let parse input : string list option = match grammar (prepare input) with | Success(ws,_) -> Some ws | Failure(_,_) -> None [] let main argv = if argv.Length <> 1 then printfn "Usage: dotnet run " exit 1 match parse argv.[0] with | Some ws -> printfn "Sentence: %A" ws | None -> printfn "Invalid sentence." 0