Skip to main content

tree-sitter-swi-prolog

Kibi requirement health

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 as dynamic, discontiguous, meta_predicate, multifile and table
  • operators from common libraries: library(clpfd) (#=, in, .., ...), library(chr) (<=>, ==>, \), library(semweb/rdf_db) (^^), library(wasm) (#Value, Expr[Index]) and the rdf_meta, persistent, record and html_meta declarations
  • dicts (_{name: "x"}, Tag{...}) and functional notation on dicts (D.key, D.put(k, V))
  • strings, back-quoted strings, 0'c character 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 ===> Y or X 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 ERROR node 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) or foo(a|b) are errors

A negative number literal is parsed as the prefix operator - applied to the number.

Queries

  • queries/highlights.scm: syntax highlighting
  • queries/tags.scm: predicate definitions (clause heads, including module-qualified heads and single-sided-unification heads with guards), module declarations, and calls. @name is 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

Changes are listed in CHANGELOG.md. To release:

  1. In a pull request, bump the version (npx tree-sitter version X.Y.Z, then npm install --package-lock-only) and add a ## X.Y.Z section to CHANGELOG.md. CI checks that the manifests and the changelog agree.
  2. Merge it, then run the Release workflow on main from the Actions tab.

The workflow refuses a version that is already tagged. It creates the vX.Y.Z tag and GitHub release, with the changelog section as notes and the Wasm parser attached, and publishes to npm, crates.io and PyPI. Don't create tags or releases by hand.

License

MIT

Metadata

Release files for tree-sitter-swi-prolog 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree-sitter-swi-prolog 0.1.0
File Size Uploaded Provenance Actions
tree_sitter_swi_prolog-0.1.0.tar.gz 105.9 kB Without provenance Details for tree_sitter_swi_prolog-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-swi-prolog 0.1.0
File Actions
tree_sitter_swi_prolog-0.1.0-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details for tree_sitter_swi_prolog-0.1.0-cp310-abi3-win_arm64.whl
tree_sitter_swi_prolog-0.1.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for tree_sitter_swi_prolog-0.1.0-cp310-abi3-win_amd64.whl
tree_sitter_swi_prolog-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for tree_sitter_swi_prolog-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
tree_sitter_swi_prolog-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for tree_sitter_swi_prolog-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
tree_sitter_swi_prolog-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64, Linux glibc 2.17+ ARM64 Details for tree_sitter_swi_prolog-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
tree_sitter_swi_prolog-0.1.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl CPython 3.10 abi3 Linux glibc 2.5+ x86-64, Linux glibc 2.28+ x86-64 Details for tree_sitter_swi_prolog-0.1.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
tree_sitter_swi_prolog-0.1.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for tree_sitter_swi_prolog-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
tree_sitter_swi_prolog-0.1.0-cp310-abi3-macosx_10_9_x86_64.whl CPython 3.10 abi3 macOS 10.9+ x86-64 Details for tree_sitter_swi_prolog-0.1.0-cp310-abi3-macosx_10_9_x86_64.whl

Total release size: 615.7 kB

Release files / tree_sitter_swi_prolog-0.1.0.tar.gz

Download URL tree_sitter_swi_prolog-0.1.0.tar.gz
Size 105.9 kB
Tags Source
SHA-256 checksum
How to use checksums
aab3f268525d619c40b166f43bc3ca18bb96b5b6acaf5721e53a16e6e22a3683
BLAKE2b-256 checksum
How to use checksums
556fa478e87b23a222172dec5e7d790bb0b212b7da151aa6fc22f93acc0cacd1
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.0-cp310-abi3-win_arm64.whl

Download URL tree_sitter_swi_prolog-0.1.0-cp310-abi3-win_arm64.whl
Size 40.2 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
342b0dd2aba5052cc2351abc688511e531f0ada8b75ce8b28530aa1364f9c872
BLAKE2b-256 checksum
How to use checksums
f5c3c57d694c63f1627b8748c2af7d0bbe4e1ab607e72730782753aa8f4a7220
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.0-cp310-abi3-win_amd64.whl

Download URL tree_sitter_swi_prolog-0.1.0-cp310-abi3-win_amd64.whl
Size 39.4 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
9f543252c61f7812201416868ab0a845e1a9c23e58aa272daabbc00bfd5d9acf
BLAKE2b-256 checksum
How to use checksums
398212f25a652d4b86cf2bdf99da8b6ec676f52cf32f49c7a4ca019de308b945
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.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_swi_prolog-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 81.7 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
f3c22665d8d4c05a86f0bec72a3430e6cd6ce90afbd9bbc610b10c5eeb43b9d0
BLAKE2b-256 checksum
How to use checksums
639dcc6f4c1cfcfcc8aa653a6633843fb23ed68e55dacd95693057a6bdf93b88
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.0-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_swi_prolog-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
Size 88.5 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
caadbb88c0ac97d2b29b187bc49c2f3a0b0840bbb0ddb5508c50995e2e55c06c
BLAKE2b-256 checksum
How to use checksums
1d637edb094fa281e56cc604404f7ca8577eb04a0de234c0c12d02ca471eae63
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.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_swi_prolog-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 90.4 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
5334e2972f108e9321b2fe0ce3f2fea526fc06ffe71d85b424568a3c3abd98be
BLAKE2b-256 checksum
How to use checksums
a8984c65d2980a23d3febc4792f960267099475d80cc5f7e23a7bab613804f02
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.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_swi_prolog-0.1.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 86.5 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
05fef9153d0384b12875db0fc037e226aecd3966c1741fbae140114d8c541255
BLAKE2b-256 checksum
How to use checksums
199602131ad273a8eca58727d70dc1e28d695b995bd1534244251ab9fd66105d
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.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_swi_prolog-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Size 42.2 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d944192d3eb0ae4850a47ef2ac208e349e2e29967ec4954d898737a9d2ec4990
BLAKE2b-256 checksum
How to use checksums
7b9b11b71273669d94384588db7cd0fd9c5d4bfed3a9c64f3216036bc19aa669
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.0-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_swi_prolog-0.1.0-cp310-abi3-macosx_10_9_x86_64.whl
Size 40.7 kB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
bfb95e12f9b4488344ebe9c94886dca9995d60e001d926f98e0db3bdc94b5881
BLAKE2b-256 checksum
How to use checksums
909f151e1f6cf1377799b2ee510c8a4b13803c8bb74108fc3c75b9fde1a4acb9
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.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page