a little parsing challenge ☺
tjreedy at udel.edu
Tue Jul 19 21:09:41 CEST 2011
On 7/19/2011 2:12 PM, Xah Lee wrote:
>> Also, you may have answered this earlier but I'll ask again anyways: You
>> ask for the first mismatched pair, Are you referring to the inner most
>> mismatched, or the outermost? For example, suppose you have this file:
>> Would the "(" be the first mismatched character or would the "]"?
> yes i haven't been precise. Thanks for brining it up.
> thinking about it now, i think it's a bit hard to define precisely.
Then it is hard to code precisely.
> My elisp code actually reports the “)”, so it's wrong too. LOL
This sort of exercise should start with a series of test cases, starting
with the simplest.
testpairs = (
('', True), # or whatever you want the OK response to be
('()', True), # and so on for each pair of fences
('(', False), # or exact error output wanted
(')', False), # and so on
The above could be generated programatically from the set of pairs that
should be the input to the program, so that the pairs are not hardcoded
into the logic.
Terry Jan Reedy
More information about the Python-list