Skip to main content

SNOBOL4 string pattern matching for Python — dual-backend (pure-Python and C/SPIPAT).

Project description

SNOBOL4python 0.5.0

SNOBOL4-style string pattern matching for Python — with a dual backend:

Backend Speed Availability
C / SPIPAT (default) 7–11× faster than 0.4.x CPython 3.10+ with GCC
Pure Python 100 % portable Any Python ≥ 3.10

The C backend is powered by Phil Budne's SPIPAT pattern engine, wrapped as a CPython extension (sno4py).


Quick Start

from SNOBOL4python import *

GLOBALS(globals())

p = σ("hello") | σ("world")
if "say hello" in p:
    print("matched")

result = SEARCH("say hello", σ("hello"))   # → slice(4, 9)

Backend Selection

Automatic (default)

On import, SNOBOL4python checks whether the sno4py C extension is importable. If it is, the C/SPIPAT backend is used; otherwise the pure-Python backend is used transparently — no code changes required.

Environment variable

# Force pure-Python (always available, useful for debugging):
SNOBOL4_BACKEND=pure python3 my_script.py

# Force C backend (ImportError if sno4py not installed):
SNOBOL4_BACKEND=c python3 my_script.py

Runtime switching

import SNOBOL4python as S4

print(S4.current_backend())   # 'c' or 'pure'
print(S4.C_AVAILABLE)         # True if sno4py extension is present

S4.use_pure()                 # switch to pure-Python
S4.use_c()                    # switch back to C (raises ImportError if unavailable)

# After switching, call GLOBALS() again so the new backend
# sees the caller's variable namespace:
S4.GLOBALS(globals())

Note: Patterns are compiled at construction time by whichever backend is active. Do not mix pattern objects from different backends in the same expression; rebuild patterns after switching.


Installing the C/SPIPAT Backend

The sno4py extension is built from source alongside the sno4py_stage8 directory that is distributed separately (or built from the repository).

cd sno4py
make                    # produces sno4py.<platform>.so
# then place or symlink it somewhere on sys.path, or into site-packages

Requirements: Python 3.10+, GCC (or compatible C compiler), python3-dev.


Pattern Reference

Constructor SNOBOL4 equivalent Description
ε() null Matches empty string
σ(s) 's' Literal string
FAIL() FAIL Always fails
ABORT() ABORT Aborts entire match
SUCCEED() SUCCEED Always succeeds (infinite)
P + Q P Q Concatenation
P | Q P | Q Alternation
~P / π(P) P | '' Optional
P @ 'name' P $ N Immediate assignment
P % 'name' P . N Conditional assignment
Σ(P, Q, …) P Q … Multi-way concatenation
Π(P, Q, …) P | Q | … Multi-way alternation
P & Q / ρ(P, Q) Conjunction (same span)
ANY(chars) ANY(s) One char from set
NOTANY(chars) NOTANY(s) One char not in set
SPAN(chars) SPAN(s) One or more chars from set
BREAK(chars) BREAK(s) Up to (not incl.) char in set
BREAKX(chars) BREAKX(s) Like BREAK, resumes after break char
NSPAN(chars) Zero or more chars (possessive)
ARB() ARB Any string (shortest first)
ARBNO(P) ARBNO(P) Zero or more repetitions of P
BAL() BAL Balanced parentheses
REM() REM Remainder of subject
FENCE() FENCE Commit point (abort on backtrack)
FENCE(P) FENCE(P) Protected region
POS(n) POS(n) Cursor at position n from left
RPOS(n) RPOS(n) Cursor at position n from right
LEN(n) LEN(n) Match exactly n chars
TAB(n) TAB(n) Advance cursor to position n
RTAB(n) RTAB(n) Advance cursor to position n from right
ζ(name_or_callable) *name Deferred pattern reference
Λ(expr_or_fn) *expr Immediate predicate / eval
λ(stmt_or_fn) Conditional action
Θ(name) Immediate cursor assignment
θ(name) Conditional cursor assignment
Φ(regex) Regex match (immediate group capture)
φ(regex) Regex match (conditional group capture)
α() BOL anchor
ω() EOL anchor

Shift-reduce parser stack (Stage 8)

Constructor Description
nPush() Push 0 onto integer counter stack
nInc() Increment top of integer counter stack
nPop() Pop integer counter stack
Shift(tag[, expr]) Push node onto parse-tree value stack
Reduce(tag[, n]) Pop n nodes, wrap as [tag, …], push back
Pop(var) Pop top of value stack into globals[var]

Match Functions

SEARCH(S, P)        # → slice or None   (search anywhere in S)
MATCH(S, P)         # → slice or None   (anchored at start)
FULLMATCH(S, P)     # → slice or None   (anchored at both ends)

# Operators:
subject in pattern          # → bool
pattern == subject          # → slice (raises F on failure)

Version History

Version Notes
0.5.0 Dual backend: C/SPIPAT (default, 7–11× faster) + pure-Python. NSPAN added. use_c() / use_pure() / current_backend() / C_AVAILABLE.
0.4.x Pure-Python generator engine. Stage 8: shift-reduce parser stack.

Credits

  • SNOBOL4python — Lon Jones Cherryholmes
  • SPIPAT / sno4py C engine — Phil Budne
  • Pattern semantics based on The SNOBOL4 Programming Language (Griswold, Poage, Polonsky) and the SPITBOL manual.

License

