package parsite

  1. Overview
  2. Docs
A micro library for simple parsing combinators

Install

dune-project
 Dependency

Authors

Maintainers

Sources

parsite-0.1.2.tbz
sha256=15f763e9d98014be41677913974ade7c1346bc5f8cae927b7fd24984c251879c
sha512=9fabb389cc6f68fa8b106a9939d41651824693192a1feb67cfda034e9bb18dd6c7702a43da10943ff462f762b5178349894291596fc1e1384c9b4e161de1551d

doc/src/parsite/types.ml.html

Source file types.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(* Parsite types, courtesy of faber-1 *)

(* Result type, used as parser output. Essentially either, but left type takes a 
   string. Also in monad shape!*)

type ('a, 'b) p_result = 
  | Win of ('b * 'a)
  | Lose of string

module PResultM = struct
  let return (x : 'b * 'a) : ('a, 'b) p_result = 
    Win x

  let (>>=) (m : ('a, 'b) p_result) (f : ('b * 'a) -> ('a, 'c) p_result ) : ('a, 'c) p_result =
    match m with 
    | Win e -> f e
    | Lose _ as l-> l

  let fail (x: string) : ('a, 'b) p_result = 
    Lose x

  let (=<<) (m: ('a, 'b) p_result) (f: string -> ('a, 'b) p_result) : ('a, 'b) p_result = 
    match m with 
    | Win _ as w -> w 
    | Lose l -> f l
  
end

type ('a, 'b) p_func = 'a -> ('a, 'b) p_result