Re: a little parsing challenge ☺

Xah Lee xahlee at gmail.com
Thu Jul 21 11:36:18 EDT 2011


Ok. Here's a preliminary report.

〈Lisp, Python, Perl, Ruby … Code to Validate Matching Brackets〉
http://xahlee.org/comp/validate_matching_brackets.html

it's taking too much time to go thru.

right now, i consider only one valid code, by Raymond Hettinger (with
minor edit from others).

right now, there's 2 other possible correct solution. One by Robert
Klemme but requires ruby19 but i only have ruby18x. One by Thomas
Jollans in Python 3 but didn't run on my machine perhaps due to some
unix/Windows issue, yet to be done.

the other 3 or 4 seems to be incomplete or just suggestion of ideas.

i haven't done extensive testing on my own code neither.
I'll revisit maybe in a few days.

Feel free to grab my report and make it nice. If you would like to fix
your code, feel free to email.

 Xah

On Jul 21, 7:26 am, Ian Kelly <ian.g.ke... at gmail.com> wrote:
> On Thu, Jul 21, 2011 at 6:58 AM, Xah Lee <xah... at gmail.com> wrote:
> > Thanks a lot for the fix Raymond.
>
> That fix was from Thomas Jollans, not Raymond Hettinger.
>
> > Though, the code seems to have a minor problem.
> > It works, but the report is wrong.
> > e.g. output:
>
> > 30068: c:/Users/h3/web/xahlee_org/p/time_machine\tm-ch04.html
>
> > that 30068 position is the last char in the file.
> > The correct should be 28319. (or at least point somewhere in the file
> > at a bracket char that doesn't match.)
> Previously you wrote:
> > If a file has mismatched matching-pairs, the script will display the
> > file name, and the  line number and column number of the first
> > instance where a mismatched bracket occures. (or, just the char number
> > instead (as in emacs's “point”))
>
> I submit that as the file contains no mismatched brackets (only an
> orphan bracket), the output is correct to specification (indeed you
> did not define any output for this case), if not necessarily useful.
>
> In other words, stop being picky.  You may be willing to spend an hour
> or moe on this, but that doesn't mean anybody else is.  Raymond gave
> you a basically working Python solution, but forgot one detail.
> Thomas fixed that detail for you but didn't invest the time to rewrite
> somebody else's function to get the output "correct".  Continuing to
> harp on it at this point is verging on trolling.



More information about the Python-list mailing list