json.bend checks
raw source on the hub · import cswap-bend-cli@0.1.0.0/json.bend as Json
4 imports
import Base import ./json/lex.bend as Lex import ./json/quote.bend as Quote import ./json/scan.bend as Scan
Types
type Json source · line 17 · raw
Data
JNullJson
JBool@b:Bool -> Json
JNum@text:String -> Json
JStr@s:String -> Json
JArr@items:Json -> Json
JObj@fields:Json -> Json
JNilJson
JCons@head:Json -> @tail:Json -> Json
JField@key:String -> @val:Json -> @tail:Json -> Json
type Mode source · line 30 · raw
Data
MValMode
MAFirstMode
MANextMode
MAAfterMode
MOFirstMode
MONextMode
MOAfterMode
type Plan source · line 87 · raw
Data
What one parser step decides, before it recurses: a finished result, a
bracketed body, two parts to parse (array item and rest, object field and
rest), or one more step in another mode. Splitting "decide" from "recurse"
keeps val a single self-recursive def (Bend has no mutual recursion) with
few arms.
PRes@r:Result<&2, &2, String, Json> -> Plan
PArr@t:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
PObj@t:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
PItems@first:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> @rest:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
PFields@k:String -> @vt:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> @rest:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
PNext@mode:Mode -> @t:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
Definitions
def only source · line 39 · raw
@t:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> @v:Json -> Result<&2, &2, String, Json>
def wrap.arr source · line 46 · raw
@ok:Bool -> @r:Result<&2, &2, String, Json> -> Result<&2, &2, String, Json>
def wrap.obj source · line 55 · raw
@ok:Bool -> @r:Result<&2, &2, String, Json> -> Result<&2, &2, String, Json>
def item.cons source · line 64 · raw
@x:Result<&2, &2, String, Json> -> @rest:Result<&2, &2, String, Json> -> Result<&2, &2, String, Json>
def field.cons source · line 73 · raw
@k:String -> @x:Result<&2, &2, String, Json> -> @rest:Result<&2, &2, String, Json> -> Result<&2, &2, String, Json>
def plan.val source · line 95 · raw
@+toks:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
def plan.items source · line 116 · raw
@+toks:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
def plan.arr_first source · line 123 · raw
@+toks:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
def plan.arr_next source · line 130 · raw
@+toks:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
def plan.arr_after source · line 137 · raw
@+toks:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
def plan.field source · line 146 · raw
@k:String -> @+t:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
def plan.obj_first source · line 149 · raw
@+toks:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
def plan.obj_next source · line 158 · raw
@+toks:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
def plan.obj_after source · line 167 · raw
@+toks:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
def plan source · line 176 · raw
@mode:Mode -> @+toks:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Plan
def body source · line 193 · raw
@+t:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok>
def val source · line 199 · raw
@fuel:Nat -> @pl:Plan -> Result<&2, &2, String, Json>
One def for values, array items and object fields: plan says which step
this is. fuel bounds the work (3 * tokens + 5). An item's tokens are those
up to the next comma or closer at depth 0.
def parse.pick source · line 216 · raw
@msg:String -> @r:Result<&2, &2, String, Json> -> Result<&2, &2, String, Json>
def parse.toks source · line 223 · raw
@+toks:List<&2, 0x0717344745a30ebad1f19045228e8f18/json/lex.Tok> -> Result<&2, &2, String, Json>
def parse source · line 227 · raw
@+s:String -> Result<&2, &2, String, Json>
Parse JSON text; Fail carries a message.
def sep.of source · line 232 · raw
@next:Json -> @+style:U32 -> @d:Nat -> String
def bool.show source · line 239 · raw
@b:Bool -> String
def emit.wrap source · line 243 · raw
@open:String -> @close:String -> @items:Json -> @inner:String -> @+style:U32 -> @+d:Nat -> String
A bracketed body: [] or {} when empty, else the body on its own lines.
def emit.go source · line 251 · raw
@j:Json -> @+style:U32 -> @+ascii:Bool -> @+d:Nat -> String
The emitter. j shrinks on every call; d is the nesting depth.
def emit source · line 273 · raw
@j:Json -> String
Compact, no spaces, UTF-8 left as is.
def emit_py source · line 277 · raw
@j:Json -> String
json.dumps(j): , and : separators, ensure_ascii.
def emit_pretty source · line 283 · raw
@j:Json -> String
json.dumps(j, indent=2), as the reference writes sequence.json and settings: ensure_ascii on (the reference never passes ensure_ascii=False for its own files), no trailing newline.
def emit_pretty_utf8 source · line 287 · raw
@j:Json -> String
json.dumps(j, indent=2, ensure_ascii=False).
def field.pick source · line 290 · raw
@hit:Bool -> @v:Json -> @rest:Maybe<&2, Json> -> Maybe<&2, Json>
def field.get source · line 299 · raw
@+key:String -> @fields:Json -> Maybe<&2, Json>
def get source · line 307 · raw
@key:String -> @j:Json -> Maybe<&2, Json>
The value under key of an object; None for a missing key or a non-object.
def as_string source · line 314 · raw
@j:Json -> Maybe<&2, String>
def as_bool source · line 321 · raw
@j:Json -> Maybe<&2, Bool>
def as_u32 source · line 329 · raw
@j:Json -> Maybe<&2, U32>
A non-negative integer that fits U32; 5.0, -1 and 1e3 are None.
def arr.chain source · line 337 · raw
@xs:List<&2, Json> -> Json
Array of the values, in order.
def arr source · line 344 · raw
@xs:List<&2, Json> -> Json
def items.list source · line 348 · raw
@items:Json -> List<&2, Json>
The elements of an array; empty for any other value.
def to_list source · line 355 · raw
@j:Json -> List<&2, Json>
def field.of source · line 362 · raw
@kv:Pair(String, Json) -> @rest:Json -> Json
def obj.chain source · line 366 · raw
@kvs:List<&1, Pair(String, Json)> -> Json
def of_pairs source · line 374 · raw
@kvs:List<&1, Pair(String, Json)> -> Json
Object from ordered (key, value) pairs.
def pairs.list source · line 377 · raw
@fields:Json -> List<&1, Pair(String, Json)>
def to_pairs source · line 385 · raw
@j:Json -> List<&1, Pair(String, Json)>
The (key, value) pairs of an object, in file order.
def keys.list source · line 392 · raw
@fields:Json -> List<&2, String>
def keys source · line 399 · raw
@j:Json -> List<&2, String>
def set.pick source · line 406 · raw
@hit:Bool -> @key:String -> @val:Json -> @v:Json -> @t:Json -> @rest:Json -> Json
def set.go source · line 413 · raw
@+key:String -> @+val:Json -> @fields:Json -> Json
def set source · line 421 · raw
@+key:String -> @+val:Json -> @j:Json -> Json
Replace the value under key in place, or append the field.
def del.pick source · line 428 · raw
@hit:Bool -> @k:String -> @v:Json -> @t:Json -> @rest:Json -> Json
def del.go source · line 435 · raw
@+key:String -> @fields:Json -> Json
def del source · line 443 · raw
@+key:String -> @j:Json -> Json
The object without key.
def unwrap source · line 452 · raw
@+r:Result<&2, &2, String, Json> -> Json
The value of a parse that must have worked; JNull when it did not. For tests and constants, not for untrusted text.