~/bend-docscommunity

lex.bend checks

raw source on the hub · import bend-safetensors-reader@0.1.0.0/lex.bend as Lex

The tokens of a safetensors header (JSON), from its bytes: one step a byte, so every step is a plain state change. Strings are decoded to code points (UTF-8 and \u escapes, surrogate pairs joined); numbers are unsigned decimal integers up to 2^64 - 1, which is all a header holds. Anything else becomes a TBad token, and the rest is ignored.

2 imports
import Base
import ./w64.bend as W

Types

type Tok source · line 7 · raw

Data

type Lx source · line 18 · raw

Data

type Out source · line 29 · raw

Data

type Cb source · line 48 · raw

Data

type Cs source · line 112 · raw

Data

Definitions

def bad source · line 32 · raw

@why:String -> @ts:List<&2, Tok> -> Out

def in_range source · line 35 · raw

@+b:U32 -> @+lo:U32 -> @+hi:U32 -> Bool

def chars source · line 39 · raw

@cs:List<&2, U32> -> @acc:String -> String

a string's code points, kept reversed while lexing, as a String

def cls_top source · line 60 · raw

@+b:U32 -> Cb

def top_step source · line 71 · raw

@c:Cb -> @+b:U32 -> @ts:List<&2, Tok> -> Out

def num_more source · line 96 · raw

@r:Maybe<&2, 0xd8619c297e019f1c512e443a1b7ff426/w64.W64> -> @ts:List<&2, Tok> -> Out

def num_step source · line 103 · raw

@isd:Bool -> @v:0xd8619c297e019f1c512e443a1b7ff426/w64.W64 -> @+b:U32 -> @ts:List<&2, Tok> -> Out

def cls_str source · line 122 · raw

@+b:U32 -> Cs

def str_step source · line 131 · raw

@c:Cs -> @+b:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def is_scalar source · line 150 · raw

@+cp:U32 -> Bool

def utf_done source · line 153 · raw

@ok:Bool -> @+cp:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def utf_next source · line 160 · raw

@last:Bool -> @+need:U32 -> @+cp:U32 -> @+min:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def utf_step source · line 167 · raw

@cont:Bool -> @+b:U32 -> @+need:U32 -> @+cp:U32 -> @+min:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def esc_val source · line 177 · raw

@+b:U32 -> U32

the character a one-letter escape stands for, 1 for \u, 0 for none

def esc_fin source · line 188 · raw

@isu:Bool -> @+v:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def esc_step source · line 195 · raw

@none:Bool -> @+v:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def hex_val source · line 203 · raw

@+b:U32 -> U32

the value of a hex digit, 16 for none

def is_high source · line 208 · raw

@+v:U32 -> Bool

def is_low source · line 211 · raw

@+v:U32 -> Bool

def u_alone source · line 215 · raw

@high:Bool -> @+v:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

a \uXXXX with no high surrogate before it

def u_pair source · line 223 · raw

@low:Bool -> @+hi:U32 -> @+v:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

a \uXXXX after a high surrogate: it must be the low half

def u_done source · line 230 · raw

@first:Bool -> @+hi:U32 -> @+v:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def hex_next source · line 237 · raw

@last:Bool -> @+left:U32 -> @+v:U32 -> @+hi:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def hex_step source · line 244 · raw

@none:Bool -> @+d:U32 -> @+left:U32 -> @+v:U32 -> @+hi:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def low_step source · line 251 · raw

@ok:Bool -> @+hi:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def lowu_step source · line 258 · raw

@ok:Bool -> @+hi:U32 -> @cs:List<&2, U32> -> @ts:List<&2, Tok> -> Out

def step source · line 267 · raw

@o:Out -> @+b:U32 -> Out

def finish source · line 290 · raw

@o:Out -> List<&2, Tok>

def go source · line 301 · raw

@bs:List<&2, U32> -> @o:Out -> List<&2, Tok>

def tokens source · line 309 · raw

@bs:List<&2, U32> -> List<&2, Tok>

the tokens of a header's bytes