OCaml parser combinator that compiles to direct recursive descent
5

Configure Feed

Select the types of activity you want to include in your feed.

2 1 0

Clone this repository

https://git.vm.fail/vm.fail/ppx_combin https://git.vm.fail/did:plc:nvwjxoarrcaoivsbbdqiz7zw
ssh://git@knot.vm.fail:2222/vm.fail/ppx_combin ssh://git@knot.vm.fail:2222/did:plc:nvwjxoarrcaoivsbbdqiz7zw

For self-hosted knots, clone URLs may differ based on your setup.


README.md

ppx_combin#

Stupid PPX library because others are stupidly hacked together. This is a parser combinator syntax that compiles to direct recursive descent.It does first-set analysis and generates tight match/loop code.

usage#

open Combin

let is_digit c = c >= '0' && c <= '9'

let digit = [%parser satisfy is_digit <?> "digit"]

let number = [%parser
  some (satisfy is_digit) >>= fun ds ->
  pure (int_of_string (String.concat "" (List.map (String.make 1) ds)))
]

let expr = [%parser
  chainl1
    (satisfy is_digit >>= fun c -> pure (Char.code c - Char.code '0'))
    (token '+' *> pure ( + ))
]

let () =
  match parse_string expr "1+2+3" with
  | Ok (n, _) -> Printf.printf "result: %d\n" n
  | Error e -> print_endline (format_error e)

install#

opam pin add ppx_combin .