On 9/17/07, Nick Alexander <[EMAIL PROTECTED]> wrote:
>
>
> > Robert, Since you do so much work on Cython, maybe you could think
> > about the formal specification of the Python language and see whether
> >      ..
> > not appearing in a string is ever valid Python.  I.e., could we add
> >      [expr1 .. expr2]
> > to the language without running into problems?
>
> Much like generators (K.<x>), this cannot be added to the preparser
> without parsing arbitary python expressions (expr1 and expr2 in this
> case).  At the moment, you can make the preparser barf and it would
> be a great deal of work to fix.  Are we willing to do another
> "correct 90% of the time" hack?  If this is considered very valuable,
> I suggest we hijack a Python binary operator and repurpose it.  Or we
> could uniformly preparse '..' to be that redefined operator; that
> would be better.
>
> I vote against.


Just for clarification, could you explain why the following algorithm
wouldn't suffice to parse the above 100% of the time?

   Suppose at position i, i+1 in the input string that there is "..", and
   this is not in a string.    Reduce i counting ['s and ]'s that are not
   in a string literal until the
   count of [ is greater than the count of ].  This locates the left [.
   Starting again with position i at .., increase i counting ['s and ]'s
   not in string literals until the count of ] is greater than
   the count of ['s.

I naively think the above should correctly find the positions of [ and ],
and hence of expr1 and expr2, in [ expr1 ... expr2 ] in all cases.
I naively think this because I think that any valid Python expression
with a [ must have a balanced ] (discarding string literals).

 -- William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to