Project

Profile

Help

Bug #5292 ยป repro2.xq

Gunther Rademacher, 2022-02-07 16:37

 
declare function local:join($done, $current, $todo)
{
if (empty($todo)) then
string-join(($done, $current), "
")
else
let $item := $todo[1]
let $todo := $todo[position() > 1]
return
typeswitch ($item)
case element(tab) return
local:join(($done, $current), (), $todo)
case processing-instruction() return
local:join($done, $current, (<tab/>, $todo))
default return
local:join($done, string-join(($current, $item)), $todo)
};

let $rendered := <root><tab col="1"/><fragment><name>json</name></fragment><tab col="9"/>::=<name>value</name><name>eof</name><tab col="1"/><fragment><name>object</name></fragment><tab col="9"/>::= '{{'(<name>pair</name>(','<name>pair</name><fragment>)*</fragment><fragment>)?</fragment>'}}'<tab col="1"/><fragment><name>pair</name></fragment><tab col="9"/>::=<name>string</name>':'<name>value</name><tab col="1"/><fragment><name>array</name></fragment><tab col="9"/>::= '['(<name>value</name>(','<name>value</name><fragment>)*</fragment><fragment>)?</fragment>']'<tab col="1"/><fragment><name>value</name></fragment><tab col="9"/>::=<name>string</name><tab col="11"/>|<name>number</name><tab col="11"/>|<name>object</name><tab col="11"/>|<name>array</name><tab col="11"/>| 'true'<tab col="11"/>| 'false'<tab col="11"/>| 'null'<tab col="1"/><fragment><name>ws</name></fragment><tab col="9"/>::=<name>whitespace^token</name><tab col="10"/>/* ws: definition */<?TOKENS?><tab col="1"/><fragment><name>eof</name></fragment><tab col="9"/>::= $<tab col="1"/><fragment><name>string</name></fragment><tab col="9"/>::= '"' (<name>anyUnicodeCharacterExceptQuoteOrBackslashOrControlCharacter</name>| '\"' | '\\' | '\/' | '\b' | '\f' | '\n' | '\r' | '\t' | '\u'<name>fourHexadecimalDigits</name><fragment>)*</fragment>'"'<tab col="1"/><fragment><name>anyUnicodeCharacterExceptQuoteOrBackslashOrControlCharacter</name></fragment><tab col="9"/>::=<name>alphabet</name>- ["#x005C]<tab col="1"/><fragment><name>alphabet</name></fragment><tab col="9"/>::= #x0009<tab col="11"/>| #x000A<tab col="11"/>| #x000D<tab col="11"/>| [#x0020-#xD7FF]<tab col="11"/>| [#xE000-#xFFFD]<tab col="11"/>| [#x10000-#x10FFFF]<tab col="1"/><fragment><name>hexadecimalDigit</name></fragment><tab col="9"/>::= [0-9A-Fa-f]<tab col="1"/><fragment><name>fourHexadecimalDigits</name></fragment><tab col="9"/>::=<name>hexadecimalDigit</name><name>hexadecimalDigit</name><name>hexadecimalDigit</name><name>hexadecimalDigit</name><tab col="1"/><fragment><name>number</name></fragment><tab col="9"/>::=<fragment>'-'?</fragment>( '0' |<name>digitOneThroughNine</name><fragment><name>digit</name>*</fragment>)('.'<fragment><name>digit</name>+</fragment><fragment>)?</fragment>(( 'e' | 'E' ) ( '+' | '-'<fragment>)?</fragment><fragment><name>digit</name>+</fragment><fragment>)?</fragment><tab col="1"/><fragment><name>digit</name></fragment><tab col="9"/>::= [0-9]<tab col="1"/><fragment><name>digitOneThroughNine</name></fragment><tab col="9"/>::=<name>digit</name>- '0'<tab col="1"/><fragment><name>whitespace</name></fragment><tab col="9"/>::=<fragment>[#x0009#x000A#x000D#x0020]+</fragment></root>
return local:join((), (), $rendered/node())
    (1-1/1)