~/bend-docscommunity

src/value.bend checks

raw source on the hub · import emerging-ezjson@1.1.0.0/src/value.bend as Value

src/value: a JSON value. Null, bool, number, string, array, and object. An array is a JArr of JCons cells ending in JNil; an object is a JObj of JPair cells ending in JNil. A number keeps its source text.

2 imports
import Base
import ./lazy.bend as Lazy

Types

type Json source · line 10 · raw

Data

a JSON value; JNil, JCons and JPair are the cells of arrays and objects. JSpan and JBind are the same string and key, as the first n chars of a source suffix, so a parse does not copy that text.

type Num source · line 24 · raw

Data

where a scan of a JSON number is

type Shape source · line 352 · raw

Data

what wf.go checks: a value, the cells of an array, or the cells of an object

Definitions

def span.str source · line 37 · raw

@src:String -> @+nn:U32 -> @zero:Bool -> String

the first nn chars of src as their own string

def span.eq.go source · line 48 · raw

@src:String -> @same:Bool -> @zero:Bool -> @key:String -> @+nn:U32 -> Bool

whether the first nn chars of src equal key, stopping at the first miss. A count past the end of src covers what there is, as span.str reads it

def span.eq source · line 64 · raw

@+src:String -> @+nn:U32 -> @+key:String -> Bool

whether the first nn chars of src are key

def reverse source · line 68 · raw

@cells:Json -> @acc:Json -> Json

reverses a chain of JCons or JPair cells onto acc

def arr.go source · line 79 · raw

@items:List<&2, Json> -> Json

def arr source · line 87 · raw

@items:List<&2, Json> -> Json

an array from a list

def obj.go source · line 90 · raw

@pairs:List<&1, Pair(String, Json)> -> Json

def obj source · line 98 · raw

@pairs:List<&1, Pair(String, Json)> -> Json

an object from pairs

def null source · line 102 · raw

Json

null

def bool source · line 106 · raw

@flag:Bool -> Json

a boolean

def str source · line 110 · raw

@txt:String -> Json

a string

def num.go source · line 113 · raw

@raw:String -> @ok:Bool -> Json

def num.ok.digit source · line 120 · raw

@+cp:U32 -> Bool

def num.ok.expmark source · line 123 · raw

@+cp:U32 -> Bool

def num.ok.lead source · line 126 · raw

@+cp:U32 -> Bool

def num.ok.step.lead source · line 129 · raw

@ok:Bool -> Num

def num.ok.step.int.go source · line 136 · raw

@+cp:U32 -> @zero:Bool -> Num

def num.ok.step.int source · line 143 · raw

@+cp:U32 -> Num

def num.ok.step.start.go source · line 146 · raw

@+cp:U32 -> @minus:Bool -> Num

def num.ok.step.start source · line 153 · raw

@+cp:U32 -> Num

def num.ok.step.mark.go source · line 156 · raw

@mark:Bool -> Num

def num.ok.step.mark source · line 163 · raw

@+cp:U32 -> Num

def num.ok.step.body.digit source · line 166 · raw

@more:Bool -> Num

def num.ok.step.body.other.go source · line 173 · raw

@+cp:U32 -> @dot:Bool -> Num

def num.ok.step.body.other source · line 180 · raw

@+cp:U32 -> Num

def num.ok.step.body.go source · line 183 · raw

@+cp:U32 -> @more:Bool -> @digit:Bool -> Num

def num.ok.step.body source · line 190 · raw

@+cp:U32 -> @more:Bool -> Num

def num.ok.step.frac.other source · line 193 · raw

@+cp:U32 -> @have:Bool -> Num

def num.ok.step.frac.go source · line 200 · raw

@+cp:U32 -> @have:Bool -> @digit:Bool -> Num

def num.ok.step.frac source · line 207 · raw

@+cp:U32 -> @have:Bool -> Num

def num.ok.step.expd.go source · line 210 · raw

