SNN (Style Name Notation) implementation for Elixir.
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.
| Constraint | Value | Rationale |
|---|---|---|
| Max string length | 32 | Sufficient for realistic style names |
These constraints enable bounded memory usage and safe parsing.
Add sashite_snn to your list of dependencies in mix.exs:
def deps do
[
{:sashite_snn, "~> 2.1"}
]
endConvert 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)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"# 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)snn = Sashite.Snn.parse!("Chess960")
# Get the name (struct field)
snn.name # => "Chess960"# 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)Sashite.Snn.Constants.max_string_length() # => 32# 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()# Reports whether string is a valid SNN style name.
@spec Sashite.Snn.valid?(term()) :: boolean()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 |
- Bounded values: Maximum string length prevents resource exhaustion
- Struct-based:
StyleNamestruct 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
- Game Protocol — Conceptual foundation
- SNN Specification — Official specification
- SNN Examples — Usage examples
Available as open source under the Apache License 2.0.