Home Download Buy Blog Forum Support

bug: regex in snippet causing instant crash

bug: regex in snippet causing instant crash

Postby teryret on Tue Jun 25, 2013 7:35 pm

I'm building a snippet to help me write java classes and I'm trying to construct a regex to convert $TM_FILEPATH into a package statement (if you know of such a regex please let me know). When I use the following line in my snippet and invoke the snippet in a file sublime instantly crashes.

package ${TM_FILEPATH/.+?ade\/(\/?([^\/]+))+\/[\w\.]+/\.$2/};

Where "ade" is the project's src directory. The error message it throws is:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> >'
what(): The complexity of matching the regular expression exceeded predefined bounds. Try refactoring the regular expression to make each choice made by the state machine unambiguous. This exception is thrown to prevent "eternal" matches that take an indefinite period time to locate.

I totally agree that my regex is to blame, but I feel like there's a better way to handle it than instant crash.
teryret
 
Posts: 4
Joined: Wed Jun 12, 2013 8:44 pm

Re: bug: regex in snippet causing instant crash

Postby teryret on Tue Jun 25, 2013 10:21 pm

In case anyone here is curious how to do this for themselves I just found one way (but there could easily be more). In the block comment at the top of the file I added:

* @file ${100:${TM_FILEPATH/([^a]|a[^d]|ad[^e])+ade\/(?<dir>.+?)\/[\w\.]+$/$+{dir}/}}/$TM_FILENAME

and then down where I wanted the package statement I used:

package ${100/\//\./g};

:D Hooray hacks to cover up for my lack of PCRE-fu
teryret
 
Posts: 4
Joined: Wed Jun 12, 2013 8:44 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 28 guests