SciLex — a generic, linear-time maximal-munch lexer built on REAL
Project description
SciLex
A small, header-only C++20 maximal-munch lexer built on REAL.
- Linear-time and ReDoS-safe by construction (via REAL).
- Eager
tokenizeor lazyscan. - Optional indentation layout for significant-whitespace languages.
- C++20 header-only + abi3 Python binding (CPython 3.10+).
- Zero dependencies beyond REAL headers.
Define an ordered set of token rules — each a (kind, regex, skip) triple — and
SciLex tokenizes by maximal munch: the longest anchored match wins, with rule
order breaking ties. Because it is a thin layer over REAL, tokenization is linear
and ReDoS-safe by construction.
This follows the same design principles as REAL: purity, simplicity, and measured optimality.
Capabilities
- Ordered token rules:
(kind, real::regex, skip) - Maximal-munch matching (longest match wins, rule order for ties)
- Source positions (byte offset, line, column)
- Eager (
tokenize) and lazy (scan) APIs - Optional
END_OF_INPUTtoken - Optional indentation layout (NEWLINE / INDENT / DEDENT)
- Positioned errors with context snippet
- Linear-time / ReDoS-safe (via REAL)
Not yet: modes, static_lexer, codepoint columns, CLI.
See the guided tour for details.
C++ API
#include <scilex/scilex.hpp>
std::vector<scilex::rule> rules = {
{0, real::regex("\\s+"), true}, // whitespace (skip)
{1, real::regex("if")}, // keyword before identifier
{2, real::regex("[a-z_][a-z0-9_]*")}, // identifier
{3, real::regex("[0-9]+")}, // number
};
scilex::lexer lexer(std::move(rules));
// Eager
for (const auto& tok : lexer.tokenize("if x + 42")) { ... }
// Lazy (preferred for parsers)
for (const auto& tok : lexer.scan("if x + 42")) { ... }
See docs/design.dox for the complete C++ API (lexer, token, position, layout, lex_error).
Python binding
An abi3 CPython extension (CPython 3.10+, Limited API).
import scilex
lx = scilex.Lexer([
(0, r"\s+", True), # whitespace (skip)
(1, r"[0-9]+", False), # number
(2, r"[A-Za-z_][A-Za-z0-9_]*", False),
])
# Eager
tokens = lx.tokenize("foo 42", eof=True)
# Lazy (generator)
for tok in lx.scan("foo 42"):
print(tok.kind, tok.lexeme, tok.position)
# Errors with context
try:
lx.tokenize("foo @")
except scilex.error as e:
e.position
e.context
For significant indentation:
laid = scilex.Layout().apply(lx.tokenize(src, eof=True))
pip install scilex (wheels + sdist). Use scilex.get_include() to compile C++ code against the installed headers.
Build locally: make python && make python-test.
Dependencies
SciLex is header-only and depends only on REAL's headers (the package
real-regex on PyPI / https://github.com/RECHE23/real-regex).
By default the build looks for them in a sibling checkout:
~/Projects/
├── real-regex/ # REAL (https://github.com/RECHE23/real-regex)
└── scilex/ # SciLex (uses ../real-regex/include by default)
Point the build elsewhere with REAL_INCLUDE (Makefile) or
-DSCILEX_REAL_INCLUDE=... (CMake) — for instance at the path printed by
python -c "import real; print(real.get_include())" when REAL is installed via
pip.
For CI or a reproducible build — where no on-disk layout can be assumed — fetch
REAL with CMake FetchContent instead (make build FETCH=1, or
-DSCILEX_FETCH_DEPS=ON); point it at a remote and pin a tag with
-DSCILEX_REAL_REPO=https://… -DSCILEX_REAL_TAG=v2026.6.6.
Development
make test # build and run the test suite
make coverage # line-coverage summary + HTML report
make sanitize # tests under AddressSanitizer + UndefinedBehaviorSanitizer
make lint # clang-tidy
make format # uncrustify, in place
make doc # API reference (Doxygen) with embedded coverage
The API reference is published at https://reche23.github.io/scilex/.
Override the compiler with make test CXX=g++-14.
Coverage bar. SciLex holds the SciLang-stack gate — 100% on all four
dimensions (lines, functions, regions and branches) of include/, checked by
make coverage and enforced by make full-local-gate (using Apple clang 16).
The published report on GitHub Pages / the doc tarball (built on clang 18) reads
mid-90s (newer clang instruments more branches). This is the documented toolchain
distinction; see the live report for exact figures. (REAL is the other documented
exception to the 100% gate — see its README.)
scilex::scilex is the CMake target — add_subdirectory, FetchContent, or an
installed config package. The config calls find_dependency(real), so installing
REAL's config package alongside (on the same prefix) makes the whole chain
resolve from one find_package:
# With REAL and SciLex installed under <prefix>:
find_package(scilex CONFIG REQUIRED) # pulls in real:: transitively
target_link_libraries(app PRIVATE scilex::scilex)
Releasing
make release computes the next calendar version YYYY.M.PATCH (the patch resets
each month; PEP 440 drops leading zeros). The pushed tag drives the release workflow
— wheels + sdist + the API-reference tarball + a GitHub Release, published via Trusted
Publishing — while docs.yml deploys the reference to GitHub Pages.
Design
A guided tour of how SciLex works (maximal munch, REAL foundation, layout,
C++/Python API, limitations) lives in
docs/design.dox (also rendered by make doc).
Performance
See BENCHMARKS.md. On normal input re is faster. On adversarial
input SciLex stays linear while re explodes. See the benchmarks for details.
License
MIT — see LICENSE.
Author
René Chenard
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scilex-2026.6.3.tar.gz.
File metadata
- Download URL: scilex-2026.6.3.tar.gz
- Upload date:
- Size: 31.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eff04fc143fdedcbfbca177654cb0fcfe81f9a8d9c0905d6b0b289c49f97d03f
|
|
| MD5 |
bbe3c62bf9fb18448d78abed24c2fafb
|
|
| BLAKE2b-256 |
ce8c8fd9c66b91418c9e715e8d840cbb015ae2917c8414200d03478fe9860dfd
|
Provenance
The following attestation bundles were made for scilex-2026.6.3.tar.gz:
Publisher:
release.yml on RECHE23/scilex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scilex-2026.6.3.tar.gz -
Subject digest:
eff04fc143fdedcbfbca177654cb0fcfe81f9a8d9c0905d6b0b289c49f97d03f - Sigstore transparency entry: 1886642251
- Sigstore integration time:
-
Permalink:
RECHE23/scilex@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Branch / Tag:
refs/tags/v2026.6.3 - Owner: https://github.com/RECHE23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Trigger Event:
push
-
Statement type:
File details
Details for the file scilex-2026.6.3-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: scilex-2026.6.3-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 244.4 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
033f7d5804cd5d5b3ea66e4b36ba4682d34bd41ca4fa136028964ab4a50f8d6b
|
|
| MD5 |
d6395ff173727b6de8f80199e2fe61d7
|
|
| BLAKE2b-256 |
118632473a6bc5a753f2d33aac37f350121fecb5f953d708e765cbd7e1f9db5f
|
Provenance
The following attestation bundles were made for scilex-2026.6.3-cp310-abi3-win_amd64.whl:
Publisher:
release.yml on RECHE23/scilex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scilex-2026.6.3-cp310-abi3-win_amd64.whl -
Subject digest:
033f7d5804cd5d5b3ea66e4b36ba4682d34bd41ca4fa136028964ab4a50f8d6b - Sigstore transparency entry: 1886642284
- Sigstore integration time:
-
Permalink:
RECHE23/scilex@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Branch / Tag:
refs/tags/v2026.6.3 - Owner: https://github.com/RECHE23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Trigger Event:
push
-
Statement type:
File details
Details for the file scilex-2026.6.3-cp310-abi3-win32.whl.
File metadata
- Download URL: scilex-2026.6.3-cp310-abi3-win32.whl
- Upload date:
- Size: 242.2 kB
- Tags: CPython 3.10+, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a438c42a6592b60d6351ef1620d80aff5b8fd3687b80ab61a79b1b5f581cd5b
|
|
| MD5 |
3871d91f74d94e3fc3a9170da8420588
|
|
| BLAKE2b-256 |
83abbc6b13584c4163cd327d8d92f372d80a08ee6402c350620a59f656fb2f9d
|
Provenance
The following attestation bundles were made for scilex-2026.6.3-cp310-abi3-win32.whl:
Publisher:
release.yml on RECHE23/scilex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scilex-2026.6.3-cp310-abi3-win32.whl -
Subject digest:
5a438c42a6592b60d6351ef1620d80aff5b8fd3687b80ab61a79b1b5f581cd5b - Sigstore transparency entry: 1886642304
- Sigstore integration time:
-
Permalink:
RECHE23/scilex@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Branch / Tag:
refs/tags/v2026.6.3 - Owner: https://github.com/RECHE23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Trigger Event:
push
-
Statement type:
File details
Details for the file scilex-2026.6.3-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: scilex-2026.6.3-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f65273078b2b1ce5697d8f0162d1b209ab95803c986963e451bb901ad2b674ee
|
|
| MD5 |
8641373876af6d2b094cf24ee7b566c1
|
|
| BLAKE2b-256 |
3cc0bccdbc59660840c3b20d2c610f007a78da44740edfd7f6b547d8ac04227c
|
Provenance
The following attestation bundles were made for scilex-2026.6.3-cp310-abi3-musllinux_1_2_x86_64.whl:
Publisher:
release.yml on RECHE23/scilex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scilex-2026.6.3-cp310-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
f65273078b2b1ce5697d8f0162d1b209ab95803c986963e451bb901ad2b674ee - Sigstore transparency entry: 1886642331
- Sigstore integration time:
-
Permalink:
RECHE23/scilex@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Branch / Tag:
refs/tags/v2026.6.3 - Owner: https://github.com/RECHE23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Trigger Event:
push
-
Statement type:
File details
Details for the file scilex-2026.6.3-cp310-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: scilex-2026.6.3-cp310-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7aea6841634eee6c874f58b9b205bf805a64b769712921748fee1a21b72e41fd
|
|
| MD5 |
0afd56caf4b626d68bc88ea5fc78c858
|
|
| BLAKE2b-256 |
ff6433dec4e042e8e29cd872253b00e4d2096a5756dc3949a05edcb274a1e971
|
Provenance
The following attestation bundles were made for scilex-2026.6.3-cp310-abi3-musllinux_1_2_aarch64.whl:
Publisher:
release.yml on RECHE23/scilex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scilex-2026.6.3-cp310-abi3-musllinux_1_2_aarch64.whl -
Subject digest:
7aea6841634eee6c874f58b9b205bf805a64b769712921748fee1a21b72e41fd - Sigstore transparency entry: 1886642314
- Sigstore integration time:
-
Permalink:
RECHE23/scilex@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Branch / Tag:
refs/tags/v2026.6.3 - Owner: https://github.com/RECHE23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Trigger Event:
push
-
Statement type:
File details
Details for the file scilex-2026.6.3-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: scilex-2026.6.3-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 448.5 kB
- Tags: CPython 3.10+, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dde2ba746d07fab833997a22a818524ba7c2d3e7df3d3e47cb831151a03d69f8
|
|
| MD5 |
71649cadfcabb20031c3954330c1ac93
|
|
| BLAKE2b-256 |
bb34b841983cba57c7c4e21464274f945c5ab754aef0a57c93888f624b27447a
|
Provenance
The following attestation bundles were made for scilex-2026.6.3-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
release.yml on RECHE23/scilex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scilex-2026.6.3-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
dde2ba746d07fab833997a22a818524ba7c2d3e7df3d3e47cb831151a03d69f8 - Sigstore transparency entry: 1886642257
- Sigstore integration time:
-
Permalink:
RECHE23/scilex@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Branch / Tag:
refs/tags/v2026.6.3 - Owner: https://github.com/RECHE23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Trigger Event:
push
-
Statement type:
File details
Details for the file scilex-2026.6.3-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: scilex-2026.6.3-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 440.0 kB
- Tags: CPython 3.10+, manylinux: glibc 2.24+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5904f125b0d7a13dbd6b7df10e19bd3be4008fe993451042f79a66f466d75a73
|
|
| MD5 |
ee63f3c916e438e5663177f67803a37b
|
|
| BLAKE2b-256 |
5a2dd9827c367acf130edbdda2552858791d76565e54249fb1882ea457296ec7
|
Provenance
The following attestation bundles were made for scilex-2026.6.3-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
release.yml on RECHE23/scilex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scilex-2026.6.3-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
5904f125b0d7a13dbd6b7df10e19bd3be4008fe993451042f79a66f466d75a73 - Sigstore transparency entry: 1886642268
- Sigstore integration time:
-
Permalink:
RECHE23/scilex@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Branch / Tag:
refs/tags/v2026.6.3 - Owner: https://github.com/RECHE23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Trigger Event:
push
-
Statement type:
File details
Details for the file scilex-2026.6.3-cp310-abi3-macosx_11_0_x86_64.whl.
File metadata
- Download URL: scilex-2026.6.3-cp310-abi3-macosx_11_0_x86_64.whl
- Upload date:
- Size: 56.8 kB
- Tags: CPython 3.10+, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e359111d9fc153ea7424ee90ad08697bc91a724ab2030adca795df4e39c0b6b
|
|
| MD5 |
f5929676b5405508f8a921e91c6a3e8f
|
|
| BLAKE2b-256 |
55dee0f70f6e58c71e92346042da8beaefe17ac576b35dc2aa031f5673802615
|
Provenance
The following attestation bundles were made for scilex-2026.6.3-cp310-abi3-macosx_11_0_x86_64.whl:
Publisher:
release.yml on RECHE23/scilex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scilex-2026.6.3-cp310-abi3-macosx_11_0_x86_64.whl -
Subject digest:
1e359111d9fc153ea7424ee90ad08697bc91a724ab2030adca795df4e39c0b6b - Sigstore transparency entry: 1886642295
- Sigstore integration time:
-
Permalink:
RECHE23/scilex@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Branch / Tag:
refs/tags/v2026.6.3 - Owner: https://github.com/RECHE23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Trigger Event:
push
-
Statement type:
File details
Details for the file scilex-2026.6.3-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: scilex-2026.6.3-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 54.2 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98e44959bd76c3652ea64d3a1981ee3ab7a7053493cd93d97b49031c0ec2d2d6
|
|
| MD5 |
bbbf43e9a92d4158cefd29056248a05e
|
|
| BLAKE2b-256 |
a08437d654f8a2095e9298ac66cd6c98b0fdf94263b456e634ecef0b7a61823c
|
Provenance
The following attestation bundles were made for scilex-2026.6.3-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on RECHE23/scilex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scilex-2026.6.3-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
98e44959bd76c3652ea64d3a1981ee3ab7a7053493cd93d97b49031c0ec2d2d6 - Sigstore transparency entry: 1886642324
- Sigstore integration time:
-
Permalink:
RECHE23/scilex@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Branch / Tag:
refs/tags/v2026.6.3 - Owner: https://github.com/RECHE23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@457eb7d70a0ba621c60603aa30818c4cefe1a95b -
Trigger Event:
push
-
Statement type: