Last active
September 20, 2016 09:32
-
-
Save TIHan/8816444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FParsec.Binary | |
open System | |
open System.Text | |
open System.Text.RegularExpressions | |
open FParsec | |
[<RequireQualifiedAccess>] | |
module File = | |
let readAllString path = | |
let data = | |
System.IO.File.ReadAllBytes path | |
|> Array.map char | |
String data | |
let (|Match|_|) (m: string) (str: string) = | |
if Regex.IsMatch (str, m) then | |
Some str | |
else | |
None | |
let anyByte : Parser<byte, unit> = anyChar |>> byte | |
let anyBytes n : Parser<byte array, unit> = | |
anyString n |>> (fun x -> Array.map byte <| x.ToCharArray ()) | |
let anyInt16 : Parser<int16, unit> = | |
anyBytes 2 | |
|>> (fun x -> BitConverter.ToInt16 (x, 0)) | |
let anyInt32 : Parser<int, unit> = | |
anyBytes 4 | |
|>> (fun x -> BitConverter.ToInt32 (x, 0)) | |
let skipAnyByte : Parser<unit, _> = | |
fun stream -> | |
stream.Skip (1) | |
Reply (()) | |
let skipAnyBytes (n: int) : Parser<unit, _> = | |
fun stream -> | |
stream.Skip (n) | |
Reply (()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mind if I fork this and make use of it?