@digit:Bool -> Num

def num.ok.step.expd source · line 217 · raw

@+cp:U32 -> Num

def num.ok.step.exps.minus.go source · line 220 · raw

@+cp:U32 -> @minus:Bool -> Num

def num.ok.step.exps.minus source · line 227 · raw

@+cp:U32 -> Num

def num.ok.step.exps.go source · line 230 · raw

@+cp:U32 -> @plus:Bool -> Num

def num.ok.step.exps source · line 237 · raw

@+cp:U32 -> Num

def num.ok.step source · line 240 · raw

@st:Num -> @+cp:U32 -> Num

def num.ok.done source · line 263 · raw

@st:Num -> Bool

def num.ok.go source · line 276 · raw

@cs:List<&2, Char> -> @st:Num -> Bool

def num.ok source · line 284 · raw

@txt:String -> Bool

whether text is a JSON number

def num source · line 288 · raw

@+raw:String -> Json

a JSON number from its text, or null when that text is not one

def find.eq.go source · line 293 · raw

@left:String -> @right:String -> @same:Bool -> Bool

character-for-character equality. String.eq rebuilds both strings and discards the copies; a search only needs the bool. A mismatch stops.

def find.eq source · line 302 · raw

@lhs:String -> @rhs:String -> Bool

def find.at source · line 306 · raw

@rest:Json -> @+key:String -> @eq:Bool -> @vv:Json -> Json

the matched value, or the next pair when the key differs

def find source · line 318 · raw

@cells:Json -> @+key:String -> Json

the value of a key in a chain of pairs; JNull when the key is absent

def get source · line 329 · raw

@val:Json -> @key:String -> Json

an object's value at a key; JNull when it is not an object or has no such key. A repeated key reads as the first value.

def at.go source · line 336 · raw

@cells:Json -> @+idx:U32 -> Json

def at source · line 344 · raw

@val:Json -> @idx:U32 -> Json

an array's item at an index; JNull when it is not an array or has none

def wf.go source · line 360 · raw

@val:Json -> @shape:Shape -> Bool

whether a value, or a chain of cells, has the shape the parser and the builders give: arrays and objects are chains of cells ending in JNil, no cell stands where a value belongs, and a number's text is a JSON number

def wf source · line 391 · raw

@val:Json -> Bool

whether a value is well-formed: the shape every value from the builders and from parse has. print writes JSON text for exactly these

def has.go source · line 395 · raw

@cells:Json -> @+key:String -> Bool

whether a chain of pairs has the key, stopping at the first match

def has source · line 405 · raw

@val:Json -> @key:String -> Bool

whether an object has the key; false when the value is not an object

def len.go source · line 413 · raw

@cells:Json -> Nat

how many cells a chain of array or object cells holds

def len source · line 425 · raw

@val:Json -> U32

how many elements an array, or members an object, has; 0 for anything else

def as_str source · line 435 · raw

@val:Json -> Maybe<&2, String>

a string, or none when the value is not one

def as_bool source · line 445 · raw

@val:Json -> Maybe<&2, Bool>

a boolean, or none when the value is not one

def as_num source · line 453 · raw

@val:Json -> Maybe<&2, String>

a number's text, or none when the value is not a number

def as_u32 source · line 461 · raw

@val:Json -> Maybe<&2, U32>

a number as a U32, or none when it is not one or does not fit

def f32.top source · line 469 · raw

F32

the largest finite F32

def f32.fit.go source · line 474 · raw

@xx:F32 -> @finite:Bool -> Maybe<&2, F32>

a read that stayed finite; none when it did not. A JSON number never spells infinity, so an infinite read is a number too large for F32

def f32.fit source · line 482 · raw

@got:Maybe<&2, F32> -> Maybe<&2, F32>

a read that stayed finite, or none

def as_f32 source · line 490 · raw

@val:Json -> Maybe<&2, F32>

a number as an F32, or none when it is not one or does not fit