XU XUv0.16.0

#encoding/xun

import: #encoding/xun

counts: 4 functions, 36 methods, 2 types, 5 constants, 0 method sets

0.11.4 parsing and serialization

Typed block lists inherit their scalar type, validate each element and preserve container/element tags when serialized. Safe homogeneous non-string scalar lists can use compact output; string lists retain block output. Serialization spelling may change: update text snapshots or compare parsed trees when spelling is not contractual. Legacy nonempty !s[...] scalar input remains accepted.

Collection nesting below the root is bounded by MAX_DEPTH (64), including inline, empty and typed containers. Duration validation rejects malformed or unitless input and always advances. Multiline parsing checks structural indentation separately from payload whitespace.

const KIND_DICT

XuAPI
pub const KIND_DICT = 0

Purpose

Constant KIND_DICT, defining protocol or algorithm parameters.

const KIND_LIST

XuAPI
pub const KIND_LIST = 1

Purpose

Constant KIND_LIST, defining protocol or algorithm parameters.

const KIND_SCALAR

XuAPI
pub const KIND_SCALAR = 2

Purpose

Constant KIND_SCALAR, defining protocol or algorithm parameters.

const MAX_BYTES

XuAPI
pub const MAX_BYTES = 1048576

Purpose

Constant MAX_BYTES, defining protocol or algorithm parameters.

const MAX_DEPTH

XuAPI
pub const MAX_DEPTH = 64

Purpose

Constant MAX_DEPTH, defining protocol or algorithm parameters.

struct Span

XuAPI
pub struct Span {
    pub lo int
    pub hi int
}

Purpose

Structure encapsulating lo, hi.

Public fields

lo int
field (int)
hi int
field (int)

struct Doc

XuAPI
pub struct Doc {
    pub kinds []int
    pub tag_lo []int
    pub tag_hi []int
    pub text_lo []int
    pub text_hi []int
    pub key_lo []int
    pub key_hi []int
    pub key_hashes []int
    pub firsts []int
    pub nexts []int
    pub lasts []int
    pub buf string
    pub root_idx int
    pub err string
    pub line int
    pub line_starts []int
    pub line_ends []int
    pub i int
    pub tok_kind int
    pub tok_no int
    pub tok_klo int
    pub tok_khi int
    pub tok_khash int
    pub tok_vlo int
    pub tok_vhi int
}

Purpose

Structure encapsulating kinds, tag_lo, tag_hi, text_lo, text_hi.

Public fields

kinds []int
Tree storage (parallel arrays; node ids index all of them).
tag_lo []int
field ([]int)
tag_hi []int
field ([]int)
text_lo []int
field ([]int)
text_hi []int
field ([]int)
key_lo []int
field ([]int)
key_hi []int
field ([]int)
key_hashes []int
field ([]int)
firsts []int
field ([]int)
nexts []int
field ([]int)
lasts []int
Child-link bookkeeping during parsing (last child of each node).
buf string
Single arena holding source document bytes plus any unescaped/multiline/interned strings.
root_idx int
field (int)
err string
error
line int
field (int)
line_starts []int
Parse state (line index i -> 1-based line number i + 1).
line_ends []int
field ([]int)
i int
index or integer
tok_kind int
field (int)
tok_no int
field (int)
tok_klo int
field (int)
tok_khi int
field (int)
tok_khash int
field (int)
tok_vlo int
field (int)
tok_vhi int
field (int)

new_doc

XuAPI
pub fn new_doc() Doc

Purpose

Construct doc.

Parameters

No arguments are required.

Returns

Doc — a value of this type

(Doc) ok

XuAPI
pub fn (d Doc) ok() bool

Purpose

Execute ok on Doc.

Parameters

d Doc
The Doc instance used by this call (value receiver).

Returns

bool — true or false

(Doc) error

XuAPI
pub fn (d Doc) error() string

Purpose

Execute error on Doc.

Parameters

d Doc
The Doc instance used by this call (value receiver).

Returns

string — result string

(Doc) error_line

XuAPI
pub fn (d Doc) error_line() int

Purpose

Operation on Doc: error line.

Parameters

d Doc
The Doc instance used by this call (value receiver).

Returns

int — a value of this type

(Doc) root

XuAPI
pub fn (d Doc) root() int

Purpose

Execute root on Doc.

Parameters

d Doc
The Doc instance used by this call (value receiver).

Returns

int — a value of this type

(Doc) kind

XuAPI
pub fn (d Doc) kind(n int) int

Purpose

Execute kind on Doc.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) is_dict

XuAPI
pub fn (d Doc) is_dict(n int) bool

Purpose

Operation on Doc: whether it is dict.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) is_list

XuAPI
pub fn (d Doc) is_list(n int) bool

Purpose

Operation on Doc: whether it is list.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) is_scalar

XuAPI
pub fn (d Doc) is_scalar(n int) bool

Purpose

Operation on Doc: whether it is scalar.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) tag

XuAPI
pub fn (d Doc) tag(n int) string

Purpose

Execute tag on Doc.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

string — result string

(Doc) text

XuAPI
pub fn (d Doc) text(n int) string

Purpose

Operation on Doc: return the current text.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

string — result string

(Doc) key

XuAPI
pub fn (d Doc) key(n int) string

Purpose

Execute key on Doc.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

string — result string

(Doc) count

XuAPI
pub fn (d Doc) count(n int) int

Purpose

Operation on Doc: count non-overlapping occurrences.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) at

XuAPI
pub fn (d Doc) at(n int, i int) int

Purpose

Execute at on Doc.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)
i int
index or integer (int)

Returns

int — a value of this type

(Doc) get

