LiteralSuffix
Identifies a scoped compile-time numeric token provider.
Module std.compiler
import std.compiler;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
LiteralSuffix
pub attribute LiteralSuffixIdentifies a scoped compile-time numeric token provider.
Suffix stores the spelling after the separating underscore. Real selects lexical real tokens; false selects integer tokens. A provider accepts exact token text through one str parameter and returns a fixed ordinary value. Applications are repeatable for aliases and do not inherit. Visibility and ambiguity follow lexical imports, never process-global registration. No allocation, parser execution or runtime registration occurs merely from constructing this metadata. Provider invocation follows consteval budgets.
Example
module example.numeric_literal_attribute;
from std.compiler import LiteralSuffix;
from std.text import TryParse;
[LiteralSuffix("ticks")]
[LiteralSuffix("tick")]
pub consteval fn ParseTicks(Text: str) -> i64 {
switch TryParse<i64>(Text) {
case .Ok { Value = Count } => return Count;
case .Err { Error = _ } => { panic; }
}
}
consteval fn InspectLiteralMetadata() -> i32 {
// Ordinary values pass Real explicitly; applications above test its default.
let Integer = LiteralSuffix("ms", false);
let Real = LiteralSuffix("ms", true);
let Alias = LiteralSuffix("milliseconds", false);
if Integer.Suffix != Real.Suffix || Integer.Real || !Real.Real { return 1; }
if Alias.Suffix != "milliseconds" || Alias.Real { return 2; }
if ParseTicks("42") != 42 { return 3; }
return 0;
}
fn Main() -> i32 { return InspectLiteralMetadata(); }LiteralSuffix.Suffix
pub Suffix: str;Stores the suffix spelling without its leading underscore.
LiteralSuffix.Real
pub Real: bool;Selects lexical real tokens instead of integer tokens.
LiteralSuffix.init
pub init(Suffix: str, Real: bool = false)Constructs the frozen lexical provider identity. Suffix: Exact suffix spelling; compiler application validates admissibility. Real: True for real tokens, false for integer tokens.