... | ... | @@ -39,11 +39,45 @@ object ::= '{' string : [value {',' value}] '}' |
|
|
value ::= object | array | numeral | string | 'true' | 'false' | 'null'
|
|
|
```
|
|
|
|
|
|
### Validating non-nested JSON
|
|
|
A JSON grammar is given by `JSON ::= value`, meaning that in some instances - `numeral | string | 'true' | 'false' | 'null'` - we do not have nesting. See an example below:
|
|
|
|
|
|
_// string.json_
|
|
|
```
|
|
|
"This is valid JSON"
|
|
|
```
|
|
|
|
|
|
Thus, when we apply NestingDepth kernel to this stream, we get the output:
|
|
|
```
|
|
|
Bracket Stream .....................
|
|
|
Nesting Depth 000000000000000000000
|
|
|
ND BixNum[2] .....................
|
|
|
ND BixNum[1] .....................
|
|
|
ND BixNum[0] .....................
|
|
|
```
|
|
|
|
|
|
Assume that `valueToken` is a bit stream that marks the end position of
|
|
|
any legal JSON numeral, string or keyword, while `anyToken` is a bit stream
|
|
|
marking the end position of any legal or illegal token.
|
|
|
Assume also that `LBrak`, `RBrak`, and `Comma` are streams marking the
|
|
|
position of JSON `[`, `]`, and `,` tokens respectively.
|
|
|
any legal JSON numeral, string or keyword, then the example above would look like:
|
|
|
```
|
|
|
valueToken ...................1.
|
|
|
EOFbit ....................1
|
|
|
```
|
|
|
|
|
|
Then we can validate if we have valid non-nesting values by checking:
|
|
|
|
|
|
```
|
|
|
otherND = bnc.UGT(ND, 0)
|
|
|
mix = otherND | valueToken // if only one bit is set, then we don't have other ND
|
|
|
begin = ~Advance(<1>, 1)
|
|
|
firstValue = ScanTo(begin, mix)
|
|
|
nonNestingValue = Advance(firstValue, 1) & EOFbit
|
|
|
err = EOFBit ^ nonNestingValue
|
|
|
```
|
|
|
|
|
|
|
|
|
### Validating arrays
|
|
|
|
|
|
Assume we have two bit streams for tokens: `valueToken` (explained above) and `anyToken`, a bit stream marking the end position of any legal or illegal token. Assume also that `LBrak`, `RBrak`, and `Comma` are streams marking the position of JSON `[`, `]`, and `,` tokens respectively.
|
|
|
|
|
|
Suppose that a BixNum `ND` has been computed as the nesting depth involving
|
|
|
the left and right delimiter sets consisting of square brackets and braces.
|
... | ... | |