Skip to content

Instantly share code, notes, and snippets.

@stdray
Created June 20, 2014 20:18
Show Gist options
  • Save stdray/8845b33d2943391453cc to your computer and use it in GitHub Desktop.
Save stdray/8845b33d2943391453cc to your computer and use it in GitHub Desktop.
open FParsec
open System
let inline opt s = optional (skipStringCI s)
let inline w s = skipStringCI s >>. spaces
let inline w1 s = skipStringCI s >>. spaces1
let inline ow1 s = optional (skipStringCI s >>. spaces1)
let str = many1Chars anyChar
let skips strs = Seq.map skipStringCI strs
let skip words = spaces >>. (words |> Seq.map (w1) |> Seq.reduce (>>.))
let strSkip (str : string) = str.Split([|' ' |], StringSplitOptions.RemoveEmptyEntries) |> skip
let anyOf1 = Seq.map w1 >> Seq.reduce (<|>)
let yoba = anyOf1 ["yoba"; "ёба"]
let num1 = pint64 .>> spaces1
let removeNoteLine = yoba >>. w1 "удали" >>. ow1 "строку" >>. num1 .>> w1 "из" .>>. str
let updateNote = yoba >>. strSkip ""
let removeNoteLine2 = yoba >>. pipe5 (w1 "удали") (ow1 "строку") num1 (w1 "из") str (fun _ _ l _ s -> l, s)
let test p str =
match run p str with
| Success(result, _, _) -> printfn "Success: %A" result
| Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg
test removeNoteLine2 "yoba удали строку 234 из лоло" |> printfn "%A"
Console.ReadLine() |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment