Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Snapshot · Oct 24, 2026 · Frozen documentation

NumberParser

Proves invariant text parsing into one exact numeric representation. Built-in integer/IEEE types bind their existing exact source parser. Custom types may provide the same static member. Parsing returns owned values and retains no text backing; syntax/range policies are explicit in ParseError. This concept grants no lifecycle permission, allocation or runtime witness.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

Module std.text

import std.text;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

NumberParser

pub concept NumberParser<Self>

Proves invariant text parsing into one exact numeric representation. Built-in integer/IEEE types bind their existing exact source parser. Custom types may provide the same static member. Parsing returns owned values and retains no text backing; syntax/range policies are explicit in ParseError. This concept grants no lifecycle permission, allocation or runtime witness. Self: Exact destination type, preserving its width and rounding policy.

Example

module example.number_parser;
from std.text import NumberParser, ParseError;
from std.prelude import Result;
fn ParseInvariant<T>(Text: str) -> Result<T, ParseError> where T: NumberParser, Defaultable {
    return T.ParseNumber(Text, default(T));
}
fn Main() -> i32 {
    switch ParseInvariant<i32>("42") {
        case .Ok { Value = Value } => { if Value != 42 { return 1; } }
        case .Err { Error = _ } => return 2;
    }
    switch ParseInvariant<i32>("42x") {
        case .Ok { Value = _ } => return 3;
        case .Err { Error = Error } => { if Error != ParseError.InvalidSyntax { return 4; } }
    }
    switch ParseInvariant<i8>("128") {
        case .Ok { Value = _ } => return 5;
        case .Err { Error = Error } => { if Error != ParseError.OutOfRange { return 6; } }
    }
    return 0;
}
Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library