Repository navigation
Replace PCRE with re, and fix regex hole bugs, performance and CI - #399
Merged
Merged
Conversation
libpcre3 is gone from Debian trixie and ocaml_pcre is being dropped from nixpkgs, which currently prevents comby from building there (#392). Regex holes now run on ocaml-re, removing the C dependency. Syntax is parsed by a new Vangstrom parser (Regex_syntax) into a Re.t rather than Re.Perl, because Re.Perl uses Latin-1 classes that split UTF-8 (\w+ on "café"), parses [\W] as [\w], and lacks inline flags, (?P<n>), \h, \v, \R and \cA. Breaking: lookaround, backreferences, recursion, possessive quantifiers, atomic groups, \p{..} and (*VERB)s are no longer supported, as the engine is an automaton. Unknown escapes like \q are now errors. Invalid regexes used to exit 0 with no output, with the error visible only under DEBUG_COMBY. They now report a reason and exit 1, or report to stderr for each file for a regex nested in a rule. Also fix hole parsing so that a class or escape after other text no longer ends the hole at its first ]: :[x~b[^a]] and :[x~a\]] now work.
Regex holes now match in the whole source by position, instead of copying the rest of the source at every attempt. That removes quadratic behavior and gives \b and \B their left context. ^ and \A now mean the start of the source rather than holding at every position. Offset conversion folded over the whole source for each offset, costing about 1ms per match on a 90KB file. Convert with a binary search over line starts instead. -fast-offset-conversion no longer has an effect. A bad regex in a rule is now caught at startup and exits 1, and \$ at the end of a pattern is no longer treated as an anchor. Build Dockerfiles with OCaml 5.3 rather than from the stale 4.11 base image, and drop the Ubuntu 18.04 one, which has no OCaml 5 path. Install scripts and the README no longer ask for PCRE.
The Alpine 3.20 image for OCaml 5.3 is a frozen pre-release that opam cannot solve for, so Alpine stays on 5.2. Build the release images in CI, since nothing else would notice them breaking.
rvantonder
force-pushed
the
replace-pcre-with-re
branch
from
November 6, 2026 07:27
2da8177 to
52c08e5
Compare
This was referenced Nov 6, 2026
Closed
5 of 13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #392. Comby no longer depends on PCRE, so it builds on distributions that dropped
libpcre3and without nixpkgs'ocaml_pcre, which is being removed.Regex engine
Regex holes now run on ocaml-re, which is pure OCaml. Syntax is parsed by a new Vangstrom parser,
lib/kernel/matchers/regex_syntax.ml, that builds aRe.t. I avoidedRe.Perlbecause its classes are Latin-1 (\w+oncafésplits theé), it parses[\W]as[\w], and it lacks inline flags,(?P<n>),\h,\v,\Rand\cA.Breaking changes
\p{..}and(*VERB)s. The engine is an automaton, so these now give an error with a reason.\qare now errors.^and\Ainside a pattern now mean the start of the source. They used to hold at every position, so(^a)ona\namatched bothas. A leading^is still handled separately and also matches after a newline.\band\Bsee the character to their left, so\bono longer matches insidefoo.-fast-offset-conversionis accepted but has no effect, because conversion is now always fast.Bug fixes
:[x~b[^a]]and:[x~a\]]ended the hole at the first], and now work.foo\$was treated as an end anchor.:[x~\w+]:[[x]]:[x~nomatchanywhere]CI and packaging
Dockerfilenow builds onubuntu-24.04-ocaml-5.3rather than the old base image.core_unixneeds Alpine below 3.21, and opam couldn't solve on the 3.20 OCaml 5.3 image, probably because it's a frozen pre-release.dockerfiles/ubuntu/binary-release-18.04, which still built with OCaml 4.11 and has no OCaml 5 path.rewas also missing fromcomby-kernel.opam.Testing
-json-linesoutput, including lines and columns, is byte-identical to the old build on the sampled sources.Known gaps
\bnext to non-ASCII text:rehardcodes a Latin-1 word category incategory.ml, with no way to override it, so\b\w+\bleavescaféalone where PCRE matchedcaf. A test pins this.dockerfiles/alpine/binary-release-plus-rganddockerfiles/alpine/base-dependencies.ocamlformat0.24.1 wasn't available. The regex files were formatted with 0.26.2 and the rest wasn't run.Token required. This predates the PR and doesn't fail the build.