package wax-lib

  1. Overview
  2. Docs
Libraries for Wax, a Rust-like syntax for WebAssembly

Install

dune-project
 Dependency

Authors

Maintainers

Sources

wax-0.1.0.tbz
sha256=41b580846af8d41bdf6c3f005f62e38feda3e60fe2e9e4aa440db34ce515a153
sha512=4b3a181fcc7d743194a8647260870fb5190770066a197bcc48104c2b77fd40c643228b795c2bcd6b29a120820e969eb42a37a9bcec98b3f608d13f152d9f6579

doc/wax-lib.conversion/Wax_conversion/Namespace/index.html

Module Wax_conversion.NamespaceSource

Sourcetype t

A namespace manages a set of unique names, avoiding collisions with reserved keywords and previously allocated names.

Sourceval reserved_words : string list

The Wax bare-word keywords (the `Regular reserved set). Kept in sync with the lexer by the keyword-consistency test; reused for editor keyword completion so it does not drift.

Sourceval make : ?kind:[ `Regular | `Label | `Type ] -> unit -> t

Create a new namespace. kind determines the set of reserved words (default `Regular):

  • `Regular: Standard reserved keywords (e.g., "if", "loop").
  • `Label: No reserved words (empty).
  • `Type: Reserved keywords plus abstract heap types (e.g., "func", "any").
Sourceval dup : t -> t

dup t returns a copy of the namespace t. Changes to the new namespace will not affect t.

Sourceval add : t -> string -> string

add t name registers name in the namespace t. If name is already taken or reserved, a unique suffix is appended (e.g., "name_1", "name_2"). Returns the unique name that was actually registered.

Sourcetype outcome =
  1. | Available
    (*

    name was free and registered as-is.

    *)
  2. | Renamed of {
    1. reserved : bool;
    2. previous : Wax_utils.Ast.location option;
    }
    (*

    name was taken and a suffix was appended. reserved is true when the requested name is a reserved word, false when it collided with another registered name. previous is the location the colliding name was first claimed from, when one was recorded (always None for a reserved word).

    *)
Sourceval add' : ?loc:Wax_utils.Ast.location -> t -> string -> string * outcome

Like add, but also reports whether the name was renamed and, if so, whether the collision was with a reserved word and where the colliding name was previously claimed. loc records this name's source location, so a later collision with it can point back here.

Sourceval is_reserved : t -> string -> bool

is_reserved t name is true when name is one of the namespace's reserved words (a Wax keyword), independent of any names already added. Used to skip an inferred name (an export or import name) that is a keyword, since the suffixed rename it would force reads worse than a generated default.

Sourceval reserve : t -> string -> unit

reserve t name reserves name in the namespace t. If name is already taken or reserved, nothing happens. If it is free, it is marked as taken. This is useful to prevent subsequent add calls from generating this name.