~/bend-docscommunity

scan.bend relies on unsafe/foreign

raw source on the hub · import gralha-text-scan@0.1.0.0/scan.bend as Scan

Text scanning, number parsing (the SVG/CSS number grammar, units, hex) and small helpers over strings, U32 and F32.

1 import
import Base

Types

type Scan source · line 63 · raw

Data

type Number source · line 138 · raw

Data

Definitions

def choose source · line 5 · raw

@-A:Type -> @yes:Bool -> @a:A -> @b:A -> A

def max.u32 source · line 10 · raw

@+a:U32 -> @+b:U32 -> U32

def min.u32 source · line 13 · raw

@+a:U32 -> @+b:U32 -> U32

def min source · line 16 · raw

@+a:F32 -> @+b:F32 -> F32

def max source · line 19 · raw

@+a:F32 -> @+b:F32 -> F32

def clamp source · line 22 · raw

@x:F32 -> @lo:F32 -> @hi:F32 -> F32

def code source · line 25 · raw

@c:Char -> U32

def space source · line 29 · raw

@+c:U32 -> Bool

def digit source · line 32 · raw

@+c:U32 -> Bool

def rev source · line 35 · raw

@s:String -> @acc:String -> String

def string.equal source · line 49 · raw

@a:String -> @b:String -> Bool

def branch source · line 52 · raw

@-A:Type -> @yes:Bool -> @a:(@_:Unit -> A) -> @b:(@_:Unit -> A) -> A

def trim source · line 57 · raw

@+s:String -> String

def until source · line 80 · raw

@s:String -> @+end:U32 -> @acc:String -> Scan

def prefix source · line 87 · raw

@s:String -> @p:String -> Bool

def drop source · line 94 · raw

@s:String -> @p:String -> String

def through source · line 100 · raw

@+s:String -> @+p:String -> String

def until.sequence source · line 106 · raw

@+s:String -> @+end:String -> @+acc:String -> Scan

def separators source · line 123 · raw

@s:String -> String

def number.exponent source · line 130 · raw

@+s:String -> Bool

def number.class source · line 150 · raw

@+c:U32 -> U32

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. The head is split off and 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 the string from the mark is kept to be the tail in that case.

def number.accepts source · line 155 · raw

@+k:U32 -> @+stage:U32 -> @+digits:Bool -> Bool

def number.pow10 source · line 161 · raw

@n:Nat -> @+acc:F32 -> F32

def number.finish source · line 168 · raw

@rest:String -> @mark:String -> @+stage:U32 -> @+sign:F32 -> @+mant:F32 -> @+div:F32 -> @+esign:F32 -> @+ev:U32 -> @+digits:Bool -> @+edigits:Bool -> Number

The value from the parts; rest is the string from the stop, mark the string from an exponent mark that turned out not to belong.

def number.split.at source · line 179 · raw

@t:String -> @mark:String -> @+stage:U32 -> @+digits:Bool -> Head

def number.split source · line 187 · raw

@atMark:Bool -> @+c:U32 -> @t:String -> @mark:String -> @+stage:U32 -> @+digits:Bool -> Head

def number source · line 220 · raw

@s:String -> Number

def number.default source · line 223 · raw

@num:Number -> @fallback:F32 -> F32

def scalar source · line 227 · raw

@s:String -> @fallback:F32 -> F32

def numbers.next source · line 230 · raw

@num:Number -> @next:(@_:String -> List<&2, F32>) -> List<&2, F32>

def nth source · line 238 · raw

@xs:List<&2, F32> -> @i:Nat -> @fallback:F32 -> F32

def uints.nth source · line 244 · raw

@xs:List<&2, U32> -> @n:Nat -> @+fallback:U32 -> U32

def hex.digit source · line 250 · raw

@+c:U32 -> U32

def hex source · line 255 · raw

@s:String -> @acc:U32 -> U32

def trim.both source · line 260 · raw

@s:String -> String

def unit source · line 263 · raw

@num:Number -> @reference:F32 -> F32

def string.contains source · line 274 · raw

@+s:String -> @+part:String -> Bool

def scan.head source · line 279 · raw

@s:Scan -> String

def unquote source · line 283 · raw

@+s:String -> String

def strings.has source · line 287 · raw

@xs:List<&2, String> -> @+s:String -> Bool

Unsafe

unsafe string.equal.go source · line 42 · raw

@same:Bool -> @a:String -> @b:String -> Bool

Consume equality inputs without rebuilding borrowed strings on the host stack.

unsafe until.go source · line 70 · raw

@hit:Bool -> @+c:U32 -> @t:String -> @+end:U32 -> @acc:String -> Scan

Scanning loops decide each character one step ahead (hit says whether c ends the scan), so the rest of the text is only ever held once: a shared tail would make every step pay for the sharing.

unsafe separators.go source · line 113 · raw

@skip:Bool -> @+c:U32 -> @t:String -> String

SVG number grammar, including adjacent signs and scientific notation.

unsafe number.go source · line 195 · raw

@h:Head -> @+stage:U32 -> @+sign:F32 -> @+mant:F32 -> @+div:F32 -> @+esign:F32 -> @+ev:U32 -> @+digits:Bool -> @+edigits:Bool -> Number

unsafe numbers source · line 235 · raw

@s:String -> List<&2, F32>