~/bend-docscommunity

json.bend checks

raw source on the hub · import element-text@0.1.0.0/json.bend as Json

1 import
import Base

Types

type Json source · line 12 · raw

Data

type Tok source · line 22 · raw

Data

type Esc source · line 54 · raw

Data

What a backslash escape turns into, and how many characters it took after the backslash.

type Str source · line 81 · raw

Data

The string body after an opening quote: its characters (reversed) and how many source characters it took, closing quote included.

type SK source · line 84 · raw

Data

type TK source · line 144 · raw

Data

type Step source · line 165 · raw

Data

One token at the head of s (after character c) and how many characters it took.

type Frame source · line 232 · raw

Data

An open container: an array's items, or an object's keys and values so far (reversed), with the key waiting for its value.

type B source · line 237 · raw

Data

The stack of open frames and the finished top-level value.

Definitions

def rev_str source · line 30 · raw

@cs:List<&2, Char> -> String

def hex_val source · line 33 · raw

@+c:U32 -> U32

def nth_c source · line 36 · raw

@xs:List<&2, Char> -> @n:Nat -> Char

def hex4 source · line 47 · raw

@+s:String -> U32

def esc_of source · line 57 · raw

@+s:String -> Esc

def esc_c source · line 69 · raw

@e:Esc -> U32

def esc_used source · line 74 · raw

@e:Esc -> Nat

def sk_of source · line 89 · raw

@s:String -> SK

def after_esc source · line 96 · raw

@+t:String -> String

def str_step source · line 101 · raw

@fuel:Nat -> @s:String -> @+acc:List<&2, Char> -> @+used:Nat -> @k:SK -> Str

k classifies the head of s (computed by the caller): a plain character, the closing quote (or the end), or a backslash escape.

def num_char source · line 120 · raw

@+c:Char -> Bool

def num_head source · line 123 · raw

@s:String -> Bool

def num_run source · line 133 · raw

@s:String -> @go:Bool -> String

The number at the head of s. go (the caller's test of the head) stops the walk at the number's end; a Bool.pick here walked the whole rest of the text for every number (bench json: k 1.98).

def tk_of source · line 152 · raw

@+c:Char -> TK

def punct source · line 159 · raw

@+c:Char -> Tok

def word source · line 168 · raw

@+s:String -> Step

def str_tok source · line 173 · raw

@r:Str -> Step

def string_tok source · line 180 · raw

@+fuel:Nat -> @+t:String -> Step

fuel is the tokenizer's own (no String.length of the rest per string, which made parsing quadratic in the number of strings).

def step_of source · line 183 · raw

@k:TK -> @+c:Char -> @+s:String -> @+t:String -> @+fuel:Nat -> Step

def step_tok source · line 199 · raw

@st:Step -> Maybe<&2, Tok>

def step_used source · line 204 · raw

@st:Step -> Nat

def push_m source · line 209 · raw

@m:Maybe<&2, Tok> -> @+acc:List<&2, Tok> -> List<&2, Tok>

def tokens source · line 216 · raw

@fuel:Nat -> @s:String -> @+acc:List<&2, Tok> -> List<&2, Tok>

def str_of_json source · line 240 · raw

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

def add_val source · line 257 · raw

@stack:List<&2, Frame> -> @+v:Json -> @+done:Maybe<&2, Json> -> B

A value lands in the top frame: an array item, an object key (a string when no key waits), or the value for the waiting key.

def close_top source · line 272 · raw

@stack:List<&2, Frame> -> @+done:Maybe<&2, Json> -> B

def on_tok source · line 283 · raw

@b:B -> @t:Tok -> B

def build source · line 300 · raw

@ts:List<&2, Tok> -> @+b:B -> B

def result source · line 307 · raw

@b:B -> Maybe<&2, Json>

def parse source · line 314 · raw

@+s:String -> Maybe<&2, Json>

A JSON text as a value; None when it is not JSON. (Lenient in one way: commas and colons are not checked for position.)

def hex_digit source · line 319 · raw

@+n:U32 -> String

def esc_kind source · line 327 · raw

@+c:Char -> U32

What a character becomes in a JSON string: 0 \", 1 \\, 2 a short escape (\b \t \n \f \r, as ES QuoteJSONString writes them), 3 \u00XX (another control), 4 \uXXXX (a surrogate code point: a JS string can hold one, and it is not valid UTF-8 on the wire; Chrome's JSON escapes it too), 5 itself. A match, not Bool.pick: only the character's own escape is built.

def esc_as source · line 332 · raw

@k:Nat -> @+c:Char -> String

def esc_char source · line 350 · raw

@+c:Char -> String

def esc_go source · line 353 · raw

@s:String -> String

def quote source · line 360 · raw

@+s:String -> String

def first_s source · line 363 · raw

@xs:List<&2, String> -> String

def rest_s source · line 370 · raw

@xs:List<&2, String> -> List<&2, String>

def sep_key source · line 377 · raw

@+first:Bool -> @+obj:Bool -> @+keys:List<&2, String> -> String

def show_items source · line 381 · raw

@xs:List<&2, Json> -> @+keys:List<&2, String> -> @+obj:Bool -> @+first:Bool -> String

Values separated by commas; keys beside them when they are an object's.

def show source · line 400 · raw

@+v:Json -> String

def show_or source · line 403 · raw

@m:Maybe<&2, Json> -> @+d:String -> String

def lookup source · line 412 · raw

@ks:List<&2, String> -> @vs:List<&2, Json> -> @+key:String -> Maybe<&2, Json>

def get source · line 420 · raw

@v:Json -> @+key:String -> Maybe<&2, Json>

An object's field.

def text_or source · line 435 · raw

@m:Maybe<&2, Json> -> @+d:String -> String

def bool_or source · line 454 · raw

@m:Maybe<&2, Json> -> @+d:Bool -> Bool

def int_go source · line 473 · raw

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

def u32_or source · line 481 · raw

@+m:Maybe<&2, Json> -> @+d:U32 -> U32

The integer part of a number (or numeric string) as U32; d when absent.

def arr_or_empty source · line 485 · raw

@m:Maybe<&2, Json> -> List<&2, Json>