Files
regexx/Makefile
T
retoorandClaude Sonnet 5 8f6afd6cd4 Add regexx: a single-file C regex interpreter with Python re semantics
concept.md is the full design document: the objective (Python re parity
plus binary/ASCII/UTF-8 modes, gigabyte-scale input, single C file), the
automata-theory argument for why unrestricted backreferences/lookaround
are incompatible with strict single-pass constant memory, the resulting
two-engine architecture, the exact Python-mirroring naming convention,
and a full comparison against POSIX regex.h for C-background readers.

regexx.c/regexx.h are the v1 implementation: parser, compiler to a
Pike/backtracking-style bytecode, and a single recursive backtracking
engine covering the pattern syntax and operations listed in README.md,
validated against CPython's own re module output (tests/), clean under
AddressSanitizer/UBSan, and stress-tested (50MB simple-quantifier match,
graceful failure rather than a crash on complex repeats over large
input, clean rejection of every intentionally unsupported construct).

Also included: examples/rxgrep.c (a small grep-like program exercising
all three data modes and the substitution API), the Makefile, the MIT
LICENSE, and docs/API.md, an exhaustive reference for every type, flag,
and function's exact return-value and memory-ownership convention,
checked against the current source and against a real CPython
interpreter rather than against memory.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EjuMk8kY9SDus1wWe2K9xY
2026-09-14 05:56:16 +00:00

58 lines
1.8 KiB
Makefile

# Makefile for regexx: a single-file C regex interpreter with Python
# `re` semantics. See concept.md for the design and README.md for the
# implementation status.
CC ?= cc
CSTD ?= -std=c11
WARN ?= -Wall -Wextra
OPT ?= -O2
CFLAGS ?= $(CSTD) $(WARN) $(OPT) -g
LDLIBS ?=
PREFIX ?= /usr/local
AR ?= ar
.PHONY: all lib example test check clean install fuzz-smoke
all: lib example
# ---- library -----------------------------------------------------------
libregexx.a: regexx.o
$(AR) rcs $@ $^
regexx.o: regexx.c regexx.h
$(CC) $(CFLAGS) -c regexx.c -o $@
lib: libregexx.a
# ---- example -------------------------------------------------------------
example: rxgrep
rxgrep: examples/rxgrep.c libregexx.a regexx.h
$(CC) $(CFLAGS) -I. -o $@ examples/rxgrep.c libregexx.a $(LDLIBS)
# ---- tests -----------------------------------------------------------------
# tests/generated_tests.c is generated from tests/cases.py using
# CPython's own `re` module as ground truth (concept.md Section 11).
tests/generated_tests.c: tests/cases.py tests/gen.py
python3 tests/gen.py
test: tests/generated_tests.c regexx.c regexx.h tests/harness.c tests/harness.h tests/main.c
$(CC) $(CFLAGS) -I. -o /tmp/regexx_test regexx.c tests/harness.c tests/generated_tests.c tests/main.c $(LDLIBS)
/tmp/regexx_test
# check also runs the suite under AddressSanitizer + UBSan.
check: tests/generated_tests.c
$(CC) $(CSTD) $(WARN) -O0 -g -fsanitize=address,undefined -I. -o /tmp/regexx_test_san \
regexx.c tests/harness.c tests/generated_tests.c tests/main.c $(LDLIBS)
/tmp/regexx_test_san
install: libregexx.a regexx.h
install -d $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include
install -m644 libregexx.a $(DESTDIR)$(PREFIX)/lib/
install -m644 regexx.h $(DESTDIR)$(PREFIX)/include/
clean:
rm -f regexx.o libregexx.a rxgrep tests/generated_tests.c