package pacomb

  1. Overview
  2. Docs

Module to build and parse list of words

type ('a, 'b) t

Type of a word list with 'a : the type of characters (typically, char or Uchar.t) 'b : a value associated to each word

val create : unit -> ('a, 'b) t

Create a new empty table

val size : ('a, 'b) t -> int

Returns the number of bindings in the table

val add_ascii : ?map:(char -> char) -> (char, 'b) t -> string -> 'b -> unit

add_ascii tbl s v adds a binding from s to v in tbl, keep all previous bindings.

map is a function transforming character before addition (typically a case transformer). (defaults to identity).

val replace_ascii : ?map:(char -> char) -> (char, 'b) t -> string -> 'b -> unit

replace_ascii tbl s v adds a binding from s to v in tbl, remove all previous bindings

val mem_ascii : ?map:(char -> char) -> (char, 'b) t -> string -> bool

mem_ascii tbl s tells if s if present in tbl. Typically used to reject identifiers that are keywords

val add_utf8 : ?map:(string -> string) -> (string, 'b) t -> string -> 'b -> unit

Same as above for an unicode string, which are splitted in graphemes

val replace_utf8 : ?map:(string -> string) -> (string, 'b) t -> string -> 'b -> unit
val mem_utf8 : ?map:(string -> string) -> (string, 'b) t -> string -> bool
val word : ?name:string -> ?final_test:(Input.buffer -> Input.pos -> bool) -> ?map:(char -> char) -> (char, 'a) t -> 'a Grammar.t

Parses word from a dictionnary returning as action all the assiociated values (it is an ambiguous grammar if there is more than one value).

final_test will be called after parsing. It may be used typically to ensure that the next character is not alphanumeric. Defaults to an always passing test.

map is called on each character before searching in the table, typically a case conversion. Defaults to identity.

val utf8_word : ?name:string -> ?final_test:(Input.buffer -> Input.pos -> bool) -> ?map:(string -> string) -> (string, 'a) t -> 'a Grammar.t
OCaml

Innovation. Community. Security.