GPL-3.0-or-later

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snobol4python-0.5.2.tar.gz (93.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

snobol4python-0.5.2-cp312-cp312-win_amd64.whl (63.1 kB view details)

Uploaded CPython 3.12Windows x86-64

snobol4python-0.5.2-cp312-cp312-musllinux_1_2_x86_64.whl (175.0 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

snobol4python-0.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (179.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

snobol4python-0.5.2-cp312-cp312-macosx_11_0_arm64.whl (68.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

snobol4python-0.5.2-cp311-cp311-win_amd64.whl (63.0 kB view details)

Uploaded CPython 3.11Windows x86-64

snobol4python-0.5.2-cp311-cp311-musllinux_1_2_x86_64.whl (173.1 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

snobol4python-0.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (177.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

snobol4python-0.5.2-cp311-cp311-macosx_11_0_arm64.whl (68.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

snobol4python-0.5.2-cp310-cp310-win_amd64.whl (63.1 kB view details)

Uploaded CPython 3.10Windows x86-64

snobol4python-0.5.2-cp310-cp310-musllinux_1_2_x86_64.whl (174.3 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

snobol4python-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (178.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

snobol4python-0.5.2-cp310-cp310-macosx_11_0_arm64.whl (68.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file snobol4python-0.5.2.tar.gz.

File metadata

  • Download URL: snobol4python-0.5.2.tar.gz
  • Upload date:
  • Size: 93.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for snobol4python-0.5.2.tar.gz
Algorithm Hash digest
SHA256 ffb7a416cd6148b16083488fbbcacc07b8ab397d590d3d1dee8ad0b30367c7b1
MD5 c85c55eec09b3768948934877171341c
BLAKE2b-256 9ab1e443776999025fd19365a23a935c5c9f9626488229eb8e92985929b1b6b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2.tar.gz:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 32741be8f1bb5f441ca18b4bd7548039c192f1c7a426edb613c9bf217b5d408d
MD5 e6fc2fd0b3d3eab9e6ff26064ac39fbb
BLAKE2b-256 c3a7bb7ad72ba423cc583a4bde2499ef044cc0d414694be2371c81affa969734

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp312-cp312-win_amd64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d9a3f288ba1453be7b0a4c1e202393538ab66153ba721e5681278094450ae1f0
MD5 adbf68f6843dc4237d1b565190b78ff0
BLAKE2b-256 3ffd4b60e3a01272ef6db2e55d6c3780c05bbcd6913b5baeafacff239c27b69d

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ce48096bcc3dd7dc222ab0fcfd1a58581fa579e68debfd483be580da3a85256
MD5 b030f4d43f3fa9f9a6ff2f67b9533366
BLAKE2b-256 2b3e5644f54e3bda21060f670a426dc3975ca2feb8c2b28066f1e50704866ece

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 941fd12861a1538fce17e9e999734cc65e5d271705f5fd7a4671dbec777778e4
MD5 c5523e69473a61040529a83afcd2f4e2
BLAKE2b-256 59f2c5ab511f981fa1377b1aa1a19c7862f963e48f1bd14172d58b0b6af3b23c

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4005da41eacc5d3afca2211fa0094779e3a8d0803506b698d942128cc8dd1675
MD5 2c2ec040a002131d922a07f0493c1e8f
BLAKE2b-256 570b2af259d7016620704109061cff92da974449b91d1cf24d223b76657e07ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp311-cp311-win_amd64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cfd5aba00f3dc0534d3815dca584604fc9e2ddde168fcb28da73ddd514b187cf
MD5 36d0a401bd154cdd5438deb1d3aca48c
BLAKE2b-256 5d602caa367e9534b68f7257533407ddd92cc1162f87e964ca8d59863c6b4efc

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e05bda2759f213a2ee64a6039bdcc14993cf1cc3664a8bcb8656dc0445b1976a
MD5 99d3f549683beaaf9211d4eef32953f3
BLAKE2b-256 7e2ac47aa4ee54c50a4ef391a7541d85d8a79c58f1c230049ce1c605edf2e296

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c0906ab986a477b95f3220f8e9c7f38dcea140c17cf104dda0ceefa3cf03a696
MD5 332fcdba243f174f80460c4bdada8d2a
BLAKE2b-256 a64e626a2ebc6b642c77504e407a8b87bc9de2541fab72814544321a531ff55e

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a21f7e1b9520a12435c8670aaf2df7a88b7a54742f567460314cbbc5ce10a468
MD5 d70c3808064313a6e1d0e08aa2baa097
BLAKE2b-256 8c566366d97caec4bd865f2670bb617b13e1fabe25da3a6811e09fbf0baaca90

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp310-cp310-win_amd64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c451244513c1a2b2d5d0f16c0049f0f6982039b33607a26233913c9c64c8825f
MD5 983b18edbc477671c715d2aae43c4593
BLAKE2b-256 efe8546071cf9364dd28778ba6ff4ab57082f5ad1987042c87c0d068cdb53781

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3eec10e844f9cb6c7e1b1cee85a9d49854c147c256b80d11f6a42ec4820ce491
MD5 b4ef3ea273fe22de66b02ca33dc3da4c
BLAKE2b-256 d83cbe64b6f3caf90736e431128ae132052be4cf0a5758b13052ed1c17cd2c49

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snobol4python-0.5.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for snobol4python-0.5.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7f19a1d7d4569668133aafe8fcb093d47e5d61430a1565714dc026e82015000c
MD5 6b4747ae187451b2172e7f106ba60782
BLAKE2b-256 b58925ac2649fa2176bb8ca2feb7bcf606fd03af847c4eed47cc8bd699978f57

See more details on using hashes here.

Provenance

The following attestation bundles were made for snobol4python-0.5.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: wheels.yml on SNOBOL4-plus/SNOBOL4-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page