Repository navigation
Description
Feature: Oracle PL/SQL Support via tree-sitter-plsql
Summary
Add first-class Oracle PL/SQL support to graphify by integrating the njank/tree-sitter-plsql grammar, enabling extraction of packages, functions, procedures, and their table dependencies from .sql, .pkb, .pks, .pls, and .plb files.
Motivation
Many enterprise codebases use Oracle databases with PL/SQL packages — bundles of stored procedures, functions, cursors, and types. These packages are the "glue logic" between application code and database schemas. Without PL/SQL support, graphify cannot see this critical middle layer.
The existing tree_sitter_sql grammar handles standard SQL DDL (CREATE TABLE/VIEW) but cannot parse Oracle PL/SQL constructs like CREATE PACKAGE BODY, CREATE FUNCTION, PROCEDURE, FORALL, BULK COLLECT, REF CURSOR, or Oracle-specific outer join syntax.
Tree-Sitter Grammar: njank/tree-sitter-plsql
A fork of andreasmaierde/tree-sitter-plsql (12 ★) with significant enhancements for enterprise Oracle codebases:
| Feature | Status |
|---|---|
| CREATE [OR REPLACE] PACKAGE / PACKAGE BODY | ✅ |
| FUNCTION/PROCEDURE declarations (spec) and definitions (body) | ✅ |
| Parameters with IN/OUT/IN OUT and %TYPE | ✅ |
| CREATE TABLE/VIEW with constraints, REFERENCES | ✅ |
| Embedded DML (SELECT, INSERT, UPDATE, DELETE, MERGE) | ✅ |
| CURSOR definitions, TYPE definitions (REF CURSOR, collections) | ✅ |
| FORALL, BULK COLLECT | ✅ |
| Conditional compilation ($IF/$THEN/$ELSE) | ✅ |
| Analytic functions with OVER/ WITHIN GROUP | ✅ |
| Oracle (+) outer joins | ✅ |
| Quoted identifiers, EDITIONABLE packages | ✅ |
| External scanner for Oracle keyword disambiguation | ✅ |
Evidence: Python Bindings Work
I built Python bindings for this grammar (following the same pattern as tree_sitter_sql) and tested against production Oracle PL/SQL:
| Test file | Error rate | Notes |
|---|---|---|
| Clean hand-written spec | 0.0% | No grammar bugs on valid PL/SQL |
| Hand-written spec with EDITIONABLE + quoted schema | 0.0% | Handles enterprise patterns |
| Advanced constructs (REF CURSOR, FORALL, analytic) | 0.0% | Full coverage |
XXDB_EPP_PRJ.pkb (204 KB production body) |
0.98% | All errors are line-truncation artifacts from extraction, not grammar |
Various extracted .pkb files (avg 23-56 KB) |
<5.5% | All errors are truncated-line artifacts (80-char line split) |
Critically: on clean Oracle PL/SQL, the grammar parses with 0% error rate. The errors seen are from SQL*Plus extraction artifacts where long lines were truncated mid-identifier.
Proposed Integration
1. Python package
The njank/tree-sitter-plsql grammar compiles to a C .so and exports language() as a PyCapsule, matching the tree_sitter_sql API exactly. The package structure:
tree-sitter-plsql/
├── pyproject.toml # setuptools build (C extension)
├── binding.c # Python capsule wrapper
├── src/
│ ├── parser.c # Generated parser (1.44M lines, committed)
│ ├── scanner.c # 57-keyword external scanner (committed)
│ └── ...
└── tree_sitter_plsql/
├── __init__.py # Same pattern as tree_sitter_sql
└── queries/
Currently built as an editable install; ready for PyPI publication.
2. Changes to graphify upstream
graphify/extractors/sql.py (~50-80 lines added)
- Try
tree-sitter-plsqlfirst, fall back totree_sitter_sql - Handle PL/SQL-specific node types:
create_package,create_package_body,function_declaration,procedure_declaration,function_definition,procedure_definition,cursor_definition,type_definition_* - Walk SQL statements embedded inside PL/SQL bodies for table references
- Adapt to different node naming (e.g.,
identifierinstead ofobject_referencefor table names)
Node type mapping:
| Concept | tree_sitter_sql |
tree-sitter-plsql |
|---|---|---|
| Table name | object_reference |
identifier |
| Column def | column_definition |
table_column_definition |
| FK constraint | keyword_references |
constraint_references |
| Function (spec) | create_function |
function_declaration |
| Procedure (spec) | create_procedure |
procedure_declaration |
| Function (body) | — | function_definition |
| Procedure (body) | — | procedure_definition |
| Package | — | create_package / create_package_body |
| Statement wrapper | statement |
not used (top-level) |
graphify/detect.py (~5 lines)
Add .pkb, .pks, .pls, .plb to CODE_EXTENSIONS and the extension→extractor mapping.
pyproject.toml (~2 lines)
Add tree-sitter-plsql as an optional dependency alongside tree-sitter-sql.
Next Steps
- Publish
tree-sitter-plsqlon PyPI (can be under any org/account) - Submit PR to graphify with the extractor + detect changes
- Add queries (highlights.scm, locals.scm, tags.scm) for code navigation
I have a working prototype with the compiled bindings, tested against production code. Happy to submit a PR with the integration once the package is published.
Related
- Grammar repo:
github.com/njank/tree-sitter-plsql - Upstream grammar (original):
github.com/andreasmaierde/tree-sitter-plsql
Activity
ezadEzanee commentedon Jul 18, 2026
Integration Update — Working Prototype ✅
The extraction, detection, and graph building pipeline has been verified end-to-end on production Oracle PL/SQL code.
What's been done
create_package,create_package_body, function/procedure declarations/definitions, cursor definitions, type definitionsPACKAGE BODY name(withoutCREATE OR REPLACE) are recovered via regex scanning — critical for real-world codebases where extraction pipelines strip the header.pkb,.pks,.pls,.plbadded to CODE_EXTENSIONSgraphify update .on a .pkb file correctly extracts package, procedures, and functions into the graphTested with production code
Next steps for PR readiness
tree-sitter-plsqlto PyPI so graphify can declare it as an optional dependencylocals.scmandtags.scmqueries for code navigation featurescmalek commentedon Aug 4, 2026
this would be extremely handy for me also