Snail programming language interpreter
Project description
Snail
Snail is a programming language that compiles to Python, combining Python's familiarity and extensive libraries with Perl/awk-inspired syntax for quick scripts and one-liners. Its what you get when you shove a snake in a shell.
AI Slop!
Snail is me learning how to devlop code using LLMs. I think its neat, and maybe useful. I don't think this is high quality. I am going to try and LLM my way into something good, but its certainly not there yet.
Installing Snail
pip install snail-lang
-or-
uv tool install snail-lang
That installs the snail CLI for your user; try it with snail "print('hello')" once the install completes.
✨ What Makes Snail Unique
Curly Braces, Not Indentation
Write Python logic without worrying about whitespace:
def process(items) {
for item in items {
if item > 0 { print(item) }
else { continue }
}
}
Note, since it is jarring to write python with semicolons everywhere, semicolons are optional. You can separate statements with newlines.
Awk Mode
Process files line-by-line with familiar awk semantics:
/hello/ { print("matched:", $0) }
{ print($1, "->", $2) }
Built-in variables:
| Variable | Description |
|---|---|
$0 |
Current line (with newline stripped) |
$1, $2, ... |
Individual fields (whitespace-split) |
$f |
All fields as a list |
$n |
Global line number (across all files) |
$fn |
Per-file line number |
$src |
Current file path |
$m |
Last regex match object |
Setup and teardown code can be supplied via CLI flags (-b/--begin, -e/--end).
Begin code runs before the line-processing loop, end code runs after.
Awk $ variables are not available in begin/end code (they are outside the awk { } block).
echo -e "5\n4\n3\n2\n1" | snail --awk --begin 'total = 0' --end 'print("Sum:", total)' '/^[0-9]+/ { total = total + int($1) }'
Xargs Mode
Process files one at a time instead of line-by-line:
print("File:", $src)
print("Size:", len($text), "bytes")
Built-in variables:
| Variable | Description |
|---|---|
$src |
Current file path |
$fd |
Open file handle for the current file |
$text |
Lazy text view of the current file contents |
Setup and teardown code can be supplied via CLI flags (-b/--begin, -e/--end).
Begin code runs before the file-processing loop, end code runs after.
Xargs $ variables are not available in begin/end code (they are outside the xargs { } block).
find . -name "*.txt" | snail --xargs --begin "print('start')" --end "print('done')" "print($src)"
Built-in Variables (All Modes)
| Variable | Description |
|---|---|
$e |
Exception object in expr:fallback? |
$env |
Environment map (wrapper around os.environ) |
Begin/End Flags
The -b/--begin and -e/--end CLI flags prepend and append code around the
main program in all modes. In awk mode the code runs outside the awk { } wrapper;
in xargs mode it runs outside the xargs { } wrapper.
print("running")
In regular mode, my main use case for this feature is passing unexported variables
my_bashvar=123
snail -b x=$my_bashvar 'int(x) + 1'
This is roughly the same as using $env to access an exported variable.
my_bashvar=123 snail 'int($env.my_bashvar) + 1'
Compact Error Handling
The ? operator makes error handling terse yet expressive:
# Swallow exception, return None
err = risky()?
# Swallow exception, return exception object
err = risky():$e?
# Provide a fallback value (exception available as $e)
value = js("malformed json"):%{"error": "invalid json"}?
details = fetch_url("foo.com"):"default html"?
exception_info = fetch_url("example.com"):$e.http_response_code?
# Access attributes directly
name = risky("")?.__class__.__name__
args = risky("becomes a list"):[1,2,3]?[0]
Destructuring + if let / while let
Unpack tuples and lists directly, including Python-style rest bindings:
x, *xs = [1, 2, 3]
if let [head, *tail] = [1, 2, 3]; head > 0 {
print(head, tail)
}
if let/while let only enter the block when the destructuring succeeds. A guard
after ; lets you add a boolean check that runs after the bindings are created.
Note that this syntax is more powerful than the walrus operator as that does not allow for destructuring.
Pipeline Operator
The | operator enables data pipelining as syntactic sugar for nested
function calls. x | y | z becomes z(y(x)). This lets you stay in a
shell mindset.
# Pipe data to subprocess stdin
result = "hello\nworld" | $(grep hello)
# Chain multiple transformations
output = "foo\nbar" | $(grep foo) | $(wc -l)
# Custom pipeline handlers
class Doubler {
def __call__(self, x) { return x * 2 }
}
doubled = 21 | Doubler() # yields 42
Arbitrary callables make up pipelines, even if they have multiple parameters. Snail supports this via placeholders.
greeting = "World" | greet("Hello ", _) # greet("Hello ", "World")
excited = "World" | greet(_, "!") # greet("World", "!")
formal = "World" | greet("Hello ", suffix=_) # greet("Hello ", "World")
When a pipeline targets a call expression, the left-hand value is passed to the
resulting callable. If the call includes a single _ placeholder, Snail substitutes
the piped value at that position (including keyword arguments). Only one
placeholder is allowed in a piped call. Outside of pipeline calls, _ remains a
normal identifier.
Built-in Subprocess
Shell commands are first-class citizens with capturing and non-capturing forms.
# Capture command output with interpolation
greeting = $(echo hello {name})
# Pipe data through commands
result = "foo\nbar\nbaz" | $(grep bar) | $(cat -n)
# Check command status
status = @(make build)? # returns SnailExitStatus on failure instead of raising
if status { print("build passed") } else { print(status.rc) }
Regex Literals
Snail supports first class patterns. Think of them as an infinte set.
if bad_email in /^[\w.]+@[\w.]+$/ {
print("Valid email")
}
# Compiled regex for reuse
pattern = /\d{3}-\d{4}/
match = pattern.search(phone)
match2 = "555-1212" in pattern
Snail regexes don't return a match object, rather they return a tuple
containing all of the match groups, including group 0. Both search and in
return the same tuple (or () when there is no match).
JSON Queries with JMESPath
Parse and query JSON data with the js() function and structured pipeline accessor:
# Parse JSON and query with $[jmespath]
# JSON query with JMESPath
data = js($(curl -s https://api.github.com/repos/sudonym1/snail))
counts = data | $[stargazers_count]
# Inline parsing and querying
result = js('{{"foo": 12}}') | $[foo]
# JSONL parsing returns a list
names = js('{{"name": "Ada"}}\n{{"name": "Lin"}}') | $[[*].name]
Snail rewrites JMESPath queries in $[query] so that double-quoted segments are
treated as string literals. This lets you write
$[items[?ifname=="eth0"].ifname] inside a single-quoted shell command. If you
need JMESPath quoted identifiers (for keys like "foo-bar"), escape the quotes
in the query (for example, $[\"foo-bar\"]). JSON literal backticks
(`...`) are left unchanged.
Full Python Interoperability
Snail compiles to Python AST—import any Python module, use any library, in any environment. Assuming that you are using Python 3.8 or later.
🚀 Quick Start
# One-liner: arithmetic + interpolation
snail 'name="Snail"; print("{name} says: {6 * 7}")'
# JSON query with JMESPath
snail 'js($(curl -s https://api.github.com/repos/sudonym1/snail)) | $[stargazers_count]'
# Compact error handling with fallback
snail 'result = int("oops"):"bad int {$e}"?; print(result)'
# Regex match and capture
snail 'if let [_, user, domain] = "user@example.com" in /^[\w.]+@([\w.]+)$/ { print(domain) }'
# Awk mode: print line numbers for matches
rg -n "TODO" README.md | snail --awk '/TODO/ { print("{$n}: {$0}") }'
# Environment variables
snail 'print($env.PATH)'
📚 Documentation
Documentation is WIP
- Language Reference — Complete syntax and semantics
- examples/all_syntax.snail — Every feature in one file
- examples/awk.snail — Awk mode examples
- examples/xargs.snail — Xargs mode examples
🔌 Editor Support
Vim/Neovim plugin with Tree-sitter-based highlighting (Neovim), formatting, and run commands:
Plug 'sudonym1/snail'
-- lazy.nvim
{
'sudonym1/snail',
lazy = false, -- optional
}
Open any .snail file and the parser will auto-install if needed.
Manual fallback: :TSInstall snail.
See extras/vim/README.md for details. Tree-sitter grammar available in extras/tree-sitter-snail/.
Performance
Section is WIP
Startup performance is benchmarked with ./benchmarks/startup.py. On my
machine snail adds 5 ms of overhead above the regular python3 interpreter.
🛠️ Building from Source
Prerequisites
Python 3.8+ (required at runtime)
Snail runs in-process via a Pyo3 extension module, so it uses the active Python environment.
Installation per platform:
- Ubuntu/Debian:
sudo apt install python3 python3-dev - Fedora/RHEL:
sudo dnf install python3 python3-devel - macOS:
brew install python@3.12(or use the system Python 3) - Windows: Download from python.org
Build, Test, and Install
# Clone the repository
git clone https://github.com/sudonym1/snail.git
cd snail
make test
make install
Arch Linux (PKGBUILD)
An Arch package build file is available at extras/arch/PKGBUILD.
mkdir -p /tmp/snail-pkg
cp extras/arch/PKGBUILD /tmp/snail-pkg/
cd /tmp/snail-pkg
# Update pkgver and sha256sums as needed, then build and install
makepkg -si
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 snail_lang-0.9.1.tar.gz.
File metadata
- Download URL: snail_lang-0.9.1.tar.gz
- Upload date:
- Size: 138.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b9f58a4d44c4f82634e34ff5e8a8d5092d0f39128127a4241d04264c9d11d88
|
|
| MD5 |
41ec521d1a12f4ea607f34a23e5af178
|
|
| BLAKE2b-256 |
b68939365a519e6ab93f2a2119abdd466aef63c9f9a8c7a35366da752d7a0b74
|
Provenance
The following attestation bundles were made for snail_lang-0.9.1.tar.gz:
Publisher:
release.yml on sudonym1/snail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
snail_lang-0.9.1.tar.gz -
Subject digest:
7b9f58a4d44c4f82634e34ff5e8a8d5092d0f39128127a4241d04264c9d11d88 - Sigstore transparency entry: 1100539461
- Sigstore integration time:
-
Permalink:
sudonym1/snail@e26dee7b9b80726eaad26ddb7308d0a91b4fa030 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/sudonym1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e26dee7b9b80726eaad26ddb7308d0a91b4fa030 -
Trigger Event:
push
-
Statement type:
File details
Details for the file snail_lang-0.9.1-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: snail_lang-0.9.1-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 691.6 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74c0a68bb7a5335f58ab118dbced13941ec670b3d26de268c0ebe55436475036
|
|
| MD5 |
c605a43e1497142e6f793e0d7914c9b5
|
|
| BLAKE2b-256 |
a2fd47a1c5c51db5dd8f66d61547d0dc0f01713ba60b7070d2eba2d48fc1ba3a
|
Provenance
The following attestation bundles were made for snail_lang-0.9.1-cp38-abi3-win_amd64.whl:
Publisher:
release.yml on sudonym1/snail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
snail_lang-0.9.1-cp38-abi3-win_amd64.whl -
Subject digest:
74c0a68bb7a5335f58ab118dbced13941ec670b3d26de268c0ebe55436475036 - Sigstore transparency entry: 1100539614
- Sigstore integration time:
-
Permalink:
sudonym1/snail@e26dee7b9b80726eaad26ddb7308d0a91b4fa030 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/sudonym1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e26dee7b9b80726eaad26ddb7308d0a91b4fa030 -
Trigger Event:
push
-
Statement type:
File details
Details for the file snail_lang-0.9.1-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: snail_lang-0.9.1-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c65ddad5be263408f3ab439e8b8ce7008cfec19d135086b4f71648b69afd6eef
|
|
| MD5 |
a0aa1a3583ad4dd26542999434a95f42
|
|
| BLAKE2b-256 |
7db99425c1960d285c445d3935fdcbe45cf9b91caa35a25ac9c2972038cff8b2
|
Provenance
The following attestation bundles were made for snail_lang-0.9.1-cp38-abi3-manylinux_2_34_x86_64.whl:
Publisher:
release.yml on sudonym1/snail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
snail_lang-0.9.1-cp38-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
c65ddad5be263408f3ab439e8b8ce7008cfec19d135086b4f71648b69afd6eef - Sigstore transparency entry: 1100539539
- Sigstore integration time:
-
Permalink:
sudonym1/snail@e26dee7b9b80726eaad26ddb7308d0a91b4fa030 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/sudonym1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e26dee7b9b80726eaad26ddb7308d0a91b4fa030 -
Trigger Event:
push
-
Statement type:
File details
Details for the file snail_lang-0.9.1-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: snail_lang-0.9.1-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 667.5 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa799f8c7a5329ffa82c26b53535a465621e9096c3bde29b5a6859701cf113c8
|
|
| MD5 |
dcda8f3d99f1ea67a69eed3500fd8b91
|
|
| BLAKE2b-256 |
cba8d5f3db1a00a25a7c36ca35f09f86143889b3feb4a158c0632af57302150b
|
Provenance
The following attestation bundles were made for snail_lang-0.9.1-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on sudonym1/snail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
snail_lang-0.9.1-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
aa799f8c7a5329ffa82c26b53535a465621e9096c3bde29b5a6859701cf113c8 - Sigstore transparency entry: 1100539682
- Sigstore integration time:
-
Permalink:
sudonym1/snail@e26dee7b9b80726eaad26ddb7308d0a91b4fa030 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/sudonym1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e26dee7b9b80726eaad26ddb7308d0a91b4fa030 -
Trigger Event:
push
-
Statement type: