hare

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

commit 7eba13421f4303c9d0a4398305e0375588ed2c98
parent a3a879bcc37bca30406782da8bf32ab11182068c
Author: Byron Torres <b@torresjrjr.com>
Date:   Thu, 22 Feb 2024 23:44:04 +0000

time::date: change type parsefail, add byteindex

Breaking-Change: 0.24.0
Signed-off-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mtime/date/date.ha | 4++--
Mtime/date/error.ha | 12+++++-------
Mtime/date/parse.ha | 12++++++------
3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/time/date/date.ha b/time/date/date.ha @@ -261,8 +261,8 @@ export fn from_str( //("%FT%T%z %L", "2009-06-30T18:30:00+0200 Europe/Amsterdam", [amst], // new(amst, 2 * time::HOUR, 2009, 6, 30, 18, 30)!), - ("%Y", "a", [], 'a': parsefail), - ("%X", "2008", [], '2': parsefail), + ("%Y", "a", [], (0z, 'a'): parsefail), + ("%X", "2008", [], (0z, '2'): parsefail), ]; let buf: [64]u8 = [0...]; diff --git a/time/date/error.ha b/time/date/error.ha @@ -24,12 +24,10 @@ export fn strerror(err: error) const str = { )); case invalid => return "Invalid date information"; - case let rn: parsefail => - if (rn == '\0') { - return "Date parsing error"; - }; - def FMTMSG = "Invalid date format for specifier '{}'"; - static let buf: [len(FMTMSG) + 2]u8 = [0...]; - return fmt::bsprintf(buf, FMTMSG, rn); + case let pf: parsefail => + const (bi, rn) = pf; + def FMTMSG = "Date parsing failure for layout rune '{}' at byteindex {}"; + static let buf: [len(FMTMSG) + 3]u8 = [0...]; + return fmt::bsprintf(buf, FMTMSG, rn, bi); }; }; diff --git a/time/date/parse.ha b/time/date/parse.ha @@ -10,9 +10,9 @@ use time::chrono; type failure = !void; -// A parsing error occurred. If appropriate, the offending format specifier is -// stored. A null rune represents all other error cases. -export type parsefail = !rune; +// A parsing error occurred. This shall contain a byteindex of and rune from the +// layout at the position where the parsing failure occured. +export type parsefail = !(size, rune); // Parses a date/time string into a [[virtual]], according to a layout format // string with specifiers as documented under [[format]]. Partial, sequential, @@ -45,12 +45,12 @@ export fn parse(v: *virtual, layout: str, s: str) (void | parsefail) = { if (!escaped) { const sr = match (strings::next(&siter)) { case void => - return '\x00'; + return (liter.dec.offs, lr); case let sr: rune => yield sr; }; if (sr != lr) { - return '\x00'; + return (liter.dec.offs, lr); }; continue; }; @@ -60,7 +60,7 @@ export fn parse(v: *virtual, layout: str, s: str) (void | parsefail) = { match (parse_specifier(v, &siter, lr)) { case void => void; case failure => - return lr; + return (liter.dec.offs, lr); }; };