Add direct SWI-Prolog Tree-sitter FFI #111

Merged
lost-rob0t merged 6 commits from agent/94-tree-sitter-ffi into main 2026-08-19 04:10:25 +00:00
lost-rob0t commented 2026-08-19 03:53:12 +00:00 (Migrated from github.com)

Summary

Implements issue #94 as the first source-analysis slice.

  • binds SWI-Prolog directly to libtree-sitter through a small C FLI layer
  • adds generic dynamic grammar loading through library path + exported grammar symbol
  • represents language/parser/tree/node resources with owned SWI foreign handles rather than naked pointers
  • preserves tree lifetime for reachable nodes and rejects stale/closed handles structurally
  • exposes parser creation, language assignment, string parsing, root lookup, node type/range/child/named-child/field traversal, and error inspection
  • enforces documented parser/tree thread affinity under SWI threads
  • supports Tree-sitter runtime/language ABI compatibility checks
  • adds deterministic fixtures using C, Lua, and Tree-sitter Query grammars through the same generic FFI
  • adds malformed-source, Unicode byte/point, stale-node, ABI-negative, lifetime/finalization, and thread-affinity coverage
  • adds a dedicated Ubuntu native-build CI workflow and build/documentation support

Runtime invariant

The C layer owns only Tree-sitter mechanics and native lifetime. Project/file facts, language detection, CST projection, query packs, semantic normalization, SPEC, and VERIFY remain Prolog concerns. Adding another compatible grammar must not require language-specific C code.

No Python, Node, Nim, subprocess parser service, or language-specific semantic visitor is introduced.

Verification

The branch has a dedicated Tree-sitter FFI workflow that installs SWI-Prolog, the Tree-sitter development package, and packaged generated grammar sources; builds the foreign library and fixture grammars; runs the focused PlUnit suite; and checks the exact commit diff for whitespace errors.

The repository's normal PR workflow remains the canonical full deterministic/live merge gate. Merge is allowed only for the exact final head after both workflows pass.

Follow-up

#95 owns the declarative Project/File/Language/grammar registry above this mechanical layer. #96-#99 own versioned CST facts, queries/captures, semantic normalization, and incremental freshness respectively.

Closes #94

## Summary Implements issue #94 as the first source-analysis slice. - binds SWI-Prolog directly to `libtree-sitter` through a small C FLI layer - adds generic dynamic grammar loading through library path + exported grammar symbol - represents language/parser/tree/node resources with owned SWI foreign handles rather than naked pointers - preserves tree lifetime for reachable nodes and rejects stale/closed handles structurally - exposes parser creation, language assignment, string parsing, root lookup, node type/range/child/named-child/field traversal, and error inspection - enforces documented parser/tree thread affinity under SWI threads - supports Tree-sitter runtime/language ABI compatibility checks - adds deterministic fixtures using C, Lua, and Tree-sitter Query grammars through the same generic FFI - adds malformed-source, Unicode byte/point, stale-node, ABI-negative, lifetime/finalization, and thread-affinity coverage - adds a dedicated Ubuntu native-build CI workflow and build/documentation support ## Runtime invariant The C layer owns only Tree-sitter mechanics and native lifetime. Project/file facts, language detection, CST projection, query packs, semantic normalization, SPEC, and VERIFY remain Prolog concerns. Adding another compatible grammar must not require language-specific C code. No Python, Node, Nim, subprocess parser service, or language-specific semantic visitor is introduced. ## Verification The branch has a dedicated `Tree-sitter FFI` workflow that installs SWI-Prolog, the Tree-sitter development package, and packaged generated grammar sources; builds the foreign library and fixture grammars; runs the focused PlUnit suite; and checks the exact commit diff for whitespace errors. The repository's normal PR workflow remains the canonical full deterministic/live merge gate. Merge is allowed only for the exact final head after both workflows pass. ## Follow-up #95 owns the declarative Project/File/Language/grammar registry above this mechanical layer. #96-#99 own versioned CST facts, queries/captures, semantic normalization, and incremental freshness respectively. Closes #94
Sign in to join this conversation.
No description provided.