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
  • the clause terminator: a . followed by layout (any Unicode white space character), a % comment or the end of the input ends the clause, and a . followed by any other character does not, as in a.b or X =.. L

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
npm run test:unit
node scripts/check-corpus.mjs path/to/prolog/sources

The unit tests in test/unit/ cover all of the project's own code: grammar.js and grammar/ (every node type, field and child type in src/node-types.json is produced by a sample), the queries (every pattern matches), src/scanner.c (with a C unit test) and the scripts. npm run coverage runs them and fails below 100% (it needs gem install bashcov for the shell scripts). npm run mutation runs mutation testing: Stryker on the JavaScript, regenerating the parser for each grammar mutant, and test/mutation/mutants.mjs on src/scanner.c and the shell scripts.

grammar/operators.js lists the operator tables. 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.

  1. 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 with npx changeset --empty.
  2. 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.
  3. Merging that pull request releases the new version: the vX.Y.Z tag 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.3

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.3
File Size Uploaded Provenance Actions
tree_sitter_swi_prolog-0.1.3.tar.gz 110.0 kB Without provenance Details for tree_sitter_swi_prolog-0.1.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-swi-prolog 0.1.3
File Actions
tree_sitter_swi_prolog-0.1.3-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details for tree_sitter_swi_prolog-0.1.3-cp310-abi3-win_arm64.whl
tree_sitter_swi_prolog-0.1.3-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for tree_sitter_swi_prolog-0.1.3-cp310-abi3-win_amd64.whl
tree_sitter_swi_prolog-0.1.3-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.3-cp310-abi3-musllinux_1_2_x86_64.whl
tree_sitter_swi_prolog-0.1.3-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for tree_sitter_swi_prolog-0.1.3-cp310-abi3-musllinux_1_2_aarch64.whl
tree_sitter_swi_prolog-0.1.3-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.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
tree_sitter_swi_prolog-0.1.3-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.3-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
tree_sitter_swi_prolog-0.1.3-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for tree_sitter_swi_prolog-0.1.3-cp310-abi3-macosx_11_0_arm64.whl
tree_sitter_swi_prolog-0.1.3-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.3-cp310-abi3-macosx_10_9_x86_64.whl

Total release size: 654.4 kB

Release files / tree_sitter_swi_prolog-0.1.3.tar.gz

Download URL tree_sitter_swi_prolog-0.1.3.tar.gz
Size 110.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6327327b90590192f3860b870f48fb378580d073cd39235210c92f0822a0fb92
BLAKE2b-256 checksum
How to use checksums
767b789f8486ae5d3587141b7fe8eff3cb337235e879505bb10ada38657c6657
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.3-cp310-abi3-win_arm64.whl

Download URL tree_sitter_swi_prolog-0.1.3-cp310-abi3-win_arm64.whl
Size 42.6 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
706eae7e1dafc116872bf51d5d9830dedf8fa3f288a3a75e8a0325afe5b89eb8
BLAKE2b-256 checksum
How to use checksums
8e0b63c871b8e69e304496aceafdc792cb4ecf43fb7432def35d2be2c157b3c5
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.3-cp310-abi3-win_amd64.whl

Download URL tree_sitter_swi_prolog-0.1.3-cp310-abi3-win_amd64.whl
Size 41.5 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
237ed4c6cf74aa7f6b44d318faa6628c4988c80b77ce434eb6b7d6108152a0f0
BLAKE2b-256 checksum
How to use checksums
11b4c508a042ca59fc46cd1ce7aadec6d8d25ddb246f7e6b3597ba6c7f4b04e8
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.3-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_swi_prolog-0.1.3-cp310-abi3-musllinux_1_2_x86_64.whl
Size 88.0 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
fe6b79291edf0a55e7f07d29c844434e3724dace2db0f2ceff49edbecd1a41e4
BLAKE2b-256 checksum
How to use checksums
8da5171188cab7b58dce54c5f845ed9747ebf31f8920190081321a01b0b0901d
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.3-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_swi_prolog-0.1.3-cp310-abi3-musllinux_1_2_aarch64.whl
Size 94.8 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
50f16f693610bc12eea7f110db69f2498f4189a7023bc04904e1266f55210e0c
BLAKE2b-256 checksum
How to use checksums
999c03df1db988a4597edda983899afad51e415839287ab882c03101ab816f7b
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.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_swi_prolog-0.1.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 96.4 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
d64cb71e88d8f505c8c94e368cade945d91d21fb33e2bac2c0a6ee5fab725302
BLAKE2b-256 checksum
How to use checksums
2411192aec6054bf432cd8084b4c3a749c3a460e88744f29d715980ff292116e
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.3-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_swi_prolog-0.1.3-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 93.1 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
e7f3a5e9cac86d5373ad688a639c9e9a77700d95805ca8043956267b3d32f6e8
BLAKE2b-256 checksum
How to use checksums
8ca19a86c4e8d08a3ddd9248f72d80db3d5eb061ee3814370f453f912834544d
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.3-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_swi_prolog-0.1.3-cp310-abi3-macosx_11_0_arm64.whl
Size 44.1 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
69fa2deeb48dc080f1ccd4aec4d1dc29cc3fcd52f92fc406b81f3c7942f7563e
BLAKE2b-256 checksum
How to use checksums
234dcc4674e5cfe7eb7086e3c72dd96fd4026d83e0ba87002b4a2f330f9988fd
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.3-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_swi_prolog-0.1.3-cp310-abi3-macosx_10_9_x86_64.whl
Size 43.8 kB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
2ef0968c653dfdfd8cc52f250c66b629775fc3b6e85e6cc72ee6ec60fb81c23c
BLAKE2b-256 checksum
How to use checksums
346835bdf9f3e4331382e1d298c5d141ccaae9fd2ec61ba12170a9959b6e2454
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.3

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