hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit c0efdf743c0d8ce2cbbb7fd1a1c8a6e1e43e1416
parent f1ea5921fca6696f8a3b22638a0839eb40540d66
Author: Byron Torres <b@torresjrjr.com>
Date:   Thu, 11 Jan 2024 11:36:42 +0000

fmt: rename type mods to modset

A set of modifiers, a modifier-set, or modset for short.

Breaking-Change: 0.24.0

Diffstat:
Mfmt/+test.ha | 14+++++++-------
Mfmt/README | 18+++++++++---------
Mfmt/iter.ha | 16++++++++--------
Mfmt/print.ha | 10+++++-----
4 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/fmt/+test.ha b/fmt/+test.ha @@ -14,7 +14,7 @@ use strconv; assert(bsprintf(buf, "{0} {0}", "hello", "world") == "hello hello"); assert(bsprintf(buf, "{1} {0} {1}", "hello", "world") == "world hello world"); - const mod = &mods { width = 7, pad = ' ', ... }; + const mod = &modset { width = 7, pad = ' ', ... }; assert(bsprintf(buf, "{%}", "hello", mod) == " hello"); assert(bsprintf(buf, "{%1}", "hello", mod) == " hello"); assert(bsprintf(buf, "{0%1}", "hello", mod) == " hello"); @@ -25,14 +25,14 @@ use strconv; assert(bsprintf(buf, "|{1%}|{}|", mod, "hello") == "| hello|hello|"); assert(bsprintf(buf, "|{}|{2%}|", "hello", mod, "world") == "|hello| world|"); assert(bsprintf(buf, "|{%}|{%}|{%}|{%}|", - "hello", &mods { ... }, - "world", &mods { width = 10, pad = ' ', ... }, - 123, &mods { prec = 10, ... }, - 0xBEEF, &mods { base = strconv::base::HEX, ... }, + "hello", &modset { ... }, + "world", &modset { width = 10, pad = ' ', ... }, + 123, &modset { prec = 10, ... }, + 0xBEEF, &modset { base = strconv::base::HEX, ... }, ) == "|hello| world|0000000123|BEEF|"); assert(bsprintf(buf, "|{%}|{%}|{0%1}|", - "hello", &mods { ... }, - "world", &mods { ... }, + "hello", &modset { ... }, + "world", &modset { ... }, ) == "|hello|world|hello|"); assert(bsprintf(buf, "x: {:8X}", 0xBEEF) == "x: BEEF"); diff --git a/fmt/README b/fmt/README @@ -66,25 +66,25 @@ Some inline modifier examples: fmt::printf("{:.2f}", 42.87934); // "42.88" A parametric format modifier is a secondary argument from the parameter list, -which is a pointer to an instance of [[mods]]. This modifier parameter +which is a pointer to an instance of [[modset]]. This modifier-set parameter describes how the primary formattable argument is formatted. A parametric format sequence of this sort takes the form of "{i%j}", where i is -the formattable parameter index, j is the modifiers parameter index, and i & j -are optional. If either i or j aren't explicitly provided by the user, they +the formattable parameter index, j is the modifier-set parameter index, and i & +j are optional. If either i or j aren't explicitly provided by the user, they will evaluate to the index of the next unused argument. Some parametric modifier examples: // "hello world hello" fmt::printf("{%} {%} {0%1}", // evaluates to "{0%1} {2%3} {0%1}" - "hello", &fmt::mods { ... }, - "world", &fmt::mods { ... }); + "hello", &fmt::modset { ... }, + "world", &fmt::modset { ... }); // "|hello| world|0000000123|BEEF|" fmt::printf("|{%}|{%}|{%}|{%}|", - "hello", &fmt::mods { ... }, - "world", &fmt::mods { pad = ' ', width = 10, ... }, - 123, &fmt::mods { prec = 10, ... }, - 0xBEEF, &fmt::mods { base = strconv::base::HEX, ... }); + "hello", &fmt::modset { ... }, + "world", &fmt::modset { pad = ' ', width = 10, ... }, + 123, &fmt::modset { prec = 10, ... }, + 0xBEEF, &fmt::modset { base = strconv::base::HEX, ... }); diff --git a/fmt/iter.ha b/fmt/iter.ha @@ -6,9 +6,9 @@ use strings; use strconv; use types; -// Tagged union of the [[formattable]] types and [[mods]]. Used for +// Tagged union of the [[formattable]] types and [[modset]]. Used for // functions which accept format strings. -export type field = (...formattable | *mods); +export type field = (...formattable | *modset); // Tagged union of all types which are formattable. export type formattable = (...types::numeric | uintptr | str | rune | bool | @@ -29,8 +29,8 @@ export type alignment = enum { LEFT, }; -// Specifies how to format an argument. -export type mods = struct { +// Modifier-set. Specifies how to format an argument. +export type modset = struct { alignment: alignment, pad: rune, neg: neg, @@ -55,7 +55,7 @@ fn iter(fmt: str, args: []field) iterator = iterator { checkunused = true, }; -fn next(it: *iterator) (str | (formattable, mods) | done) = { +fn next(it: *iterator) (str | (formattable, modset) | done) = { let r = match (strings::next(&it.iter)) { case done => return done; @@ -100,7 +100,7 @@ fn next(it: *iterator) (str | (formattable, mods) | done) = { }; assert(idx < len(it.args), "Not enough parameters given"); let arg = it.args[idx] as formattable; - let mod = mods { ... }; + let mod = modset { ... }; switch (r) { case ':' => @@ -117,7 +117,7 @@ fn next(it: *iterator) (str | (formattable, mods) | done) = { yield it.idx; }; assert(idx < len(it.args), "Not enough parameters given"); - mod = *(it.args[idx] as *mods); + mod = *(it.args[idx] as *modset); assert(r == '}', "Invalid format string (didn't find '}' after modifier index)"); case '}' => void; case => abort("Invalid format string"); @@ -126,7 +126,7 @@ fn next(it: *iterator) (str | (formattable, mods) | done) = { return (arg, mod); }; -fn scan_modifiers(it: *iterator, mod: *mods) void = { +fn scan_modifiers(it: *iterator, mod: *modset) void = { mod.pad = ' '; for (true) switch (getrune(it)) { // alignment diff --git a/fmt/print.ha b/fmt/print.ha @@ -11,7 +11,7 @@ use types; // Formats values for printing using the default format modifiers and writes // them to an [[io::handle]] separated by spaces. export fn fprint(h: io::handle, args: formattable...) (size | io::error) = { - let mod = mods { ... }; + let mod = modset { ... }; let n = 0z; for (let i = 0z; i < len(args); i += 1) { n += format(h, args[i], &mod)?; @@ -33,8 +33,8 @@ export fn fprintf( for (true) match (next(&it)) { case done => break; case let s: str => - n += format(h, s, &mods { ... })?; - case let f: (formattable, mods) => + n += format(h, s, &modset { ... })?; + case let f: (formattable, modset) => n += format(h, f.0, &f.1)?; }; @@ -45,7 +45,7 @@ export fn fprintf( fn format( out: io::handle, arg: formattable, - mod: *mods, + mod: *modset, ) (size | io::error) = { let start = 0z; // guaranteed not to have starting padding in either of these cases @@ -76,7 +76,7 @@ fn format( fn format_raw( out: io::handle, arg: formattable, - mod: *mods, + mod: *modset, ) (size | io::error) = match (arg) { case void => return io::write(out, strings::toutf8("void"));