Sublime Forum

Bug: regex in snippet causing instant crash

#1

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_injectorstd::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.

0 Likes

#2

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/(?.+?)/\w.]+$/$+{dir}/}}/$TM_FILENAME

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

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

:smiley: Hooray hacks to cover up for my lack of PCRE-fu

0 Likes