Sashite.Snn (Sashite.Snn v1.0.0)

View Source

Implementation of the SNN (Style Name Notation) specification.

SNN provides a human-readable naming system for game styles in abstract strategy board games. It uses PascalCase names with optional numeric suffixes.

This module implements strict parsing, validation, and protocol support for SNN tokens.

Summary

Types

t()

A struct representing a valid SNN token.

Functions

Parses a string into an SNN struct.

Parses a string into an SNN struct, raising on error.

Returns the compiled regular expression used for SNN validation.

Checks if a string conforms to the SNN format. It explicitly rejects any input containing line breaks (\r or \n).

Types

t()

@type t() :: %Sashite.Snn{name: String.t()}

A struct representing a valid SNN token.

Functions

parse(s)

@spec parse(String.t()) :: {:ok, t()} | {:error, atom()}

Parses a string into an SNN struct.

Returns {:ok, snn} if valid, or {:error, reason} otherwise.

Examples

iex> Sashite.Snn.parse("Shogi")
{:ok, %Sashite.Snn{name: "Shogi"}}

iex> Sashite.Snn.parse("invalid")
{:error, :invalid_format}

parse!(s)

@spec parse!(String.t()) :: t()

Parses a string into an SNN struct, raising on error.

Examples

iex> Sashite.Snn.parse!("Xiangqi")
%Sashite.Snn{name: "Xiangqi"}

iex> Sashite.Snn.parse!("invalid")
** (ArgumentError) invalid SNN format: "invalid"

regex()

@spec regex() :: Regex.t()

Returns the compiled regular expression used for SNN validation.

valid?(s)

@spec valid?(String.t()) :: boolean()

Checks if a string conforms to the SNN format. It explicitly rejects any input containing line breaks (\r or \n).

Examples

iex> Sashite.Snn.valid?("Chess")
true

iex> Sashite.Snn.valid?("Chess960")
true

iex> Sashite.Snn.valid?("Chess\n")
false

iex> Sashite.Snn.valid?("chess")
false

iex> Sashite.Snn.valid?("")
false