From: ara.t.howard@... Date: 2006-07-13T04:58:07+09:00 Subject: Re: Help with a regexp On Thu, 13 Jul 2006 dblack@wobblini.net wrote: >>>> I need to grab the number, then read that many characters, then read the >>>> next number, etc. >>> >>> How do you know, in the case of: >>> >>> 2:ab23:cat >>> >>> which of the two is invalid? >> >> the second. it's invalid here >> >> 2:ab23:cat >> ^ >> ^ >> >> virtual position 10. > > How do you know? The first one could be wrong and the second one > right. because that's the specification: >>>> I need to grab the number, then read that many characters, then read the >>>> next number, etc. so, in this case, the parse follows these steps: - read '2:' - read 2 chars - read '23:' - read 23 chars -> ERROR i think you are confusing the syntax of the structure for the the logic of it. syntax wise '2:ab' is totally valid and so that token pair is consumed. of course it's the case that the user meant 3:ab23:cat it's not up to parsers to detect logic errors, only syntax errors. in this case the left to right quality (no backtracking specified) makes it unambiguous as to which token contains the error - it's the second. yaml has similar issues, for instance this yaml document k : v - 0 - 2 - 3 loads as {"k"=>[0, 2, 3]} which is obviously not what is meant. but is it - k : v - 0 - 2 - 3 or k : - 0 - 2 - 3 both are one char errors. nevertheless it's too much to expect yaml to determine which was meant or suspect that an error was made. regards. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama