Skip to content
This repository was archived by the owner on Dec 5, 2026. It is now read-only.
sashitePublic archive

About

SNN support for the Elixir language.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

snn.ex

Hex.pm Docs CI License

SNN (Style Name Notation) implementation for Elixir.

Overview

This library implements the SNN Specification v1.0.0.

SNN names identify Styles (movement traditions), not Variants. The Sashité ecosystem uses Western, Chinese, Japanese and Siamese, which SIN abbreviates as W, C, J and S. SNN itself reserves no names: any PascalCase name with an optional numeric suffix, such as Chess960, is valid.

Implementation Constraints

Constraint Value Rationale
Max string length 32 Sufficient for realistic style names

These constraints enable bounded memory usage and safe parsing.

Installation

Add sashite_snn to your list of dependencies in mix.exs:

def deps do
  [
    {:sashite_snn, "~> 2.1"}
  ]
end

Usage

Parsing (String → StyleName)

Convert an SNN string into a StyleName struct.

alias Sashite.Snn.StyleName

# Standard parsing (returns {:ok, _} or {:error, _})
{:ok, snn} = Sashite.Snn.parse("Western")
snn.name  # => "Western"

# With numeric suffix
{:ok, snn} = Sashite.Snn.parse("Chess960")
snn.name  # => "Chess960"

# Bang version (raises on error)
snn = Sashite.Snn.parse!("Japanese")

# Invalid input returns error tuple
{:error, :empty_input} = Sashite.Snn.parse("")
{:error, :invalid_format} = Sashite.Snn.parse("western")
{:error, :not_a_string} = Sashite.Snn.parse(nil)

Formatting (StyleName → String)

Convert a StyleName back to an SNN string.

alias Sashite.Snn.StyleName

# From StyleName struct
snn = StyleName.new("Western")
StyleName.to_string(snn)  # => "Western"

# String interpolation (via String.Chars protocol)
"#{snn} style"  # => "Western style"

Validation

# Boolean check
Sashite.Snn.valid?("Western")     # => true
Sashite.Snn.valid?("Chess960")  # => true
Sashite.Snn.valid?("western")     # => false (lowercase start)
Sashite.Snn.valid?("")          # => false (empty)
Sashite.Snn.valid?(nil)         # => false (not a string)

Accessing Data

snn = Sashite.Snn.parse!("Chess960")

# Get the name (struct field)
snn.name  # => "Chess960"

API Reference

Types

# StyleName represents a validated SNN style name.
%Sashite.Snn.StyleName{
  name: String.t()  # The validated SNN string
}

# Create a StyleName from a valid name string.
# Raises ArgumentError if the name is invalid.
Sashite.Snn.StyleName.new(name)

Constants

Sashite.Snn.Constants.max_string_length()  # => 32

Parsing

# Parses an SNN string into a StyleName.
# Returns {:ok, style_name} or {:error, reason}.
@spec Sashite.Snn.parse(String.t()) :: {:ok, StyleName.t()} | {:error, atom()}

# Parses an SNN string into a StyleName.
# Raises ArgumentError if the string is not valid.
@spec Sashite.Snn.parse!(String.t()) :: StyleName.t()

Validation

# Reports whether string is a valid SNN style name.
@spec Sashite.Snn.valid?(term()) :: boolean()

Errors

Parsing errors are returned as atoms:

Atom Cause
:not_a_string Input is not a binary
:empty_input String length is 0
:input_too_long String exceeds 32 characters
:invalid_format Does not match SNN format

Design Principles

  • Bounded values: Maximum string length prevents resource exhaustion
  • Struct-based: StyleName struct enables pattern matching and encapsulation
  • Elixir idioms: {:ok, _} / {:error, _} tuples, parse! bang variant
  • Immutable data: Struct fields are read-only after creation
  • No dependencies: Pure Elixir standard library only

Related Specifications

License

Available as open source under the Apache License 2.0.

About

SNN support for the Elixir language.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages