<div dir="ltr">Dear oXygen Support,<div><br></div><div>I encountered an unexpected error today when applying "Format & Indent" to a valid XQuery file. The error is:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Cannot format the document. Lexical error at line 21, column 33.  Encountered: "]" (93), after : ""</blockquote><div><br></div><div>The XQuery is as follows, and line 21, column 33 corresponds to the nested array constructors [[]] :</div><div><br></div><div>





<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Helvetica"><span class="gmail-s1" style="color:rgb(0,150,200)"><b>xquery version</b></span> <span class="gmail-s2" style="color:rgb(50,50,150)">"3.1"</span><span class="gmail-s3" style="color:rgb(120,120,0)">;</span><br>
<br>
<span class="gmail-s1" style="color:rgb(0,150,200)"><b>declare namespace</b></span> <span class="gmail-s4" style="color:rgb(0,0,230)"><b>array</b></span><span class="gmail-s5" style="color:rgb(200,80,40)">=</span><span class="gmail-s2" style="color:rgb(50,50,150)">"<a href="http://www.w3.org/2005/xpath-functions/array">http://www.w3.org/2005/xpath-functions/array</a>"</span><span class="gmail-s3" style="color:rgb(120,120,0)">;</span><br>
<br>
<span class="gmail-s1" style="color:rgb(0,150,200)"><b>let</b></span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$permArray</b></span> <span class="gmail-s3" style="color:rgb(120,120,0)">:=</span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>function</b></span>(<span class="gmail-s6" style="color:rgb(150,50,150)"><b>$myAr</b></span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>as</b></span> <span class="gmail-s4" style="color:rgb(0,0,230)"><b>array</b></span>(<span class="gmail-s3" style="color:rgb(120,120,0)">*</span>)) <span class="gmail-Apple-converted-space">  </span><br>
{<span class="gmail-Apple-converted-space">  </span><br>
<span class="gmail-Apple-converted-space">  </span><span class="gmail-s1" style="color:rgb(0,150,200)"><b>let</b></span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$extend</b></span> <span class="gmail-s3" style="color:rgb(120,120,0)">:=</span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>function</b></span>(<span class="gmail-s6" style="color:rgb(150,50,150)"><b>$ar</b></span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>as</b></span> <span class="gmail-s4" style="color:rgb(0,0,230)"><b>array</b></span>(<span class="gmail-s3" style="color:rgb(120,120,0)">*</span>)<span class="gmail-s3" style="color:rgb(120,120,0)">,</span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$mem</b></span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>as</b></span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>item</b></span>()<span class="gmail-s3" style="color:rgb(120,120,0)">*</span>) <br>
<span class="gmail-Apple-converted-space">   Â  Â  Â  Â  Â  Â  Â  </span>{<br>
<span class="gmail-Apple-converted-space">   Â  Â  Â  Â  Â  Â  Â  Â  </span><span class="gmail-s1" style="color:rgb(0,150,200)"><b>array</b></span>{ <span class="gmail-Apple-converted-space">  Â  </span><br>
<span class="gmail-Apple-converted-space">  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span><span class="gmail-s4" style="color:rgb(0,0,230)"><b>for</b></span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$i</b></span> <span class="gmail-s4" style="color:rgb(0,0,230)"><b>in</b></span> <span class="gmail-s2" style="color:rgb(50,50,150)">1</span> <span class="gmail-s7" style="color:rgb(0,64,0)"><i>to</i></span> (<span class="gmail-s7" style="color:rgb(0,64,0)"><i>array:size</i></span>(<span class="gmail-s6" style="color:rgb(150,50,150)"><b>$ar</b></span>) <span class="gmail-s3" style="color:rgb(120,120,0)">+</span><span class="gmail-s2" style="color:rgb(50,50,150)">1</span>)<br>
<span class="gmail-Apple-converted-space">  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span><span class="gmail-s4" style="color:rgb(0,0,230)"><b>return</b></span> <span class="gmail-Apple-converted-space">  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span><br>
<span class="gmail-Apple-converted-space">   Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span><span class="gmail-s7" style="color:rgb(0,64,0)"><i>array:insert-before</i></span>(<span class="gmail-s6" style="color:rgb(150,50,150)"><b>$ar</b></span><span class="gmail-s3" style="color:rgb(120,120,0)">,</span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$i</b></span><span class="gmail-s3" style="color:rgb(120,120,0)">,</span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$mem</b></span>)<br>
<span class="gmail-Apple-converted-space">  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span>} <span class="gmail-Apple-converted-space">  </span><br>
<span class="gmail-Apple-converted-space">   Â  Â  Â  Â  Â  Â  Â  </span>}<span class="gmail-s3" style="color:rgb(120,120,0)">,</span><br>
<span class="gmail-Apple-converted-space">  Â  Â  </span><span class="gmail-s6" style="color:rgb(150,50,150)"><b>$extendAllSubArrays</b></span> <span class="gmail-s3" style="color:rgb(120,120,0)">:=</span><span class="gmail-Apple-converted-space">  </span><span class="gmail-s1" style="color:rgb(0,150,200)"><b>function</b></span>(<span class="gmail-s6" style="color:rgb(150,50,150)"><b>$zero</b></span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>as</b></span> <span class="gmail-s4" style="color:rgb(0,0,230)"><b>array</b></span>(<span class="gmail-s3" style="color:rgb(120,120,0)">*</span>)<span class="gmail-s3" style="color:rgb(120,120,0)">,</span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$mem</b></span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>as</b></span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>item</b></span>()<span class="gmail-s3" style="color:rgb(120,120,0)">*</span>)<br>
<span class="gmail-Apple-converted-space">  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span>{<br>
<span class="gmail-Apple-converted-space">  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span><span class="gmail-s7" style="color:rgb(0,64,0)"><i>array:join</i></span>(<br>
<span class="gmail-Apple-converted-space">  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span><span class="gmail-s1" style="color:rgb(0,150,200)"><b>for</b></span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$i</b></span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>in</b></span> <span class="gmail-s2" style="color:rgb(50,50,150)">1</span> <span class="gmail-s1" style="color:rgb(0,150,200)"><b>to</b></span> <span class="gmail-s7" style="color:rgb(0,64,0)"><i>array:size</i></span>(<span class="gmail-s6" style="color:rgb(150,50,150)"><b>$zero</b></span>)<br>
<span class="gmail-Apple-converted-space">   Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span><span class="gmail-s1" style="color:rgb(0,150,200)"><b>return</b></span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$extend</b></span>(<span class="gmail-s6" style="color:rgb(150,50,150)"><b>$zero</b></span>(<span class="gmail-s6" style="color:rgb(150,50,150)"><b>$i</b></span>)<span class="gmail-s3" style="color:rgb(120,120,0)">,</span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$mem</b></span>)<br>
<span class="gmail-Apple-converted-space">   Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span>)<br>
<span class="gmail-Apple-converted-space">   Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span>}<br>
<span class="gmail-Apple-converted-space">   Â  </span><span class="gmail-s1" style="color:rgb(0,150,200)"><b>return</b></span><br>
<span class="gmail-Apple-converted-space">   Â  Â  </span><span class="gmail-s7" style="color:rgb(0,64,0)"><i>array:fold-left</i></span>(<span class="gmail-s6" style="color:rgb(150,50,150)"><b>$myAr</b></span><span class="gmail-s3" style="color:rgb(120,120,0)">,</span> [[]]<span class="gmail-s3" style="color:rgb(120,120,0)">,</span><span class="gmail-Apple-converted-space">  </span><span class="gmail-s6" style="color:rgb(150,50,150)"><b>$extendAllSubArrays</b></span>)<span class="gmail-Apple-converted-space">  </span><br>
}<br>
<span class="gmail-s1" style="color:rgb(0,150,200)"><b>return</b></span> <span class="gmail-s6" style="color:rgb(150,50,150)"><b>$permArray</b></span>([<span class="gmail-s2" style="color:rgb(50,50,150)">1</span><span class="gmail-s3" style="color:rgb(120,120,0)">,</span> <span class="gmail-s2" style="color:rgb(50,50,150)">2</span><span class="gmail-s3" style="color:rgb(120,120,0)">,</span> <span class="gmail-s2" style="color:rgb(50,50,150)">3</span>]) <span class="gmail-s3" style="color:rgb(120,120,0)">=></span> <span class="gmail-s7" style="color:rgb(0,64,0)"><i>serialize</i></span>(<span class="gmail-s1" style="color:rgb(0,150,200)"><b>map</b></span> { <span class="gmail-s6" style="color:rgb(150,50,150)"><b>"method"</b></span><span class="gmail-s3" style="color:rgb(120,120,0)">:</span> <span class="gmail-s2" style="color:rgb(50,50,150)">"json"</span> })</p></blockquote></div><div><br></div><div>The query was shared on the XML.com Slack at <a href="https://xmlcom.slack.com/archives/C011NLXE4DU/p1659114945879269?thread_ts=1658881670.454309&cid=C011NLXE4DU">https://xmlcom.slack.com/archives/C011NLXE4DU/p1659114945879269?thread_ts=1658881670.454309&cid=C011NLXE4DU</a>.</div><div><br></div><div>Using the XQuery debugger, oXygen returns the expected results: </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">[[3,2,1],[2,3,1],[2,1,3],[3,1,2],[1,3,2],[1,2,3]]</blockquote><div><br></div><div>But for some reason oXygen is unable to perform "format & indent" on the source XQuery. Could you please investigate this "lexical error"?</div><div><br></div><div>Thank you,</div><div>Joe</div></div>