<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>4176</bug_id>
          
          <creation_ts>2007-01-10 09:23:36 +0000</creation_ts>
          <short_desc>[UPD] Syntax &quot;do rename ... as ...&quot; problematic with tokenization</short_desc>
          <delta_ts>2007-03-08 11:05:05 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>Update Facility</component>
          <version>Working drafts</version>
          <rep_platform>Macintosh</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Martin Probst">martin</reporter>
          <assigned_to name="Andrew Eisenberg">andrew.eisenberg</assigned_to>
          <cc>john.snelson</cc>
    
    <cc>scott_boag</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>13396</commentid>
    <comment_count>0</comment_count>
    <who name="Martin Probst">martin</who>
    <bug_when>2007-01-10 09:23:36 +0000</bug_when>
    <thetext>While implementing the current XQuery updates working draft I noticed a problem with the syntax for &quot;do rename&quot;. Syntax is &quot;do rename&quot; expr &quot;as&quot; expr. Assuming a stateful, stack based Lexer, the implementation will run into problems. I&apos;m using the state names from the &quot;Building a Tokenizer for XPath or XQuery&quot; note.

The Lexer will be in default state after the &quot;do rename&quot; token, then lex the expr content. After that, it&apos;s in operator state. When it now encounters an &quot;as&quot; token it&apos;s ambiguous whether the next state should be itemtype or default. Type declarations like &quot;let $x as foo :=&quot; need the itemtype state, do rename needs default state. 

As far as I can see it&apos;s not possible to solve this using the stack. The only two workarounds are to either duplicate the expression states in the lexer just for the do rename statement (ie. have a &quot;default but do rename&quot; state) or to inject the state knowledge from the parser. Both doesn&apos;t quite get a buty price.

Is &quot;do rename expr into expr&quot; correct English? That should give less problems.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>13398</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2007-01-10 10:15:01 +0000</bug_when>
    <thetext>If it&apos;s problematic for rename, then it&apos;s presumably problematic for insert too?

My personal view on this is that I&apos;m not at all comfortable with the English-like or Cobol-like statement syntax when used in a language that&apos;s an expression language rather than a statement language, and especially one that has no reserved words. We changed the sequence type syntax for this reason from &quot;element x of type y&quot; to element(x,y), and I think we would make life easier for both implementors and users if we applied the same treatment to update expressions. I can&apos;t see what&apos;s wrong with rename(x,y); or if there are semantic reasons for not using a function call, then perhaps rename{x,y} or rename{x}{y}. On the surface it looks more cryptic, but once you build compound expressions with a lot of nesting it&apos;s far clearer.

Michael Kay</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>13444</commentid>
    <comment_count>2</comment_count>
    <who name="Martin Probst">martin</who>
    <bug_when>2007-01-11 12:59:22 +0000</bug_when>
    <thetext>In do insert ... (as first | as last) into ... you can do a lookahead and decide because of the following &apos;first into&apos; or &apos;last into&apos;, as those would be syntax errors in the itemtype state (however if there would only be one word following, that would be a problem...).

I do second the idea of a function-based syntax. I implemented a custom syntax for updates using functions (which are extremely close to this spec, except for the syntax) before this spec was publicly available, and users seem to adapt to it without much problems.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>13445</commentid>
    <comment_count>3</comment_count>
    <who name="John Snelson">john.snelson</who>
    <bug_when>2007-01-11 14:36:59 +0000</bug_when>
    <thetext>I thought I had solved this problem, but I&apos;ve just checked and found a bug. A simpler solution would be to use &quot;to&quot; instead of &quot;as&quot;, since the &quot;to&quot; operator already changes back to the initial state.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>13509</commentid>
    <comment_count>4</comment_count>
    <who name="Martin Probst">martin</who>
    <bug_when>2007-01-12 22:48:39 +0000</bug_when>
    <thetext>If I remember this correctly the syntax used to be &quot;do rename ... to ...&quot;, but the problem is that &quot;to&quot; conflicts with the syntax for integer list construction:

