You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{ k0:v0, key : "val-\t-.... -> {k0:v0}
if you want the lefted parted for continue, use
require("nvison-parse-internal")
D {
....
lefted: {
type: 3,
data: { rslt: 'val-\t-....\n\n\n', lefted: '', state: 3, quote: '"' }
},
....
}
comments
two kind : line-comment(//....\n) and block-comment(/...../)
four position supported: @after_key, @before_val(properties), @after_val, @before_val(elements)
valid and invalid comment
// VALID
{
.....
/*text-node-comment*/
key /*key-comment*/ : /* before-val-comment*/ value /*after-val-comment*/ ,
/*text-node-comment*/
key1 : value1,
/*text-node-comment*/
.....
}
[
.....
/*text-node-comment*/
element0 /*after-val-comment*/ ,
/*text-node-comment*/
....
]
//VALID
//INVALID
[ abc/*in-value-comment-not-supported*/def, ....]
it will be treated as [ abc, def ....]
{ kkkk/*in-key-comment-not-supported*/ey : value, ...}
it will be treadted as { ey:value,....} ,
the pre-part of kkkkey(kkkk) will be dropped
//INVALID
hash can add more-than-one "key" to a value, for reference
ref will search along the "scope" chain, recursively
ref can NOT ref "behind" to right-sibling and children and descendants
coz ison originally is used for streaming parse, it did NOT known what will come
hash and ref performance is BAD when the ison-file is too Big,such as 4M+
valid and invalid
//valid
{ #root
key0: {k0:v0, k1:&root} //ref to ancestor
key1: value1,
key2: &key0 //ref to preceding-sibling
} //will be {key0: {k0:v0,k1:<Circular>}, key1:value1,key2:{k0:v0,k1:<Circular>}}
{
....
key0 : value0 #hash-after-val ,
key1 : &hash-after-val
....
} // will be {key0:value0, key1:value0}
/* very very long string */ #comment
[ &comment, &comment ,&comment] //valid to ref to text-node-position-comment
//invalid
{
key0 #hash-after-key-will-be-treated-as-comment : value0
}
{
key0 : #hash-before-value-will-be-treated-as-comment value0
}
{
key0: &fsib, //ref to following-sibling have no effect
key1: value1,
key2: value2 #fsib,
key3: {
k30:&des, //ref to descendant have no effect
k31: [
des0,
des1,
des2 #des
]
}
}
{
k : /*before_val*/ #hash v //hash between colon and value have no effect
}
example 1
var code = `
{
arr: [1,2,3,4] #ary0 ,
x: &ary0 ,
y: {
k0:abcdefghijklmnopqrstuvwxyz,
k1:&ary0,
k2:&x, //ref to x, it will be reursively point to [1,2,3,4]
k3:&k0, //along the scope(ArrayBlock or ObjectBlock), it will be point to abcdefghijklmnopqrstuvwxyz
k4:&0 //if the ref is a number, it will be the sibling-position, it will be point to abcdefghijklmnopqrstuvwxyz
}
}
`
var j = ison.parse_from_str(code,{enable_ref:true})
/*
{
arr: [ 1, 2, 3, 4 ],
x: [ 1, 2, 3, 4 ],
y: {
k0: 'abcdefghijklmnopqrstuvwxyz',
k1: [ 1, 2, 3, 4 ],
k2: [ 1, 2, 3, 4 ],
k3: 'abcdefghijklmnopqrstuvwxyz',
k4: 'abcdefghijklmnopqrstuvwxyz'
}
}
*/
> j.x === j.arr
true
> j.y.k1 === j.arr
true
> j.y.k2 === j.arr
true
>
example 2
var code = `
//use hash '#' to set a alias for ref
"https://127.0.0.1/img.jpg" #jpg
"https://127.0.0.1/img.png" #png
//multi-hash permitted : the below has two hash
\`this is a very long
very long string
...string\` #long-string #so-long
[
// different hashes point to the same value
&long-string;
&so-long;
/*html-like, use ref '&' to get-value-of value-with-hash */
{
div@1: {
attribs:{style={}}
} #div ,
div@2: &div,
div@3: &div,
div@4: &div,
img@1: &jpg,
img@2: &png,
} #body;
/*repeat the body*/
&body;
] #html
`
var j = ison.parse_from_str(code,{enable_ref:true})
/*
> j
[
'https://127.0.0.1/img.jpg',
'https://127.0.0.1/img.png',
'this is a very long\n very long string\n ...string',
[
'this is a very long\n very long string\n ...string',
'this is a very long\n very long string\n ...string',
{
'div@1': [Object],
'div@2': [Object],
'div@3': [Object],
'div@4': [Object],
'img@1': 'https://127.0.0.1/img.jpg',
'img@2': 'https://127.0.0.1/img.png'
},
{
'div@1': [Object],
'div@2': [Object],
'div@3': [Object],
'div@4': [Object],
'img@1': 'https://127.0.0.1/img.jpg',
'img@2': 'https://127.0.0.1/img.png'
}
]
]
>
*/
console.log(JSON.stringify(j,null,2))
/*
[
"https://127.0.0.1/img.jpg",
"https://127.0.0.1/img.png",
"this is a very long\n very long string\n ...string",
[
"this is a very long\n very long string\n ...string",
"this is a very long\n very long string\n ...string",
{
"div@1": {
"attribs": {
"style": {}
}
},
"div@2": {
"attribs": {
"style": {}
}
},
"div@3": {
"attribs": {
"style": {}
}
},
"div@4": {
"attribs": {
"style": {}
}
},
"img@1": "https://127.0.0.1/img.jpg",
"img@2": "https://127.0.0.1/img.png"
},
{
"div@1": {
"attribs": {
"style": {}
}
},
"div@2": {
"attribs": {
"style": {}
}
},
"div@3": {
"attribs": {
"style": {}
}
},
"div@4": {
"attribs": {
"style": {}
}
},
"img@1": "https://127.0.0.1/img.jpg",
"img@2": "https://127.0.0.1/img.png"
}
]
]
*/