Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zaid-ajaj/fable.parsimmon
Fable binding for the Parsimmon parser combinator library
https://github.com/zaid-ajaj/fable.parsimmon
fable fsharp parser parsimmon
Last synced: 3 months ago
JSON representation
Fable binding for the Parsimmon parser combinator library
- Host: GitHub
- URL: https://github.com/zaid-ajaj/fable.parsimmon
- Owner: Zaid-Ajaj
- License: mit
- Created: 2017-08-04T23:47:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T14:37:44.000Z (about 2 years ago)
- Last Synced: 2024-03-28T02:31:19.222Z (10 months ago)
- Topics: fable, fsharp, parser, parsimmon
- Language: F#
- Homepage:
- Size: 602 KB
- Stars: 21
- Watchers: 3
- Forks: 3
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fable.Parsimmon [![Build Status](https://travis-ci.org/Zaid-Ajaj/Fable.Parsimmon.svg?branch=master)](https://travis-ci.org/Zaid-Ajaj/Fable.Parsimmon)
[Fable](http://fable.io/) binding and helpers for the [Parsimmon](https://github.com/jneen/parsimmon) parser combinator library.
### Nuget Packages
| Fable version | Package |
| ------------- | ------------- |
| 2.0 | [![Nuget](https://img.shields.io/nuget/v/Fable.Parsimmon.svg?maxAge=0&colorB=brightgreen)](https://www.nuget.org/packages/Fable.Parsimmon) |# 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)](https://github.com/Zaid-Ajaj/Fable.Parsimmon/blob/master/Fable.Parsimmon/Parsimmon.js) 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:
```fs
open Fable.ParsimmonQUnit.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 commalet 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](https://github.com/jneen/parsimmon/blob/master/API.md#parsimmonlazyfn) are also supported:
```fs
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()
```