XuAPI
pub fn (d Doc) get(n int, key string) int

Purpose

Execute get on Doc.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)
key string
key (string)

Returns

int — a value of this type

(Doc) as_str

XuAPI
pub fn (d Doc) as_str(n int) string

Purpose

Operation on Doc: as str.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

string — result string

(Doc) as_int

XuAPI
pub fn (d Doc) as_int(n int) int

Purpose

Operation on Doc: as int.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) as_f64

XuAPI
pub fn (d Doc) as_f64(n int) f64

Purpose

Operation on Doc: as f64.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

f64 — a value of this type

(Doc) as_bool

XuAPI
pub fn (d Doc) as_bool(n int) bool

Purpose

Operation on Doc: as bool.

Parameters

d Doc
The Doc instance used by this call (value receiver).
n int
count, length, or limit (int)

Returns

bool — true or false

($&Doc) set_root

XuAPI
pub fn (d $&Doc) set_root(r int)

Purpose

Operation on $&Doc: set root.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
r int
rune (Unicode code point) (int)

Returns

This call does not return a value.

($&Doc) new_node

XuAPI
pub fn (d $&Doc) new_node(kind int, tag string, text string, key string) int

Purpose

Operation on $&Doc: construct node.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
kind int
kind tag (int)
tag string
tag (string)
text string
text (string)
key string
key (string)

Returns

int — a value of this type

($&Doc) attach

XuAPI
pub fn (d $&Doc) attach(parent int, child int)

Purpose

Execute attach on $&Doc.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
child int
child (int)

Returns

This call does not return a value.

($&Doc) add_dict

XuAPI
pub fn (d $&Doc) add_dict(parent int, key string) int

Purpose

Operation on $&Doc: add dict.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
key string
key (string)

Returns

int — a value of this type

($&Doc) add_list

XuAPI
pub fn (d $&Doc) add_list(parent int, key string) int

Purpose

Operation on $&Doc: add list.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
key string
key (string)

Returns

int — a value of this type

($&Doc) add_scalar

XuAPI
pub fn (d $&Doc) add_scalar(parent int, key string, tag string, text string) int

Purpose

Operation on $&Doc: add scalar.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
key string
key (string)
tag string
tag (string)
text string
text (string)

Returns

int — a value of this type

($&Doc) add_str

XuAPI
pub fn (d $&Doc) add_str(parent int, key string, val string) int

Purpose

Operation on $&Doc: add str.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
key string
key (string)
val string
value (string)

Returns

int — a value of this type

($&Doc) add_int

XuAPI
pub fn (d $&Doc) add_int(parent int, key string, val int) int

Purpose

Operation on $&Doc: add int.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
key string
key (string)
val int
value (int)

Returns

int — a value of this type

($&Doc) add_f64

XuAPI
pub fn (d $&Doc) add_f64(parent int, key string, val f64) int

Purpose

Operation on $&Doc: add f64.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
key string
key (string)
val f64
value (f64)

Returns

int — a value of this type

($&Doc) add_bool

XuAPI
pub fn (d $&Doc) add_bool(parent int, key string, val bool) int

Purpose

Operation on $&Doc: add bool.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
key string
key (string)
val bool
value (bool)

Returns

int — a value of this type

($&Doc) push_dict

XuAPI
pub fn (d $&Doc) push_dict(parent int) int

Purpose

Operation on $&Doc: push dict.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)

Returns

int — a value of this type

($&Doc) push_list

XuAPI
pub fn (d $&Doc) push_list(parent int) int

Purpose

Operation on $&Doc: push list.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)

Returns

int — a value of this type

($&Doc) push_scalar

XuAPI
pub fn (d $&Doc) push_scalar(parent int, tag string, text string) int

Purpose

Operation on $&Doc: push scalar.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
tag string
tag (string)
text string
text (string)

Returns

int — a value of this type

($&Doc) push_str

XuAPI
pub fn (d $&Doc) push_str(parent int, val string) int

Purpose

Operation on $&Doc: push str.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
val string
value (string)

Returns

int — a value of this type

($&Doc) push_int

XuAPI
pub fn (d $&Doc) push_int(parent int, val int) int

Purpose

Operation on $&Doc: push int.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
val int
value (int)

Returns

int — a value of this type

($&Doc) push_f64

XuAPI
pub fn (d $&Doc) push_f64(parent int, val f64) int

Purpose

Operation on $&Doc: push f64.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
val f64
value (f64)

Returns

int — a value of this type

($&Doc) push_bool

XuAPI
pub fn (d $&Doc) push_bool(parent int, val bool) int

Purpose

Operation on $&Doc: push bool.

Parameters

d $&Doc
The Doc instance used by this call (exclusive borrow).
parent int
parent (int)
val bool
value (bool)

Returns

int — a value of this type

parse

XuAPI
pub fn parse(src &string) Doc

Purpose

Parse the input.

Parameters

src &string
source (read-only borrow; caller keeps the original; type &string)

Returns

Doc — a value of this type

decode

XuAPI
pub fn decode(src &string) Doc

Purpose

Decode data from encoded representation.

Parameters

src &string
source (read-only borrow; caller keeps the original; type &string)

Returns

Doc — a value of this type

encode

XuAPI
pub fn encode(d &Doc) string

Purpose

Encode data into output format.

Parameters

d &Doc
d (read-only borrow; caller keeps the original; type &Doc)

Returns

string — result string

(Doc) to_xun

XuAPI
pub fn (d Doc) to_xun() string

Purpose

Operation on Doc: convert to xun.

Parameters

d Doc
The Doc instance used by this call (value receiver).

Returns

string — result string