aboutsummaryrefslogtreecommitdiff

TECO Regular Expression Engine

This is a regular expression engine, derived from the standalone hsrex library, which is based on Henry Spencer's implementation of advanced regular expressions (ARE) in the Tcl language. This library therefore also provides AREs (see re_syntax). It is a hybrid NFA/DFA design. In contrast to PCRE terex' stack use cannot grow arbitrarily and it has polynomial worst-case runtime. terex is the regular expression engine used by the SciTECO editor and motivated by its needs. It is still kept as a standalone library and may be useful to other projects as well.

Compared to hsrex, this library has the following changes:

  • Renamed re_comp() to tere_comp(), re_exec() to tere_exec(), re_free() to tere_free() and re_error() to tere_error() to avoid collisions with BSD's functions from unistd.h.
  • Native UTF-8 support - no need to convert UTF-8 to UTF-32 first. You no longer need to compile a special version of the library. It expects Unicode strings by default unless specifying the REG_RAW tere_comp() compilation flag.
  • Support the REG_ANCHORED flag for tere_exec().
  • tere_free() ignores nullified regex_t objects.
  • tere_set_is_interrupted_cb() allows configuring a repeatedly invoked callback. If it returns true (non-null) matching aborts immediately and tere_exec() will return REG_EINTR.

TODO

  • Expose enough API to swap out the regular expression lexer. Useful for custom DSLs like glob patterns or TECO patterns.
  • Support splitting the subject string into two halves, so we can preserve the buffer gap when used in SciTECO.
  • Check for useful changes in the Tcl codebase.
  • Check against a proper regular expression test suite. At the very least, convert regtest_terex.sh into an Autotest suite - but then it will work only with Autoconf.

Building

make -f Makefile.linux

There is also an Automake file (Makefile.am) for integration into an existing Autotools build system.