def number.class

gralha-text-scan@0.1.0.1 · scan.bend:138

import gralha-text-scan@0.1.0.1/scan.bend as Scan
import Base

138# A number is read straight into a float: digits accumulate the mantissa
139# (fraction digits also scale a divisor), an exponent accumulates its own
140# digits, and a sign is taken where it may appear. Nothing is copied into a
141# scratch string. Each character is classified one step ahead, so the loop
142# branches on parameters: class 0 digit, 1 dot, 2 exponent mark, 3 sign,
143# 4 anything else; stage 0 start, 1 mantissa, 2 fraction, 3 after the
144# mark, 4 exponent digits. An exponent mark that no digit follows is not
145# part of the number (as in "1em"), so `mark` keeps what was read from the
146# mark on (the mark and any signs, reversed) to give back in that case.
147def number.class(+c: U32) -> U32:
148  choose(U32, digit(c), 0, choose(U32, U32.is_eq(c, 46), 1,
149    choose(U32, U32.is_eq(c, 101) || U32.is_eq(c, 69), 2,
150      choose(U32, U32.is_eq(c, 43) || U32.is_eq(c, 45), 3, 4))))

Uses (5)

Used by (1)