package earley

  1. Overview
  2. Docs
Parsing library based on Earley Algorithm

Install

Dune Dependency

Authors

Maintainers

Sources

3.0.0.tar.gz
md5=6b666c0392dc5b153f81c27d6ef49b12
sha512=a81d2bcf05088a3aaa5c3c0fb3a38306061a624ddf6d8bbefee1b4a17d7a5961ad1b12c0af9bd8dce86aa14b6f05f1956b3f7b5731f3c552bec7f4550182c398

doc/src/earley.core/keywords.ml.html

Source file keywords.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
29
30
31
32
33
34
35
36
37
38
39
40
module type Spec =
  sig
    val id_charset : Charset.t
    val reserved : string list
  end

module Make(S : Spec) =
  struct
    let reserved : string list ref = ref S.reserved

    let mem : string -> bool = fun s ->
      List.mem s !reserved

    let reserve : string -> unit = fun s ->
      if mem s then invalid_arg "already reserved";
      reserved := s :: !reserved

    let check : string -> unit = fun s ->
      if List.mem s !reserved then Earley.give_up ()

    let special : string -> unit Earley.grammar = fun s ->
      if s = "" then invalid_arg "empty word";
      let fn str pos =
        let str = ref str in
        let pos = ref pos in
        for i = 0 to String.length s - 1 do
          let (c, str', pos') = Input.read !str !pos in
          if c <> s.[i] then Earley.give_up ();
          str := str'; pos := pos'
        done;
        let c = Input.get !str !pos in
        if Charset.mem S.id_charset c then Earley.give_up ();
        ((), !str, !pos)
      in
      Earley.black_box fn (Charset.singleton s.[0]) false s

    let create : string -> unit Earley.grammar = fun s ->
      if mem s then invalid_arg "keyword already defined";
      reserve s; special s
  end
OCaml

Innovation. Community. Security.