|
declare function local:join($done, $todo)
|
|
{
|
|
if (empty($todo)) then
|
|
string-join($done, "
")
|
|
else
|
|
let $item := $todo[1]
|
|
let $todo := $todo[position() > 1]
|
|
let $last := $done[last()]
|
|
return
|
|
typeswitch ($item)
|
|
case element(tab) return
|
|
let $tab := xs:integer($item/@col) - 1
|
|
let $n := $tab - string-length($last)
|
|
return
|
|
if ($n >= 0) then
|
|
let $spaces := string-join((1 to $n)!" ")
|
|
return local:join(($done[position() < last()], concat($last, $spaces)), $todo)
|
|
else
|
|
let $spaces := string-join((1 to $tab)!" ")
|
|
return local:join(($done, $spaces), $todo)
|
|
default return
|
|
local:join
|
|
(
|
|
(
|
|
$done[position() < last()],
|
|
if ($last = "") then
|
|
string($item)
|
|
else
|
|
(: result will be correct when replacing '$done[last()]' :)
|
|
(: in the following line by '$last' :)
|
|
string-join(($done[last()], string($item)), " ")
|
|
),
|
|
$todo
|
|
)
|
|
};
|
|
|
|
let $fragments :=
|
|
(
|
|
<tab col="1"/>,
|
|
<fragment>json</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::=</fragment>,
|
|
<fragment>value</fragment>,
|
|
<fragment>eof</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>object</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::= '{{'(</fragment>,
|
|
<fragment>pair</fragment>,
|
|
<fragment>(','</fragment>,
|
|
<fragment>pair</fragment>,
|
|
<fragment>)*</fragment>,
|
|
<fragment>)?</fragment>,
|
|
<fragment>'}}'</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>pair</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::=</fragment>,
|
|
<fragment>string</fragment>,
|
|
<fragment>':'</fragment>,
|
|
<fragment>value</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>array</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::= '['(</fragment>,
|
|
<fragment>value</fragment>,
|
|
<fragment>(','</fragment>,
|
|
<fragment>value</fragment>,
|
|
<fragment>)*</fragment>,
|
|
<fragment>)?</fragment>,
|
|
<fragment>']'</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>value</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::=</fragment>,
|
|
<fragment>string</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>|</fragment>,
|
|
<fragment>number</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>|</fragment>,
|
|
<fragment>object</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>|</fragment>,
|
|
<fragment>array</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>| 'true'</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>| 'false'</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>| 'null'</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>ws</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::=</fragment>,
|
|
<fragment>whitespace^token</fragment>,
|
|
<tab col="10"/>,
|
|
<fragment>/* ws: definition */</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>eof</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::= $</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>string</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::= '"' (</fragment>,
|
|
<fragment>anyUnicodeCharacterExceptQuoteOrBackslashOrControlCharacter</fragment>,
|
|
<fragment>| '\"' | '\\' | '\/' | '\b' | '\f' | '\n' | '\r' | '\t' | '\u'</fragment>,
|
|
<fragment>fourHexadecimalDigits</fragment>,
|
|
<fragment>)*</fragment>,
|
|
<fragment>'"'</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>anyUnicodeCharacterExceptQuoteOrBackslashOrControlCharacter</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::=</fragment>,
|
|
<fragment>alphabet</fragment>,
|
|
<fragment>- ["#x005C]</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>alphabet</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::= #x0009</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>| #x000A</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>| #x000D</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>| [#x0020-#xD7FF]</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>| [#xE000-#xFFFD]</fragment>,
|
|
<tab col="11"/>,
|
|
<fragment>| [#x10000-#x10FFFF]</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>hexadecimalDigit</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::= [0-9A-Fa-f]</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>fourHexadecimalDigits</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::=</fragment>,
|
|
<fragment>hexadecimalDigit</fragment>,
|
|
<fragment>hexadecimalDigit</fragment>,
|
|
<fragment>hexadecimalDigit</fragment>,
|
|
<fragment>hexadecimalDigit</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>number</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::=</fragment>,
|
|
<fragment>'-'?</fragment>,
|
|
<fragment>( '0' |</fragment>,
|
|
<fragment>digitOneThroughNine</fragment>,
|
|
<fragment>digit*</fragment>,
|
|
<fragment>)('.'</fragment>,
|
|
<fragment>digit+</fragment>,
|
|
<fragment>)?</fragment>,
|
|
<fragment>(( 'e' | 'E' ) ( '+' | '-'</fragment>,
|
|
<fragment>)?</fragment>,
|
|
<fragment>digit+</fragment>,
|
|
<fragment>)?</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>digit</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::= [0-9]</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>digitOneThroughNine</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::=</fragment>,
|
|
<fragment>digit</fragment>,
|
|
<fragment>- '0'</fragment>,
|
|
<tab col="1"/>,
|
|
<fragment>whitespace</fragment>,
|
|
<tab col="9"/>,
|
|
<fragment>::=</fragment>,
|
|
<fragment>[#x0009#x000A#x000D#x0020]+</fragment>
|
|
)
|
|
return local:join((), $fragments)
|