package yuujinchou

  1. Overview
  2. Docs
Name pattern combinators

Install

Dune Dependency

Authors

Maintainers

Sources

1.0.0.tar.gz
md5=e69e68af927edca52959459668d5c4d5
sha512=60a722bfa9636c21813ab5469168d4df97f2c5a861a3b9a52abd9a96e3ccfd244698c181dbae346982ea00dedeee7d6b0d373e1b4cc8e46d768eebaeba66d1d2

Description

This package implements a pattern language for selecting names. It intends to facilitate the implementation of the "import" statement or any feature that allows users to select a group of names by patterns.

Published: 15 Jan 2022

README

README.mkd

# Yuujinchou: Name Pattern Combinators

_Yuujinchou_ is an OCaml package of name patterns for implementing import statements. Please consult the [generated documentation](https://redprl.org/yuujinchou/yuujinchou/Yuujinchou) for more details.

## How to Use It

```ocaml
open Yuujinchou

module Data =
struct
  type t = int
  let equal n1 n2 = n1 = n2
  let merge ~rev_path x y =
    if equal x y then x
    else failwith @@
      "Inconsistent data assigned to the same path " ^ String.concat "." @@ List.rev rev_path
  let shadow ~rev_path:_ _x y = y
  let compare : t -> t -> int = compare
end

(** An environment is a mapping from paths to data. *)
type env = Data.t Trie.t

(** [remap pattern env] uses the [pattern] to massage
    the environment [env]. *)
let remap pattern env =
  let pp_path = function [] -> "(root)" | path -> String.concat "." path in
  match Action.run Data.merge pattern env with
  | Ok env -> env
  | Error (Action.Binding_not_found path) ->
    failwith ("Expected binding(s) not found within the subtree at " ^ pp_path path ^ ".")

(** [import env pattern imported] imports the environment
    [imported] massaged by [pattern] into [env]. *)
let import env pattern imported =
  Trie.union Data.shadow env @@ remap pattern imported

module DataSet = Set.Make (Data)

(** [select env pattern] returns the set of matched data. *)
let select env pattern =
  DataSet.of_seq @@ Trie.to_seq_values @@ remap pattern env
```

## Installation

You need OCaml 4.08.0 or newer. The package is available on the OPAM repository:
```
opam install yuujinchou
```

You could also check out the source repository and install the latest version in development:
```
git clone https://github.com/RedPRL/yuujinchou.git
opam install ./yuujinchou
```

Dependencies (2)

  1. ocaml >= "4.08.0"
  2. dune >= "2.7"

Dev Dependencies (2)

  1. odoc with-doc
  2. alcotest >= "1.2.1" & with-test

Used by

None

Conflicts

None