# jrpat/sex architecture

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

- Interactive diagram: https://gitdiagram.com/jrpat/sex
- Repository: https://github.com/jrpat/sex

## Overview

##### Main Components

a. Input Layer:
- Entry point through `sexread()` function
- Input as string-based S-expressions

b. Parser Core:
- Central component showing the recursive parsing mechanism
- Custom reader registry system
- Character processing pipeline (lexer-like functionality)

c. Node Management:
- SexNode structure and its different types
- Memory management system (allocation/deallocation)

d. Output/Printing System (Optional Component):
- If SEX_ENABLE_PRINT is defined
- Pretty-printing capabilities

**[Input String] → [Parser Core] → [Node Tree] → [Pretty Printer]**

##### Component Details

**┌─────────────────────────┐**
- Parser Core             │
- ┤
- Character Scanner     │
- Custom Reader Registry│
- Type Detection       │
- Node Construction    │
- ┘

**┌─────────────────────────┐**
- SexNode                 │
- ┤
- List                  │
- Symbol                │
- String                │
- Integer               │
- Decimal               │
- Custom               │
- ┘

##### Technical Details to Highlight

- C11 dependency requirement
- POSIX dependency for pretty-printing (conditional)

##### Implementation Notes

- The recursive nature of the parser
- The flexibility of the custom reader system
- The memory management strategy
- The optional pretty-printing capability

Remember to include notes about limitations mentioned in the README, such as:
- 512 character limit for numbers/symbols (configurable)
- C11 compiler requirement
- String escape character parsing limitation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        Input[/"Input S-Expression String"/]
    end

    subgraph "Parser Core"
        Parser["Parser Core"]:::core
        Scanner["Character Scanner"]:::core
        Registry["Custom Reader Registry"]:::core
        TypeDetect["Type Detection"]:::core
        NodeConst["Node Construction"]:::core

        Parser --> Scanner
        Scanner --> TypeDetect
        TypeDetect --> NodeConst
        Registry -.-> TypeDetect
    end

    subgraph "Node Management"
        SexNode["SexNode Structure"]:::node
        NodeTypes["Node Types"]:::node
        MemMgmt["Memory Management"]:::memory

        SexNode --- NodeTypes
        NodeTypes --> |Allocation|MemMgmt
        MemMgmt --> |Deallocation|NodeTypes
    end

    subgraph "Output System"
        PrettyPrint["Pretty Printer"]:::output
    end

    subgraph "Configuration"
        Config["Configuration Options"]:::config
        direction TB
        ConfigItems["SEX_MALLOC
        SEX_VALCHARS_MAX
        SEX_ENABLE_PRINT"]:::config
        Config --- ConfigItems
    end

    Input --> Parser
    Parser <--> SexNode
    NodeTypes --> PrettyPrint

    subgraph "Legend"
        direction TB
        L1["Core Components"]:::core
        L2["Node Components"]:::node
        L3["Memory Operations"]:::memory
        L4["Output Components"]:::output
        L5["Configuration"]:::config
    end

    %% Component Mappings
    click Parser "https://github.com/jrpat/sex/blob/main/sex.c"
    click SexNode "https://github.com/jrpat/sex/blob/main/sex.h"
    click PrettyPrint "https://github.com/jrpat/sex/blob/main/sexprint.c"
    click Config "https://github.com/jrpat/sex/blob/main/test/main.c"
    click ConfigItems "https://github.com/jrpat/sex/tree/main/test/Makefile"

    %% Styles
    classDef core fill:#a8d1f0,stroke:#333
    classDef node fill:#90EE90,stroke:#333
    classDef memory fill:#FFB6C1,stroke:#333
    classDef output fill:#DDA0DD,stroke:#333
    classDef config fill:#F0E68C,stroke:#333
```
