# pest-parser/pest architecture

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

- Interactive diagram: https://gitdiagram.com/pest-parser/pest
- Repository: https://github.com/pest-parser/pest

## Overview

##### Main Components Identification

a. Core Components:
- pest (core library)
- pest_derive (procedural macros)
- meta (grammar parser)
- vm (virtual machine)
- generator (code generator)
- grammars (predefined grammar implementations)
- debugger (debugging utilities)

**Top Level (User Interface):**
- Grammar Files (.pest) ─────┐
- Rust Source Files     ─────┤
- ↓
**Processing Layer:**
- pest_derive (macro processing) ←→ meta (grammar parsing)
- ↓
**Core Implementation:**
- pest (core library) ←→ vm (virtual machine)
- ↓
**Output Layer:**
- Generated Parser Implementation

##### Component Relationships

a. Primary Flow:
- Grammar files (.pest) are processed by the meta component
- Rust source code interacts with pest_derive
- pest_derive uses meta for grammar parsing
- The core pest library provides the runtime parsing functionality
- The vm component handles the parsing execution

b. Secondary Relationships:
- generator works with pest_derive for code generation
- debugger interfaces with the vm and core pest components
- grammars provides pre-built grammar implementations

##### Additional Details

Important aspects:

- Parser Generation Pipeline:
Transformation from .pest files to working parser code
- Error Reporting System:
How error reporting flows through the system
- Testing Components:
Relationship with fuzzing and testing infrastructure

##### Technical Notes

Annotations for:
- Rust version requirements (1.61.0+)
- no_std support capabilities
- Key dependencies and integrations
- Performance characteristics

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        GF[".pest Grammar Files"]
        RS["Rust Source Files"]
    end

    subgraph "Processing Layer"
        PD["pest_derive"]
        META["meta"]
        GEN["generator"]
        
        subgraph "Meta Components"
            GDEF["Grammar Definition"]
            PARS["Parser Implementation"]
            OPT["Optimizer"]
        end
    end

    subgraph "Core Layer"
        PEST["pest Core"]
        VM["Virtual Machine"]
        
        subgraph "Core Components"
            ERR["Error Handler"]
            PST["Parser State"]
            TOK["Token Processor"]
            UNI["Unicode Support"]
        end
    end

    subgraph "Predefined Grammars"
        JSON["JSON Grammar"]
        HTTP["HTTP Grammar"]
        TOML["TOML Grammar"]
        SQL["SQL Grammar"]
    end

    subgraph "Development Tools"
        DBG["debugger"]
    end

    subgraph "Output"
        GP["Generated Parser Implementation"]
    end

    %% Relationships
    GF --> META
    RS --> PD
    PD <--> META
    PD <--> GEN
    META --> PEST
    PEST <--> VM
    VM --> GP
    DBG -.-> VM
    DBG -.-> PEST

    %% Meta Component Relationships
    META --> GDEF
    META --> PARS
    META --> OPT

    %% Core Component Relationships
    PEST --> ERR
    PEST --> PST
    PEST --> TOK
    PEST --> UNI

    %% Click Events
    click PEST "https://github.com/pest-parser/pest/blob/master/pest/src/lib.rs"
    click PD "https://github.com/pest-parser/pest/blob/master/derive/src/lib.rs"
    click META "https://github.com/pest-parser/pest/blob/master/meta/src/lib.rs"
    click GDEF "https://github.com/pest-parser/pest/blob/master/meta/src/grammar.pest"
    click PARS "https://github.com/pest-parser/pest/blob/master/meta/src/parser.rs"
    click OPT "https://github.com/pest-parser/pest/blob/master/meta/src/optimizer/mod.rs"
    click VM "https://github.com/pest-parser/pest/blob/master/vm/src/lib.rs"
    click GEN "https://github.com/pest-parser/pest/blob/master/generator/src/lib.rs"
    click JSON "https://github.com/pest-parser/pest/blob/master/grammars/src/grammars/json.pest"
    click HTTP "https://github.com/pest-parser/pest/blob/master/grammars/src/grammars/http.pest"
    click TOML "https://github.com/pest-parser/pest/blob/master/grammars/src/grammars/toml.pest"
    click SQL "https://github.com/pest-parser/pest/blob/master/grammars/src/grammars/sql.pest"
    click DBG "https://github.com/pest-parser/pest/blob/master/debugger/src/lib.rs"
    click ERR "https://github.com/pest-parser/pest/blob/master/pest/src/error.rs"
    click PST "https://github.com/pest-parser/pest/blob/master/pest/src/parser_state.rs"
    click TOK "https://github.com/pest-parser/pest/blob/master/pest/src/token.rs"
    click UNI "https://github.com/pest-parser/pest/blob/master/pest/src/unicode/mod.rs"

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef input fill:#d9ead3,stroke:#333
    classDef processing fill:#fff2cc,stroke:#333
    classDef core fill:#cfe2f3,stroke:#333
    classDef tools fill:#f4cccc,stroke:#333
    classDef output fill:#d9d2e9,stroke:#333
    classDef grammars fill:#ead1dc,stroke:#333

    class GF,RS input
    class PD,META,GEN,GDEF,PARS,OPT processing
    class PEST,VM,ERR,PST,TOK,UNI core
    class DBG tools
    class GP output
    class JSON,HTTP,TOML,SQL grammars
```