do rename 1 to 10 to xs:QName(&quot;foo&quot;)

(I think it&apos;s then non-LL(1)).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>13857</commentid>
    <comment_count>5</comment_count>
    <who name="Scott Boag">scott_boag</who>
    <bug_when>2007-01-31 16:06:06 +0000</bug_when>
    <thetext>Irrespecitive of proposals for new syntax such as rename(a, b), the current syntax does not seem to have an ambiguity problem, as far as I can tell.  

&quot;Building a Tokenizer for XPath or XQuery&quot; (http://www.w3.org/TR/xquery-xpath-parsing/ was supposed to be marked as obsolete.  That it&apos;s not is probably my fault.  I know someone had an action from a working group meeting to do so.  We were running into certain brick walls with trying to do lexical-based disambiguation, which is why we dropped much of the lexical state machine in the test parser in favor of a lookahead mechanism (http://www.w3.org/2006/11/applets/xqueryApplet.html ... I can send you an xquery-update version of this, including .jjt file), and made the note obsolete.

I think you are saying that something like:

do rename foo treat as element() as baz

or 

do rename let $x as element() := foo return $x as baz

They are not ambiguous as the first is clearly associated with the &quot;treat&quot;, and the second more stand-alone &quot;as&quot; only occurs within limited defined contexts which expects a type declaration or a non-default thing such as &quot;:=&quot; or &quot;,&quot; or &quot;{&quot;.  Lexicially, they don&apos;t have to be distinguished... they can be the same token.  I don&apos;t think you actually need lookahead for this.   The test parser evaluates both expressions correctly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>13905</commentid>
    <comment_count>6</comment_count>
    <who name="Martin Probst">martin</who>
    <bug_when>2007-02-05 10:55:51 +0000</bug_when>
    <thetext>The problem for me is that the grammar started out as being LL(1) if a certain (quite complex) set of tokenization rules is being followed. With this addition of &quot;as&quot; as a token that leads to a non itemtype state, these rules break - it&apos;s no longer possible to write a tokenizer that is self-sufficient and correctly tokenizes any input without the help of a parser. The language is not ambiguous, it&apos;s just no longer LL(1), even with a tricky lexer.

To clarify: using &apos;as&apos; as the keyword in this place would require to no longer lex a following &apos;element()&apos; as an element test/type. This would then require the parser to look ahead beyond the QName token &apos;element&apos; and see what&apos;s coming up to decide if &apos;element&apos; is a type name or the element test. That is not LL(1).

It&apos;s possible to solve this (my current way is to include a Horrible Hack (tm) where the parser tells the lexer in the rename state to expect that &quot;as&quot; token), but it&apos;s quite ugly to add a language extension that breaks a formerly good strategy to parse the language.

I&apos;d also say that adding more and more syntax to the language doesn&apos;t really make it more usable, quite the contrary. &apos;as&apos; used to be an indicator of a type declaration (functions, flwor, typeswitch), now it&apos;s being used for two different things. I think it would also be easier for GUIs/editors if we would try to keep single keywords having a single meaning as much as possible.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>14346</commentid>
    <comment_count>7</comment_count>
    <who name="Don Chamberlin">chamberl</who>
    <bug_when>2007-03-07 19:30:00 +0000</bug_when>
    <thetext>Martin,
The Query Working Group considered this issue on 6 March 2007. We believe that multiple approaches exist that permit tokenization and parsing of the &quot;rename ... as&quot; syntax published in the current Working Draft. Therefore we are changing the status of this bug report to &quot;Invalid&quot;. If you are satisfied with this resolution, please mark this bug report as Closed.
Thanks,
Don Chamberlin (for the Query Working Group)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>14351</commentid>
    <comment_count>8</comment_count>
    <who name="Martin Probst">martin</who>
    <bug_when>2007-03-08 11:05:05 +0000</bug_when>
    <thetext>Closing the bug.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>