1.0.9 • Published 12 months ago
nvyson v1.0.9
nvyson
- a simple json-like format
- nvlang use this structure to transfer shape+symbol
- its a little complicated than nvzson
- for test compile-cli-tool of nvlang, normally USELESS
valid chars:
LBC : {
RBC : }
LBK : [
RBK : ]
symbol : [a-z][a-z0-9]* AND "@"
can NOT begin with <digit>
"@" IS a place-holder
ws : all others are treated-as white-space // so caps-lock A-Z OR chinese-characters could be used AS comments
example:
#0 { k0 k1 k2 [@ {k4 k5} @] k6 k7 }
when parse-to-json IN js:
#0 will become :
{ // implicit _0
k0:1, // implicit _1
k1:2, // implicit _2
k2:3, // implicit _3
_4:[ // explicit _4 is auto generated for array-element
5, // implicit _5
{ // explicit _6
k4:7, // implicit _7
k5:8 // implicit _8
}, // </_6>
9 // implicit _9
], // </_4>
k6:10, // implicit _10
k7:11, // implicit _11
} // </_0>
AND a array of size 12(nodes count of the shape)
// _0 k0 k1 k2 _4 _5 _6 k4 k5 _9 k6 k7
["D", null,null,null, "A", null, "D", null,null,null,null,null]
in nvlang:
#0 will become a struct definition :
struct YourShapeName { //implicit _0
void* k0; //implicit _1
void* k1; //implicit _2
void* k2; //implicit _3
struct { //explicit _4
void* _5; //implicit _5
struct { //explicit _6
void* k4; //implicit _7
void* k5; //implicit _8
} //_6;
void* _9; //implicit _9
} // _4;
void* k6; //implicit _10
void* k7; //implicit _11
};
// void* can ALSO be uint64_t
AND a std::array<anything-length-is-8byte 16:48>
// _0 k0 k1 k2 _4 _5 _6 k4 k5 _9 k6 k7
["D", null,null,null, "A", null, "D", null,null,null,null,null]
// the highbit-16 save the type-meta-info
// the lowbit-48 save a ptr OR inplace-small-string(byte-length<=6) OR uint48_t
nvlang USE this-simple-data-structure to transfer stack-allocated-object
#1 your can also write AS {@@@[@{@@}@]@@} IF you dont care key-name
## in this secarino, it is same as nvzson
{ // explicit _0
_1:1, // explicit _1
_2:2, // explicit _2
_3:3, // explicit _3
_4:[ // explicit _4
5, // explicit _5
{ // explicit _6
_7:7, // explicit _7
_8:8 // explicit _8
}, // </_6>
9 // explicit _9
], // </_4>
_10:10, // explicit _10
_11:11, // explicit _11
}
IF using array-only such as [@@@ [@ [@@] @] @@] , suggested for transfer
refer to nvvson
install
- npm install nvyson
usage
const {ser,der} = require("nvyson");
example
serialize from json
const {
ser_from_json_without_check,
_ser_from_json
} = require("nvyson").ser;
var J = { //0
a:<any>, //1
b:[ //2
{ //3
a:<any> //4
},
<any>,
<any>,
<any>,
<any>,
<any>,
],
c:<any>,
d:<any>,
e:<any>
}
console.log(ser_from_json_without_check(J))
/*{a b [{a }@ @ @ @ @ ]c d e }*/
parse from str
const {der} = require("nvyson").der;
var s = "{aa b kkk [{a}@@@@@{o p q r}]c d e [@]}"
console.dir(der(s),{depth:null})
/*
Scheme {
shape: {
aa: 1,
b: 2,
kkk: 3,
_4: [ { a: 6 }, 7, 8, 9, 10, 11, { o: 13, p: 14, q: 15, r: 16 } ],
c: 17,
d: 18,
e: 19,
_20: [ 21 ]
},
data: [...],
depths: [...],
ks: [,,,],
is_fcs: [...],
is_lcs: [...],
sedfs: [...],
sibseqs: [...],
sib_cnts: [...]
}
*/
to ccode template
var s = "{aa b kkk [{a}@@@@@{o p q r}]c d e [@]}"
const {struct,array,all} = require("nvyson").s2c;
console.log(struct(s))
/*
struct DShape {
uint64_t aa; // nest-dict-index: .aa offsets: sizeof(uint64_t) * 0 flat-nid: #1
uint64_t b; // nest-dict-index: .b offsets: sizeof(uint64_t) * 1 flat-nid: #2
uint64_t kkk; // nest-dict-index: .kkk offsets: sizeof(uint64_t) * 2 flat-nid: #3
struct { // nest-dict-index: ._4 offsets: sizeof(uint64_t) * 3 flat-nid: #4
struct { // nest-dict-index: ._4._0 offsets: sizeof(uint64_t) * 3 flat-nid: #5
uint64_t a; // nest-dict-index: ._4._0.a offsets: sizeof(uint64_t) * 3 flat-nid: #6
} _0;
uint64_t _1; // nest-dict-index: ._4._1 offsets: sizeof(uint64_t) * 4 flat-nid: #7
uint64_t _2; // nest-dict-index: ._4._2 offsets: sizeof(uint64_t) * 5 flat-nid: #8
uint64_t _3; // nest-dict-index: ._4._3 offsets: sizeof(uint64_t) * 6 flat-nid: #9
uint64_t _4; // nest-dict-index: ._4._4 offsets: sizeof(uint64_t) * 7 flat-nid: #10
uint64_t _5; // nest-dict-index: ._4._5 offsets: sizeof(uint64_t) * 8 flat-nid: #11
struct { // nest-dict-index: ._4._6 offsets: sizeof(uint64_t) * 9 flat-nid: #12
uint64_t o; // nest-dict-index: ._4._6.o offsets: sizeof(uint64_t) * 9 flat-nid: #13
uint64_t p; // nest-dict-index: ._4._6.p offsets: sizeof(uint64_t) * 10 flat-nid: #14
uint64_t q; // nest-dict-index: ._4._6.q offsets: sizeof(uint64_t) * 11 flat-nid: #15
uint64_t r; // nest-dict-index: ._4._6.r offsets: sizeof(uint64_t) * 12 flat-nid: #16
} _6;
} _4;
uint64_t c; // nest-dict-index: .c offsets: sizeof(uint64_t) * 13 flat-nid: #17
uint64_t d; // nest-dict-index: .d offsets: sizeof(uint64_t) * 14 flat-nid: #18
uint64_t e; // nest-dict-index: .e offsets: sizeof(uint64_t) * 15 flat-nid: #19
struct { // nest-dict-index: ._20 offsets: sizeof(uint64_t) * 16 flat-nid: #20
uint64_t _0; // nest-dict-index: ._20._0 offsets: sizeof(uint64_t) * 16 flat-nid: #21
} _20;
};
*/
console.log(array(s))
// The libc++ tuple implementation has the opposite layout.
// so std::get<0>(AShape) IS Dshape'_20
// plget<4,0,2>(AShape) IS Dshape'_4._6._p
/*
using AShape = std::tuple<
std::tuple< // nest-array-index: <0 > offset: sizeof(uint64_t) * 0 flat-nid: #20
uint64_t // nest-array-index: <0,0 > offset: sizeof(uint64_t) * 0 flat-nid: #21
>,
uint64_t, // nest-array-index: <1 > offset: sizeof(uint64_t) * 1 flat-nid: #19
uint64_t, // nest-array-index: <2 > offset: sizeof(uint64_t) * 2 flat-nid: #18
uint64_t, // nest-array-index: <3 > offset: sizeof(uint64_t) * 3 flat-nid: #17
std::tuple< // nest-array-index: <4 > offset: sizeof(uint64_t) * 4 flat-nid: #4
std::tuple< // nest-array-index: <4,0 > offset: sizeof(uint64_t) * 4 flat-nid: #12
uint64_t, // nest-array-index: <4,0,0> offset: sizeof(uint64_t) * 4 flat-nid: #16
uint64_t, // nest-array-index: <4,0,1> offset: sizeof(uint64_t) * 5 flat-nid: #15
uint64_t, // nest-array-index: <4,0,2> offset: sizeof(uint64_t) * 6 flat-nid: #14
uint64_t // nest-array-index: <4,0,3> offset: sizeof(uint64_t) * 7 flat-nid: #13
>,
uint64_t, // nest-array-index: <4,1 > offset: sizeof(uint64_t) * 8 flat-nid: #11
uint64_t, // nest-array-index: <4,2 > offset: sizeof(uint64_t) * 9 flat-nid: #10
uint64_t, // nest-array-index: <4,3 > offset: sizeof(uint64_t) * 10 flat-nid: #9
uint64_t, // nest-array-index: <4,4 > offset: sizeof(uint64_t) * 11 flat-nid: #8
uint64_t, // nest-array-index: <4,5 > offset: sizeof(uint64_t) * 12 flat-nid: #7
std::tuple< // nest-array-index: <4,6 > offset: sizeof(uint64_t) * 13 flat-nid: #5
uint64_t // nest-array-index: <4,6,0> offset: sizeof(uint64_t) * 13 flat-nid: #6
>
>,
uint64_t, // nest-array-index: <5 > offset: sizeof(uint64_t) * 14 flat-nid: #3
uint64_t, // nest-array-index: <6 > offset: sizeof(uint64_t) * 15 flat-nid: #2
uint64_t // nest-array-index: <7 > offset: sizeof(uint64_t) * 16 flat-nid: #1
>;
*/
console.log(all(s))
{
mirr: {
aa: '<7>',
'<7>': 'aa',
b: '<6>',
'<6>': 'b',
kkk: '<5>',
'<5>': 'kkk',
_4: '<4>',
'<4>': '_4',
'_4._0': '<4,6>',
'<4,6>': '_4._0',
'_4._0.a': '<4,6,0>',
'<4,6,0>': '_4._0.a',
'_4._1': '<4,5>',
'<4,5>': '_4._1',
'_4._2': '<4,4>',
'<4,4>': '_4._2',
'_4._3': '<4,3>',
'<4,3>': '_4._3',
'_4._4': '<4,2>',
'<4,2>': '_4._4',
'_4._5': '<4,1>',
'<4,1>': '_4._5',
'_4._6': '<4,0>',
'<4,0>': '_4._6',
'_4._6.o': '<4,0,3>',
'<4,0,3>': '_4._6.o',
'_4._6.p': '<4,0,2>',
'<4,0,2>': '_4._6.p',
'_4._6.q': '<4,0,1>',
'<4,0,1>': '_4._6.q',
'_4._6.r': '<4,0,0>',
'<4,0,0>': '_4._6.r',
c: '<3>',
'<3>': 'c',
d: '<2>',
'<2>': 'd',
e: '<1>',
'<1>': 'e',
_20: '<0>',
'<0>': '_20',
'_20._0': '<0,0>',
'<0,0>': '_20._0'
},
dshape: 【...struct(s)】,
ashape: 【...array(s)】,
nmap: 【std::map<std::string,std::string> ShapeNMAP {...}】,
util: 【
template <int idx, int... idxes> auto& plget(auto& maybe_nest) {...};
template <int idx, int... idxes> auto& plset(auto& maybe_nest,auto v) {...};
using Shape = std::variant<DShape,AShape>;
】
}
METHODS
APIS
LICENSE
- ISC