Giter Site home page Giter Site logo

starcombinator's Introduction

StarCombinator

Tiny parser combinator library for FStar

How to use

Just open the main module:

open StarCombinator
  • You can chain two parsers a (outputing things of type t) b (outputing things of type y): a <*> b will make a parser of type (a * b)
  • a <*>> b will chain a and b omiting the result of a (a <<*> b exists as well)
  • You can parse either a or b (a and b being parsers of a same type t) with a <|> b, that will make a parser of type t
  • a </> b parse either a or b, but of different types t u, making some parser (either t u)
  • a <?> "some error message" attribute a custom error message for any parser
  • maybe many many1
  • keyword "hey" match "hey" and ensure there is no letter after or before it
  • notFollowedBy lookAhead
  • delayMe p with p: () -> parser t (for some type t) makes a parser behave as a lazy function: then you can write stuff like let myParser () = (number <*>> keyword "+") <<*> maybe (delayMe myParser)
  • suppose p: parser t, then f @<< p (with f: t -> u) is of type parser u: it maps the output of p using f. For instance here is a parser for any number of additions (i.e. 10 + 30 + 2, 6 + 36 or 42):
let myParser (): parser int
	= (fun (leftNumber, right) -> match right with
		| None             -> leftNumber
		| Some rightNumber -> leftNumber + rightNumber
	) @<< (
		     (number <*>> keyword "+")
		<<*> maybe (delayMe myParser)
	)

Examples

The files StarCombinator.Examples.fst and StarCombinator.Examples.While.fst contains examples.

About MyIO

This module is used only for debugging purposes (and for the examples). Using the normal IO module from FStar didn't worked for me (so this MyIO module is basically a copy paste).

starcombinator's People

Contributors

mariari avatar w95psp avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

mariari

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.