package sedlex

  1. Overview
  2. No Docs
An OCaml lexer generator for Unicode

Install

dune-project
 Dependency

Authors

Maintainers

Sources

sedlex-3.8.1.tbz
sha256=b8efae9d2a9a39c2ca2c43a2684f3fb686a8775329f7f9b07c3e3d8a2b7682d6
sha512=ae6ac8282b9e899a510745d64a817d06d908bc61f29530568323eb4145b3db38cf61a82575e2b4c15825f570f2b270ab885c3d27adedbbbe7cdad12510de6d80

doc/sedlex.compiler/Sedlex_compiler/Ir/index.html

Module Sedlex_compiler.IrSource

Intermediate representation for sedlex patterns.

This IR captures the regexp structure including named capture annotations (as bindings) but before tag allocation, fixed-length optimization, or discriminator handling. The compiler processes this IR to produce a compiled DFA with binding extraction information.

The IR does not depend on ppxlib and can be constructed directly in tests.

Sourcetype t =
  1. | Chars of Cset.t
    (*

    Match a single code point in the given set.

    *)
  2. | Seq of t list
    (*

    Sequence (concatenation). Invariant: length >= 2. Use seq smart constructor.

    *)
  3. | Alt of t list
    (*

    Alternation. Invariant: length >= 2. Use alt smart constructor which flattens nested Alts.

    *)
  4. | Star of t
    (*

    Kleene star (zero or more).

    *)
  5. | Plus of t
    (*

    One or more.

    *)
  6. | Rep of t * int * int
    (*

    Rep (r, n, m): between n and m repetitions.

    *)
  7. | Eps
    (*

    Empty string (epsilon).

    *)
  8. | Capture of string * t
    (*

    Named capture: Capture (name, inner) wraps inner with an as binding. The compiler decides tag allocation strategy.

    *)

A pattern with named captures.

Smart constructors

Constructors that enforce structural invariants return result.

  • alt checks name consistency across branches.
  • capture checks for shadowed inner bindings.
  • seq rejects duplicate capture names across elements.
  • star, plus, rep reject inner captures.
Sourceval chars : Cset.t -> t
Sourceval seq : t -> t -> (t, string) result
Sourceval alt : t -> t -> (t, string) result
Sourceval star : t -> (t, string) result
Sourceval plus : t -> (t, string) result
Sourceval rep : t -> int -> int -> (t, string) result
Sourceval eps : t
Sourceval capture : string -> t -> (t, string) result
Sourceval reject_captures : string -> t -> (t, string) result

reject_captures ctx t returns Ok t if t contains no Capture nodes, or Error msg mentioning ctx otherwise.

Analysis

Sourcemodule SSet : Set.S with type elt = string
Sourceval capture_names : t -> SSet.t

capture_names t returns the set of capture names in t.

Sourceval fixed_length : t -> int option

fixed_length t returns Some n if t always matches exactly n code points, or None if the length is variable.

Sourceval check_invariant : t -> unit

Invariant checking

All structural constraints are enforced by the smart constructors. check_invariant asserts these hold. Use for debugging.

Pretty-printing

Sourceval pp : Format.formatter -> t -> unit
Sourceval show : t -> string