Fable binding for the Parsimmon parser combinator library
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.paket
.vscode Initial commit Aug 4, 2017
Fable.Parsimmon.Tests
Fable.Parsimmon
public
.gitattributes Initial commit Aug 4, 2017
.gitignore
.travis.yml
Fable.Parsimmon.sln
LICENSE
Nuget.Config
README.md
build.cmd
build.fsx
build.sh
package.json
paket.dependencies
paket.lock
webpack.config.js
yarn.lock

README.md

Fable.Parsimmon Build Status

Fable binding and helpers for the Parsimmon parser combinator library.

Nuget Packages

Fable version Package
2.0 Nuget

Installation

You can install the library from Nuget using Paket:

paket add nuget Fable.Parsimmon --project path/to/YourProject.fsproj 

It includes the javascript dependency (this file) in the Nuget package so there no need to install anything else using npm

Make sure the references are added to your paket files

// paket.dependencies (solution-wide dependencies)
nuget Fable.Parsimmon

// paket.refernces (project-specific dependencies)
Fable.Parsimmon

To understand how to use it, refer to the project Fable.Parsimmon.Tests where most of the combinators are tested, for example:

open Fable.Parsimmon 

QUnit.test "Parsing list of numbers works" <| fun test ->
    let comma = Parsimmon.str ","

    let commaSeperatedNumbers = 
        Parsimmon.digit
        |> Parsimmon.many
        |> Parsimmon.concat
        |> Parsimmon.map int
        |> Parsimmon.seperateBy comma

    let leftBracket = Parsimmon.str "["
    let rightBracket = Parsimmon.str "]"

    commaSeperatedNumbers
    |> Parsimmon.between leftBracket rightBracket
    |> Parsimmon.parse "[5,10,15,20,25]"
    |> function
        | Some [| 5; 10; 15; 20; 25 |] -> test.pass()
        | otherwise -> test.fail()

Recursive parsers as values such as this one are also supported:

QUnit.test "Parsimmon.ofLazy works" <| fun test -> 
    
    let rec lazyValue = Parsimmon.ofLazy <| fun () -> 
        [ Parsimmon.str "X" 
          Parsimmon.str "("
             |> Parsimmon.chain lazyValue
             |> Parsimmon.skip (Parsimmon.str ")") ]
        |> Parsimmon.choose
    

    ["X"; "(X)"; "((X))"] 
    |> List.map (fun token -> Parsimmon.parse token lazyValue)
    |> function 
        | [ Some "X"; Some "X"; Some "X" ] -> test.pass()
        | otherwise -> test.fail()