# codeant-ai/tree-sitter-plsql architecture

> Architecture diagram of the GitHub repository codeant-ai/tree-sitter-plsql, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codeant-ai/tree-sitter-plsql
- Repository: https://github.com/codeant-ai/tree-sitter-plsql

## Overview

##### Project type and purpose
- This is an open-source grammar and parser binding project for PL/SQL, built on top of the Tree-Sitter parsing framework.
- It provides:
- A language grammar definition (grammar.js + JSON)
- A generated C parser (src/parser.c, src/tree_sitter/parser.h)
- Bindings for Node.js (bindings/node) and Rust (bindings/rust)
- Examples and a corpus for testing and demonstration

##### File structure
Top-level artifacts:
- binding.gyp, package.json – Node.js build configuration
- Cargo.toml – Rust crate configuration
- grammar.js, src/grammar.json, src/node-types.json – grammar definitions
- src/parser.c + src/tree_sitter/parser.h – generated C parser code
- bindings/node/ – Node.js integration: binding.cc, index.js
- bindings/rust/ – Rust integration: build.rs, lib.rs
- corpus/ + examples/ – test inputs and usage samples

Architectural patterns:
- Code generation pipeline: grammar → JSON → C parser
- Multi-language bindings (polyglot library design)
- Separation of “core parser” and “language-specific bindings”

##### Key insights from the README
- Project goal: syntax highlighting and parsing of Oracle PL/SQL in editors (e.g., Neovim)
- Status: under active development; supports major DDL/DML statements
- Dependencies: Tree-Sitter core, Node.js, Rust toolchain

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Grammar Definition Layer
    subgraph "Grammar Definition Layer"
        GRAMJS["grammar.js"]:::definition
        GRAMJSON["grammar.json"]:::definition
        NODESPEC["node-types.json"]:::definition
    end
    click GRAMJS "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//grammar.js"
    click GRAMJSON "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//src/grammar.json"
    click NODESPEC "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//src/node-types.json"

    %% Parser Generation Engine
    subgraph "Parser Generation Engine"
        TSCli["Tree-Sitter CLI"]:::external
        PARSEC["parser.c"]:::engine
        PARSEH["parser.h"]:::engine
    end
    click PARSEC "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//src/parser.c"
    click PARSEH "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//src/tree_sitter/parser.h"

    %% Core Parser Library
    subgraph "Core Parser Library (C)"
        CORE["Core Parser Library"]:::engine
    end

    %% Bindings Layer
    subgraph "Bindings"
        subgraph "Node.js Binding"
            GYP["binding.gyp"]:::binding
            BCC["binding.cc"]:::binding
            IDX["index.js"]:::binding
            PKG["package.json"]:::binding
        end
        subgraph "Rust Binding"
            CTOML["Cargo.toml"]:::binding
            BRS["build.rs"]:::binding
            LRS["lib.rs"]:::binding
        end
    end
    click GYP "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//binding.gyp"
    click BCC "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//bindings/node/binding.cc"
    click IDX "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//bindings/node/index.js"
    click PKG "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//package.json"
    click CTOML "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//Cargo.toml"
    click BRS "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//bindings/rust/build.rs"
    click LRS "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//bindings/rust/lib.rs"

    %% Clients / Consumers
    subgraph "Clients / Consumers"
        EDITOR["Editor Plugin (Neovim)"]:::client
        EXAMPLES["Examples (.sql)"]:::client
        CORPUSDIR["corpus"]:::client
        TESTTXT["test.txt"]:::client
    end
    click EXAMPLES "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//examples/*.sql"
    click CORPUSDIR "https://github.com/codeant-ai/tree-sitter-plsql/tree/main//corpus"
    click TESTTXT "https://github.com/codeant-ai/tree-sitter-plsql/blob/main//corpus/test.txt"

    %% Data Flows
    GRAMJS -->|"grammar.js"| TSCli
    GRAMJSON -->|"grammar.json"| TSCli
    NODESPEC -->|"node-types.json"| TSCli

    TSCli -->|"generated C code"| PARSEC
    TSCli -->|"generated headers"| PARSEH

    PARSEC -->|"compiles"| CORE
    PARSEH -->|"compiles"| CORE

    CORE -->|"linked by node-gyp"| GYP
    CORE -->|"linked by Cargo"| CTOML

    GYP -->|"compiles native addon"| BCC
    BCC -->|"wrapped by"| IDX
    PKG -->|"metadata"| IDX

    CTOML -->|"build script"| BRS
    BRS -->|"generates bindings"| LRS

    IDX -->|"exposed API"| EDITOR
    IDX -->|"usage samples"| EXAMPLES

    LRS -->|"exposed API"| EDITOR
    LRS -->|"usage samples"| EXAMPLES

    EXAMPLES -->|"SQL input"| CORE
    TESTTXT -->|"test input"| CORE

    %% Styles
    classDef definition fill:#E0F7FA,stroke:#0288D1,color:#01579B
    classDef engine fill:#C8E6C9,stroke:#2E7D32,color:#1B5E20
    classDef binding fill:#FFE0B2,stroke:#EF6C00,color:#E65100
    classDef client fill:#EEEEEE,stroke:#757575,color:#424242
    classDef external fill:#CFD8DC,stroke:#607D8B,color:#37474F
```
