-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.jsn
185 lines (153 loc) · 4.55 KB
/
example.jsn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import import.jsn
import test.jsn
{
// sytax highlights quite nicely in most editors with c or c++ syntax
// allow comments
/*
multi-
line
comments
*/
// tabs and any whitespace allowed
// compatible with json
"json": {
"bool": true,
"int": 1,
"float": 1.0,
"string": "yes",
"array": [1, 2, 3]
},
// compatible with json5
json5: {
unquoted: 'and you can quote me on that',
single_quotes: 'I can use "double quotes" here',
hexadecimal: 0xdecaf,
line_breaks: "Look, Mom! No \
\\n's!",
leading_decimal_point: .8675309, and_trailing: 8675309.,
positive_sign: +1,
trailing_comma: 'in objects', and_in: ['arrays',],
},
// jsn features
jsn: {
// ditch the quotes and commas!
unquoted_string: without_whitespace // cannot contain whitespace or special chars (see str_test)
unquoted: [strings, in, arrays]
binary_literal: 0b10011
bit_shifts: 1<<16 | 1<<8
// mixed newline and commas
object_members_separated_by_newline: {
no_commas: yes
with_new_lines: "if you like"
but: "you can", still: "use them here"
}
arrays_elements_separated_by_newline:[
"no need for commas"
"if you use newlines"
"still", "separate", "using commas", "on the same line"
]
// you can define variables to be re-used
jsn_vars: {
data: "path/to/data"
var_str: "hello"
var_int: 10
}
// evaluate variables with ${} inside quotes..
variable_data_path: "${data}/subdir"
variable_int: "${var_int}"
array_of_vars: ["${data}", "${var_str}"]
// subobjects can be merged and inherited recursively see ** inheritence(jsn)
base: "foo"
sub_object: {
one: "1"
two: "2"
nested_var: "${var_int}" // variable comes from outer scope.
}
// use <windows, mac, linux> in angled brackets to conditionally include or exclude keys
// the platform specific keys will be merged into the base key if one exists
platform: {
base: "exists"
}
// useful for selecting platform specific paths and executables
platform<windows>: {
exe: "path/windows/program.exe"
}
platform<mac>: {
exe: "path/mac/program"
}
}
//** // add object name to inherit inside parenthesis
inheritence(jsn): {
// inheritance adds keys from 'jsn' object
// ..
// duplicated keys are overridden by the derived object
base: "bar"
// inheritance on sub-objects continues recursively
sub_object: {
three: "3"
//..
}
}
// multiple and hierarchical inheritance
objb: { b: "b" }
multiple_inheritence(inheritence, objb): {
// vars can also be shadowed / overriden..
jsn_vars: {
data: "another/path/to/data"
var_int: 22
}
c: "c"
}
xxx: {
// some test cases
empty_object: {}
empty_array: []
array_of_objects:[
{object: 1, other: "value"}
{object: 2, other: "value"}
]
array_with_string_commas:[
"test,2",
"test,3"
]
nested_objects: {
yes: true
and: {
deeper: nesting
}
}
multi_type_arrays: [
1,
[2, 3]
]
array_of_arrays:[
[hello, world]
[goodbye, world]
]
array_of_values:[
+255
0b11111111
0xff
1 << 1
1 << 2 | 1
1 << 2 | 1
.255
]
value: null
array_of_null: [null, null, null]
jsn_vars: {
va: "path/to/data"
vb: "hello"
}
array_of_array_vars: [
["${va}", "${vb}"]
["${vb}", "non var"]
]
multiple_vars: "${va}/${vb}.bin"
q1: "small 'quotes' inside"
q2: 'double "quotes" inside'
q3: "double escaped \"quotes\" inside"
}
//**
str_test: ":[{}]'+.,0b0x" // this tests ignoring special chars inside quotes
}