Scan.number.class: def of gralha-text-scan@0.1.0.1 Import: import gralha-text-scan@0.1.0.1/scan.bend as Scan Lines 138-150 of gralha-text-scan@0.1.0.1/scan.bend: https://jend.leeeet.dev/read.txt?path=gralha-text-scan@0.1.0.1/scan.bend&start_line=138&end_line=150 import Base # A number is read straight into a float: digits accumulate the mantissa # (fraction digits also scale a divisor), an exponent accumulates its own # digits, and a sign is taken where it may appear. Nothing is copied into a # scratch string. Each character is classified one step ahead, so the loop # branches on parameters: class 0 digit, 1 dot, 2 exponent mark, 3 sign, # 4 anything else; stage 0 start, 1 mantissa, 2 fraction, 3 after the # mark, 4 exponent digits. An exponent mark that no digit follows is not # part of the number (as in "1em"), so `mark` keeps what was read from the # mark on (the mark and any signs, reversed) to give back in that case. def number.class(+c: U32) -> U32: choose(U32, digit(c), 0, choose(U32, U32.is_eq(c, 46), 1, choose(U32, U32.is_eq(c, 101) || U32.is_eq(c, 69), 2, choose(U32, U32.is_eq(c, 43) || U32.is_eq(c, 45), 3, 4)))) Uses (5): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.or https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_eq https://jend.leeeet.dev/definition.txt?path=gralha-text-scan@0.1.0.1/scan.bend&name=choose https://jend.leeeet.dev/definition.txt?path=gralha-text-scan@0.1.0.1/scan.bend&name=digit