tree-sitter-swi-prolog
SWI-Prolog grammar for tree-sitter.
It parses the Prolog that real SWI-Prolog projects are written in, not only ISO core:
- the default SWI-Prolog operator table, including
:module qualification,=>single-sided unification,=@=,>:<,:<,as,$, and declaration prefixes such asdynamic,discontiguous,meta_predicate,multifileandtable - operators from common libraries:
library(clpfd)(#=,in,.., ...),library(chr)(<=>,==>,\),library(semweb/rdf_db)(^^),library(wasm)(#Value,Expr[Index]) and therdf_meta,persistent,recordandhtml_metadeclarations - dicts (
_{name: "x"},Tag{...}) and functional notation on dicts (D.key,D.put(k, V)) - strings, back-quoted strings,
0'ccharacter codes, radix integers (16'FF), digit groups (1 000 000), rationals (1r3) and special floats (1.0Inf) - Unicode atoms and variables, multi-line quoted text,
%and/* */comments, and a leading#!line
Clauses are structured for tools: every top-level term is a clause (with head, neck and body fields), a directive or a query.
max(X, Y, X) :- X >= Y, !.
(clause
head: (compound_term functor: (atom) arguments: (arguments (variable) (variable) (variable)))
neck: (operator)
body: (binary_operation left: (binary_operation ...) operator: (operator) right: (atom))
(end))
Coverage
CI parses SWI-Prolog's own boot/ and library/ sources and fails if fewer than 99.5% of top-level terms parse without errors. On SWI-Prolog's current boot/ and library/ 99.88% of terms parse cleanly, and on the full SWI-Prolog 10.0.2 library with packages (413 files, about 240,000 lines) 99.91%; the rest use prefix operators their files declare themselves.
Limits
A tree-sitter grammar has a fixed operator table, so operators declared at load time with op/3 are not known while parsing:
- an unknown infix operator between two operands, symbolic or alphanumeric (for example
X ===> YorX cis Y), is read as an infix operator at priority 700, so the clause still parses, with the grouping that priority gives - unknown prefix and postfix operators produce an
ERRORnode for that term only; the parser recovers at the next clause - the parser does not lower operator priorities the way SWI-Prolog does in some argument positions, so
foo(:- a)orfoo(a|b)are errors
A negative number literal is parsed as the prefix operator - applied to the number.
Queries
queries/highlights.scm: syntax highlightingqueries/tags.scm: predicate definitions (clause heads, including module-qualified heads and single-sided-unification heads with guards), module declarations, and calls.@nameis the predicate name without arity; count the head's arguments for the arity, and add two for DCG rules (neck-->)queries/locals.scm: variables are local to their clause, directive or query
Usage
Node, Rust, Python, Go, Swift and C bindings are generated by tree-sitter init. For the browser or other WebAssembly hosts, build the parser with:
npx tree-sitter build --wasm
and load tree-sitter-swi_prolog.wasm with web-tree-sitter.
Development
npm install
npx tree-sitter generate
npx tree-sitter test
npx tree-sitter build --wasm
node scripts/check-corpus.mjs path/to/prolog/sources
grammar.js lists the operator tables at the top. To support another library's operators, add them to the matching table with their SWI-Prolog priority and type.
Releasing
Releases are made from changesets.
- A pull request with a user-visible change adds a changeset: run
npx changeset, pick the bump and describe the change for users. CI fails a pull request without a changeset; for a change users don't see, add an empty one withnpx changeset --empty. - When it is merged, the Release workflow opens (or updates) a Version packages pull request that applies all pending changesets: it bumps the version in every manifest and writes their text into
CHANGELOG.md. - Merging that pull request releases the new version: the
vX.Y.Ztag and GitHub release (with the changelog section as notes and the Wasm parser attached), npm, crates.io and PyPI.
The release step publishes only what is missing for the current version, so if a registry fails, run the Release workflow again from the Actions tab. Don't create tags or releases by hand.
License
MIT
Metadata
Release files for tree-sitter-swi-prolog 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tree_sitter_swi_prolog-0.1.2.tar.gz | 109.5 kB | Without provenance | Details for tree_sitter_swi_prolog-0.1.2.tar.gz |
Built distributions (wheels)
Total release size: 630.7 kB
Release files / tree_sitter_swi_prolog-0.1.2.tar.gz
| Download URL | tree_sitter_swi_prolog-0.1.2.tar.gz |
|---|---|
| Size | 109.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca128d9392c49985b9ed92fa39f062f8fd91158493f75e9480f175c9c644a5d9
|
|
BLAKE2b-256 checksum How to use checksums |
4acc6896dab16c7188c6f9f74d72728b2b7f477541cffd8e3877c99200e85e22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / tree_sitter_swi_prolog-0.1.2-cp310-abi3-win_arm64.whl
| Download URL | tree_sitter_swi_prolog-0.1.2-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 41.6 kB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
08bce611e006cfdafd393ac28a0fa83212e8b980099a389859c0e7098f0068bd
|
|
BLAKE2b-256 checksum How to use checksums |
ee78842e3a039694bb001428a258c058a5ff623522298a09e474308d1ede659c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / tree_sitter_swi_prolog-0.1.2-cp310-abi3-win_amd64.whl
| Download URL | tree_sitter_swi_prolog-0.1.2-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 40.9 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
fd77dee56f5521c6fd09b27ead011ae64241b07ed5c647e2fb50793c626a86b5
|
|
BLAKE2b-256 checksum How to use checksums |
8b9c73af0b0d2fe4051564d3555b8fa7e99e50511c71e97b82a7ab491690955a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / tree_sitter_swi_prolog-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | tree_sitter_swi_prolog-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 83.2 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
4df2edea9bb56b0a466f5acdcabb406b1282a2202866e0d48a54f1be4e856a80
|
|
BLAKE2b-256 checksum How to use checksums |
429526d9e06e3fc83b00fc7516872b226fc22a369b41b392ba3f514314f0dfde
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / tree_sitter_swi_prolog-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | tree_sitter_swi_prolog-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 89.9 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
3247f6b4741a1da90799f4ba2d94ee08df2e996d0dd117637ab10c2858642b5e
|
|
BLAKE2b-256 checksum How to use checksums |
484050e0ed1aed84ac111c0100214880b1f5825f995a99dfd52fa78219e5ef06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / tree_sitter_swi_prolog-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
| Download URL | tree_sitter_swi_prolog-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 91.8 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
d68039ccf48922c9e6d7503d4d1536390275929c4ae29bf0b3fcc2f6eae75a66
|
|
BLAKE2b-256 checksum How to use checksums |
ca2e3c2fc62efff8e60264674d4283b6637fa45202ee910e7831dcbf7b6044dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / tree_sitter_swi_prolog-0.1.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
| Download URL | tree_sitter_swi_prolog-0.1.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl |
|---|---|
| Size | 88.0 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
3da1c4c2c3d9ececc62e2fcb70999fd42c9ad0b9476568e267c24fb0467c0d85
|
|
BLAKE2b-256 checksum How to use checksums |
b7a4ccd8eecb6682e97d42fef70df148fbbe89fe84732b77f09209435d7719dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / tree_sitter_swi_prolog-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | tree_sitter_swi_prolog-0.1.2-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 43.6 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c6b7837a9aed92fe60e78962d3dafdd2fed9c0969669f1a15ab0d0f03eeb7fc0
|
|
BLAKE2b-256 checksum How to use checksums |
cca0ded2313d44eecdc5163ae47afeee1d5c535053c4ae86e998cc2d84749175
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / tree_sitter_swi_prolog-0.1.2-cp310-abi3-macosx_10_9_x86_64.whl
| Download URL | tree_sitter_swi_prolog-0.1.2-cp310-abi3-macosx_10_9_x86_64.whl |
|---|---|
| Size | 42.1 kB |
| Tags | CPython 3.10 abi3 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
a0f737cf53a6ca40922e153081f821131a928f1b5d925a9f49ab34c0b0aece91
|
|
BLAKE2b-256 checksum How to use checksums |
a0b46fc87dc0ba5f998991889da42aaf7cb3fed1e9d99532c1068cc0c8950cd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for tree-sitter-swi-prolog 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.