devshorts / parsecclone Goto Github PK
View Code? Open in Web Editor NEWA tiny subset clone of parserc/fparsec combinators that supports string and binary parsing and is in extensible in what stream source is available.
License: MIT License
A tiny subset clone of parserc/fparsec combinators that supports string and binary parsing and is in extensible in what stream source is available.
License: MIT License
Hi,
I am trying rewrite my hand-made binary parser with ParserClone and can not figure out how can I seek from begin of stream? For example, suppose there is 64 byte-length file and I need to begin to parse offset which locates at end of file (last 4 bytes). Then I need to seek from begin of file by this parsed offset and parse another int32.
Create test file:
let writeTestFile () =
use f = IO.File.OpenWrite("testfile.bin")
use bw = new IO.BinaryWriter(f)
let value = 55
let offset = 32
do bw.BaseStream.Seek(int64 offset, IO.SeekOrigin.Begin) |> ignore
do bw.Write(BitConverter.GetBytes(value))
do bw.BaseStream.Seek(int64 60, IO.SeekOrigin.Begin) |> ignore
do bw.Write(BitConverter.GetBytes(offset))
Parse:
let parseTestFile () =
let parser =
bp.skip 60
>>. bp.int32 // parse offset
// ??? seek from start by readed offset
>>. bp.int32 // parse value
let fs = IO.File.OpenRead("testfile.bin")
let bs = makeBinStream fs
parser bs |> printfn "%A"
How can I do that?
Now that the blit emit code is all in f# we don't need to have a c# library dependency.
We need to remove the project, update the msbuild, the nuspec, and the readme.
If a satisfyUserState parser returns None but also the user state predicate returns false, then the None should be ignored and the state should backtrack. Right now, anything other than a Some will fail and not backtrack which causes instability in other parsers since the stream position has been modified.
The stream position should return the actual stream position, and not the cached start position that was used when the stream container was instantiated.
you know the drill
It'd be nice to see some benchmarks to show the advantage of parsecclone over alternatives
BenchmarkDotNet is really easy to use and generates preformatted charts that you can paste straight into the readme.
If a satisfyUserState parser returns None
but also the user state predicate returns false
, then the None
should be ignored and the state should backtrack. Right now, anything other than a Some
will fail and not backtrack which causes instability in other parsers since the stream position has been modified.
System.ArgumentOutOfRangeException : Index and length must refer to a location within the string.
Parameter name: length
at System.String.Substring (System.Int32 startIndex, System.Int32 length) [0x0006a] in <a07d6bf484a54da2861691df910339b1>:0
at FooStringUnitTests.testFloat () [0x00047] in <5968faeedd987869a7450383eefa6859>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <a07d6bf484a54da2861691df910339b1>:0
https://travis-ci.org/devshorts/ParsecClone/builds/253690729
@jinahong can you take a look and see if this is related? This will prevent cutting a new release
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.