Parsing recovers spans by pointer subtraction and settles the currency across three variables #37
Labels
No labels
kind
bug
kind
enhancement
kind
refactor
workflow
needs-info
workflow
needs-triage
workflow
ready-for-agent
workflow
ready-for-human
workflow
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rosa/lucre#37
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What to build
Two things inside the parser make it harder to follow than the job requires.
The first is how a span is found.
span_ofsubtracts one string's pointer fromanother's to work out where a token sits in the text the caller handed in. It
only answers correctly when the token is a slice of that exact text, and nothing
in the type system says so — a separate string holding the same characters gives
a wrong answer, or a panic. Carry the offset instead: a small slice type that
holds its own position and keeps it through trimming and splitting, so a span is
correct by construction and
span_ofis not needed.The second is how the currency is settled.
identifyspreads one decisionacross three pieces of state: a two-slot array standing in for the prefix and
suffix, a separate record of whichever side held an ISO code, and a fold over
what is left. Classify each side once as empty, a code, or a symbol, then match
on the pair.
Neither changes what the parser accepts or refuses. The same errors come out,
pointing at the same byte ranges, counted from the untrimmed start as they are
today.
Acceptance criteria
span_ofis goneidentifysettles the currency by matching two classified sides, not by threading three pieces of statemise run cipassesBlocked by
None — can start immediately.
ParseMoneyErrorvariant repeats the text it read #39