The example parses the people document in your selected format.
It then reads Ada's age through the document nodes.
Typed reads give you these values without serializing the document.
people_text holds this document:
dust 232 B
#_ada { name Ada
role engineer
age 36 }
#_bob { name Bob
role engineer
age 41
mentor { #link #_ada } }
#_cy { name Cy
role designer
age 29 }
#_tx { author smoke
reason seed }
c 647 B
stardust_document * people = NULL ;
int64_t root = 0 , ada = 0 , age = 0 ;
int64_t result = 0 ;
int64_t status = stardust_parse (people_text , STARDUST_DUST , & people );
if (status == STARDUST_OK ) status = stardust_document_root (people , & root );
if (status == STARDUST_OK ) status = stardust_document_member (people , root , (stardust_bytes ){(const uint8_t * )"#_ada" , 5 }, & ada );
if (status == STARDUST_OK ) status = stardust_document_member (people , ada , (stardust_bytes ){(const uint8_t * )"age" , 3 }, & age );
if (status == STARDUST_OK ) status = stardust_document_i64 (people , age , & result );
stardust_document_release (people );
if (status != STARDUST_OK ) return status ; Result / 2 B
36
A document number is an i64 integer or a finite f64 value. The number type defines both.
An integer read requires an integer node. A floating-point node can cause the read to fail. Choose the typed read that matches the node that you read.
c 141 B
int64_t stardust_schema_validate (const stardust_document * bundle , const stardust_document * instance , int64_t node , stardust_result ** output ); c 95 B
int64_t stardust_result_error (const stardust_result * result , stardust_diagnostic_view * output ); c 54 B
void stardust_result_release (stardust_result * result );
c 512 B
stardust_document * bundle = NULL ;
stardust_document * instance = NULL ;
stardust_result * validated = NULL ;
int64_t status = stardust_parse (bundle_text , STARDUST_DUST , & bundle );
if (status == STARDUST_OK ) status = stardust_parse (instance_text , STARDUST_DUST , & instance );
if (status == STARDUST_OK ) status = stardust_schema_validate (bundle , instance , 0 , & validated );
stardust_result_release (validated );
stardust_document_release (instance );
stardust_document_release (bundle );
if (status != STARDUST_OK ) return status ;
c 512 B
stardust_document * bundle = NULL ;
stardust_document * instance = NULL ;
stardust_result * validated = NULL ;
int64_t status = stardust_parse (bundle_text , STARDUST_JSON , & bundle );
if (status == STARDUST_OK ) status = stardust_parse (instance_text , STARDUST_JSON , & instance );
if (status == STARDUST_OK ) status = stardust_schema_validate (bundle , instance , 0 , & validated );
stardust_result_release (validated );
stardust_document_release (instance );
stardust_document_release (bundle );
if (status != STARDUST_OK ) return status ;
c 510 B
stardust_document * bundle = NULL ;
stardust_document * instance = NULL ;
stardust_result * validated = NULL ;
int64_t status = stardust_parse (bundle_text , STARDUST_EDN , & bundle );
if (status == STARDUST_OK ) status = stardust_parse (instance_text , STARDUST_EDN , & instance );
if (status == STARDUST_OK ) status = stardust_schema_validate (bundle , instance , 0 , & validated );
stardust_result_release (validated );
stardust_document_release (instance );
stardust_document_release (bundle );
if (status != STARDUST_OK ) return status ;
c 512 B
stardust_document * bundle = NULL ;
stardust_document * instance = NULL ;
stardust_result * validated = NULL ;
int64_t status = stardust_parse (bundle_text , STARDUST_TRON , & bundle );
if (status == STARDUST_OK ) status = stardust_parse (instance_text , STARDUST_TRON , & instance );
if (status == STARDUST_OK ) status = stardust_schema_validate (bundle , instance , 0 , & validated );
stardust_result_release (validated );
stardust_document_release (instance );
stardust_document_release (bundle );
if (status != STARDUST_OK ) return status ; Also calls: stardust_result_error , stardust_result_release
c 90 B
int64_t stardust_parse (stardust_bytes source , int64_t format , stardust_document ** output ); c 96 B
int64_t stardust_document_error (const stardust_document * doc , stardust_diagnostic_view * output );
expression_text holds these bytes:
text 278 B
// One expression built once and evaluated against several inputs. The
// evaluate examples load this file, build `expression`, evaluate it with each
// of `inputs` in order and compare each result with `expected`.
expression [+ ?x 1]
inputs [{x 1} {x 41}]
expected [2 42] c 186 B
stardust_document * result = NULL ;
int64_t status = stardust_parse (expression_text , STARDUST_DUST , & result );
if (status != STARDUST_OK ) {stardust_document_release (result ); return status ; } Result / 293 B
{
// One expression built once and evaluated against several inputs. The
// evaluate examples load this file, build `expression`, evaluate it with each
// of `inputs` in order and compare each result with `expected`.
expression [+ ?x 1]
inputs [{x 1} {x 41}]
expected [2 42]}
malformed_text holds these bytes:
text 1 B
] c 187 B
stardust_document * failed = NULL ;
int64_t status = stardust_parse (malformed_text , STARDUST_DUST , & failed );
stardust_diagnostic_view result = {0 };
stardust_document_error (failed , & result ); Result / 175 B
{violations null
code invalid_dust
message Invalid_Syntax at offset 0
path null
field null
entity null
offset 0
status invalid_argument}
malformed_text holds these bytes:
text 1 B
[ c 187 B
stardust_document * failed = NULL ;
int64_t status = stardust_parse (malformed_text , STARDUST_DUST , & failed );
stardust_diagnostic_view result = {0 };
stardust_document_error (failed , & result ); Result / 175 B
{violations null
code invalid_dust
message Unexpected_End at offset 2
path null
field null
entity null
offset 2
status invalid_argument}
Also calls: stardust_document_error
c 76 B
int64_t stardust_document_root (const stardust_document * doc , int64_t * node );
input_text holds this document:
dust 5 B
x 41
c 295 B
stardust_document * source = NULL ;
int64_t root = 0 ;
int64_t status = stardust_parse (input_text , STARDUST_DUST , & source );
if (status == STARDUST_OK ) status = stardust_document_root (source , & root );
stardust_document_release (source );
if (status != STARDUST_OK ) return status ;
int64_t result = root ; Result / 1 B
0
c 78 B
int64_t stardust_document_count (const stardust_document * doc , int64_t * count );
input_text holds this document:
dust 5 B
x 41
c 277 B
stardust_document * source = NULL ;
int64_t result = 0 ;
int64_t status = stardust_parse (input_text , STARDUST_DUST , & source );
if (status == STARDUST_OK ) status = stardust_document_count (source , & result );
stardust_document_release (source );
if (status != STARDUST_OK ) return status ; Result / 1 B
2
Call stardust_document_read_many with capacity 1.
Also calls: stardust_document_read_many
c 145 B
int64_t stardust_document_read_many (const stardust_document * doc , int64_t start , int64_t capacity , stardust_node_view * output , int64_t * written );
input_text holds this document:
dust 5 B
x 41
c 525 B
stardust_document * source = NULL ;
int64_t root = 0 ;
stardust_node_view view = {0 };
int64_t written = 0 ;
int64_t status = stardust_parse (input_text , STARDUST_DUST , & source );
if (status == STARDUST_OK ) status = stardust_document_root (source , & root );
if (status == STARDUST_OK ) status = stardust_document_read_many (source , root , 1 , & view , & written );
stardust_document_release (source );
if (status != STARDUST_OK ) return status ;
stardust_node_view result = view ; Result / 145 B
{kind object
boolean false
parent null
position 0
first_child 1
next_sibling null
key ""
text ""}
input_text holds this document:
dust 5 B
x 41
c 525 B
stardust_document * source = NULL ;
int64_t root = 0 ;
stardust_node_view view = {0 };
int64_t written = 0 ;
int64_t status = stardust_parse (input_text , STARDUST_DUST , & source );
if (status == STARDUST_OK ) status = stardust_document_root (source , & root );
if (status == STARDUST_OK ) status = stardust_document_read_many (source , root , 1 , & view , & written );
stardust_document_release (source );
if (status != STARDUST_OK ) return status ;
stardust_node_view result = view ; Result / 145 B
{kind object
boolean false
parent null
position 0
first_child 1
next_sibling null
key ""
text ""}
c 115 B
int64_t stardust_document_member (const stardust_document * doc , int64_t object , stardust_bytes name , int64_t * node );
input_text holds this document:
dust 5 B
x 41
c 431 B
stardust_document * source = NULL ;
int64_t root = 0 , node = 0 ;
int64_t status = stardust_parse (input_text , STARDUST_DUST , & source );
if (status == STARDUST_OK ) status = stardust_document_root (source , & root );
if (status == STARDUST_OK ) status = stardust_document_member (source , root , (stardust_bytes ){(const uint8_t * )"x" , 1 }, & node );
stardust_document_release (source );
if (status != STARDUST_OK ) return status ;
int64_t result = node ; Result / 1 B
1
c 144 B
int64_t stardust_document_pointer (const stardust_document * doc , int64_t start , const stardust_document * path , int64_t path_node , int64_t * node ); c 120 B
int64_t stardust_document_pointer_text (const stardust_document * doc , int64_t start , stardust_bytes text , int64_t * node ); c 77 B
int64_t stardust_document_builder_create (stardust_document_builder ** output ); c 128 B
int64_t stardust_document_builder_add_many (stardust_document_builder * builder , const stardust_node_input * nodes , int64_t count ); c 103 B
int64_t stardust_document_builder_seal (stardust_document_builder * builder , stardust_document ** output ); c 75 B
void stardust_document_builder_release (stardust_document_builder * builder ); c 55 B
void stardust_document_release (stardust_document * doc );
A miss is not a failure: a missing key, an index past the end, a string token such as - on an array, or a step into a scalar. An integer token on an object selects the member named by its decimal text. Duplicate keys select the first member, as member does. A malformed path fails even after a step that misses.
expression_text holds these bytes:
text 278 B
// One expression built once and evaluated against several inputs. The
// evaluate examples load this file, build `expression`, evaluate it with each
// of `inputs` in order and compare each result with `expected`.
expression [+ ?x 1]
inputs [{x 1} {x 41}]
expected [2 42] c 481 B
stardust_document * source = NULL ;
int64_t root = 0 , node = STARDUST_DOCUMENT_NO_NODE ;
int64_t status = stardust_parse (expression_text , STARDUST_DUST , & source );
if (status == STARDUST_OK ) status = stardust_document_root (source , & root );
if (status == STARDUST_OK )
status = stardust_document_pointer_text (source , root , (stardust_bytes ){(const uint8_t * )"/inputs/1/x" , 11 }, & node );
stardust_document_release (source );
if (status != STARDUST_OK ) return status ;
int64_t result = node ; Result / 1 B
9
Also calls: stardust_document_pointer_text , stardust_document_builder_create , stardust_document_builder_add_many , stardust_document_builder_seal , stardust_document_builder_release , stardust_document_release
c 80 B
int64_t stardust_pointer_parse (stardust_bytes text , stardust_document ** output ); c 96 B
int64_t stardust_document_error (const stardust_document * doc , stardust_diagnostic_view * output ); c 145 B
int64_t stardust_document_read_many (const stardust_document * doc , int64_t start , int64_t capacity , stardust_node_view * output , int64_t * written ); c 91 B
int64_t stardust_document_i64 (const stardust_document * doc , int64_t node , int64_t * output ); c 55 B
void stardust_document_release (stardust_document * doc );
The empty text is the root path []. ~1 decodes to / and ~0 to ~. A canonical array index token becomes an integer, including a key such as 2024; every other token stays a string, such as 01 or -. No target document is needed.
c 226 B
stardust_document * result = NULL ;
int64_t status = stardust_pointer_parse ((stardust_bytes ){(const uint8_t * )"/inputs/1/x" , 11 }, & result );
if (status != STARDUST_OK ) {
stardust_document_release (result );
return status ;
} Result / 12 B
[inputs 1 x]
Also calls: stardust_document_error , stardust_document_read_many , stardust_document_i64 , stardust_document_release
c 101 B
int64_t stardust_pointer_format (const stardust_document * path , int64_t node , stardust_text ** output ); c 77 B
int64_t stardust_document_builder_create (stardust_document_builder ** output ); c 128 B
int64_t stardust_document_builder_add_many (stardust_document_builder * builder , const stardust_node_input * nodes , int64_t count ); c 103 B
int64_t stardust_document_builder_seal (stardust_document_builder * builder , stardust_document ** output ); c 75 B
void stardust_document_builder_release (stardust_document_builder * builder ); c 55 B
void stardust_document_release (stardust_document * doc ); c 63 B
stardust_bytes stardust_text_data (const stardust_text * result ); c 91 B
int64_t stardust_text_error (const stardust_text * result , stardust_diagnostic_view * output ); c 50 B
void stardust_text_release (stardust_text * result );
The root path [] formats as empty text. / encodes as ~1 and ~ as ~0. pointer.parse of the result returns the same path.
c 350 B
stardust_document * path = NULL ;
stardust_text * result = NULL ;
int64_t status = stardust_pointer_parse ((stardust_bytes ){(const uint8_t * )"/inputs/1/x" , 11 }, & path );
if (status == STARDUST_OK ) status = stardust_pointer_format (path , 0 , & result );
stardust_document_release (path );
if (status != STARDUST_OK ) {stardust_text_release (result ); return status ; } Result / 18 B
{text /inputs/1/x}
Also calls: stardust_document_builder_create , stardust_document_builder_add_many , stardust_document_builder_seal , stardust_document_builder_release , stardust_document_release , stardust_text_data , stardust_text_error , stardust_text_release
Read the first child, then follow next_sibling with stardust_document_read_many.
Also calls: stardust_document_read_many
Follow the children of an object node; each node view carries its key.
Also calls: stardust_document_read_many
c 91 B
int64_t stardust_document_i64 (const stardust_document * doc , int64_t node , int64_t * output );
input_text holds this document:
dust 5 B
x 41
c 510 B
stardust_document * source = NULL ;
int64_t root = 0 , node = 0 ;
int64_t result = 0 ;
int64_t status = stardust_parse (input_text , STARDUST_DUST , & source );
if (status == STARDUST_OK ) status = stardust_document_root (source , & root );
if (status == STARDUST_OK ) status = stardust_document_member (source , root , (stardust_bytes ){(const uint8_t * )"x" , 1 }, & node );
if (status == STARDUST_OK ) status = stardust_document_i64 (source , node , & result );
stardust_document_release (source );
if (status != STARDUST_OK ) return status ; Result / 2 B
41
c 90 B
int64_t stardust_document_f64 (const stardust_document * doc , int64_t node , double * output );
Integer conversion can round values outside the exact f64 integer range.
number_text holds this document:
dust 4 B
1.0
c 374 B
stardust_document * source = NULL ;
int64_t root = 0 ;
double result = 0 ;
int64_t status = stardust_parse (number_text , STARDUST_DUST , & source );
if (status == STARDUST_OK ) status = stardust_document_root (source , & root );
if (status == STARDUST_OK ) status = stardust_document_f64 (source , root , & result );
stardust_document_release (source );
if (status != STARDUST_OK ) return status ; Result / 3 B
1.0
c 55 B
void stardust_document_release (stardust_document * doc ); Consumes the receiver handle.
expression_text holds this document:
dust 9 B
[ + ?x 1 ]
c 338 B
stardust_document * source = NULL ;
stardust_text * result = NULL ;
int64_t status = stardust_parse (expression_text , STARDUST_DUST , & source );
if (status == STARDUST_OK ) status = stardust_serialize (source , STARDUST_DUST , 0 , & result );
stardust_document_release (source );
if (status != STARDUST_OK ) {stardust_text_release (result ); return status ; } Result / 33 B
{
text '''
[+ ?x 1]
'''
}
This record contains the result of read and read_many. The key and text fields borrow the document until it closes.
This record supplies a node for add and add_many. The number field holds a typed i64 or f64 value. Go uses I64/F64, Rust and Odin use Number, Clojure uses long or double, and Python uses int or float. This value sets the ABI number kind and the integer or real field.