Determining offset of regex syntax errors
Members of class reg_expression know where they are up to while compiling, but don't include that information when they throw. It can be pretty daunting to get the "Invalid regular expression" error message, with no indication of where to start looking, so I'd like to be more helpful. Given the character offset from the start of the RE, I can put the cursor there. Any suggestions as to how to obtain that information? Thanks, Keith MacDonald
Members of class reg_expression know where they are up to while compiling, but don't include that information when they throw. It can be pretty daunting to get the "Invalid regular expression" error message, with no indication of where to start looking, so I'd like to be more helpful. Given the character offset from the start of the RE, I can put the cursor there. Any suggestions as to how to obtain that information?
Currently it can't be done, but you are right that is useful information: I
think the thing to do is put that in the exception class that gets thrown.
I'm working on a re-write of the regular expression construction code now,
so if you're patient I'll add it to my todo list, if not you'll have to add
it yourself to the existing code (look at reg_expression
Members of class reg_expression know where they are up to while compiling, but don't include that information when they throw. It can be pretty daunting to get the "Invalid regular expression" error message, with no indication of where to start looking, so I'd like to be more helpful. Given the character offset from the start of the RE, I can put the cursor
Yes, adding the current position to the bad_expression exception would be
the most helpful solution, for my application. As it's now on your TODO
list, my users will just have to be patient, or more careful ;-)
Thanks,
Keith MacDonald
"John Maddock"
Any suggestions as to how to obtain that information?
Currently it can't be done, but you are right that is useful information: I think the thing to do is put that in the exception class that gets thrown. I'm working on a re-write of the regular expression construction code now, so if you're patient I'll add it to my todo list, if not you'll have to add it yourself to the existing code (look at reg_expression
::fail which handles all failed expression compiles). John.
Yes, adding the current position to the bad_expression exception would be the most helpful solution, for my application. As it's now on your TODO list, my users will just have to be patient, or more careful ;-)
I forgot to mention: don't forget that bad_expression::what() returns at least some information on why there was an error (if not where). John.
participants (2)
-
John Maddock
-
Keith MacDonald