A2UICore.Identifier (A2UICore v0.1.1)

Copy Markdown View Source

UAX #31 identifier validation for catalog entity names, with the upstream pattern ^[\p{XID_Start}_][\p{XID_Continue}]*$, compiled like a schema pattern by A2UICore.Schema.ECMA262: exact on Erlang/OTP 28 and later, an approximation on older PCRE.

Two structural points follow the reference:

  • the empty string is invalid;
  • a leading @ makes a name invalid, unless allow_leading_at: true (payload validation, where a call may name a system function such as @index): then one leading @ is ignored. Catalog declarations never allow it.

Summary

Functions

Raises A2UICore.Error with category :catalog if name is not a valid UAX #31 identifier.

Returns whether codepoint (a one-character string) continues an identifier (XID_Continue, as in valid?/1). Expression and path scanning use it to find token boundaries.

Returns whether name is a valid UAX #31 identifier.

Functions

assert_valid!(name, context \\ "identifier")

(since 0.1.0)
@spec assert_valid!(String.t(), String.t()) :: :ok

Raises A2UICore.Error with category :catalog if name is not a valid UAX #31 identifier.

continue?(char)

(since 0.1.0)
@spec continue?(term()) :: boolean()

Returns whether codepoint (a one-character string) continues an identifier (XID_Continue, as in valid?/1). Expression and path scanning use it to find token boundaries.

iex> A2UICore.Identifier.continue?("a")
true
iex> A2UICore.Identifier.continue?("-")
false

valid?(name, options \\ [])

(since 0.1.0)
@spec valid?(term(), keyword()) :: boolean()

Returns whether name is a valid UAX #31 identifier.

Options: allow_leading_at: true ignores one leading @.

iex> A2UICore.Identifier.valid?("submit_form")
true
iex> A2UICore.Identifier.valid?("@index")
false
iex> A2UICore.Identifier.valid?("@index", allow_leading_at: true)
true