Parser and unparser (pretty printer) from the same grammar. Somewhat akin to the boomerang package for Haskell, or the Boomerang language.
- Written in F# 4.0
- In F#, you can define the grammar in a functional style with combinators!
- Still pretty rough, especially from C#
- Not many tests yet
- Not yet optimized for performance
- Not yet a complete parsing framework
You'll need Visual Studio 2015 -- earlier versions will not work. Just load SharpBoomerang.sln
and go!
If you are using Mono, you'll need version 4.3.1 or newer. Just load SharpBoomerang.sln
in Xamarin Studio and go!
Documentation can be found in the docs
directory, or online. The HTML docs can be built like this:
[Windows] build.cmd docs
[Mac] build.fsx docs
For those who are impatient, here are some samples that are more fully discussed in the docs.
[hide]
#load @"SharpBoomerang.fsx"
open SharpBoomerang
open SharpBoomerang.Combinators
let bhello =
blit %"Hello" >> // boomerang the literal string, "Hello"
~~(blit %",") %true >> // optionally parse a comma (",") -- "%true" means it will always be printed
!+(bws %' ') >> // parse one or more whitespace characters -- it will print one space
blit %"World!" // boomerang the literal string, "World!"
type Title =
| Mr
| Ms
| Dr
type Name = {
Title : Title option;
First : string;
Last : string;
}
let bspace = !+(bws %' ')
let btitle = ~~~(bdu<Title> .>> ~~(blit %".") %true .>> bspace)
let bname = btitle .>>. bstr .>> bspace .>>. bstr .>>% ((fun (t, f, l) -> { Title = t; First = f; Last = l }), (fun n -> (n.Title, n.First, n.Last)))
See the full document here.
The NUnit tests are under the tests
directory. The tests should be runnable from the Unit Tests pad in Xamarin Studio or the Test Explorer in Visual Studio.
Sometimes it's helpful to build the NuGet package locally. To do this:
[Windows] build.cmd nupkg
[Mac] build.fsx nupkg
If you have not already built a Release build, the build will run as part of this command. Note that you'll need to have previously restored the NuGet packages otherwise it will fail.
All welcome! Feel free to file PRs or Issues. Also consider poking me on Twitter @chknofthescene, as I sometimes miss GitHub notifications.