# b3b00/csly architecture

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

- Interactive diagram: https://gitdiagram.com/b3b00/csly
- Repository: https://github.com/b3b00/csly

## Overview

##### Main Components

a) Core Components:
- Lexer System
- Generic Lexer
- FSM (Finite State Machine) Lexer
- Lexer Builder
- Token Management

- Parser System
- BNF Parser
- EBNF Parser
- Expression Parser
- Parser Builder
- Syntax Tree Management

b) Supporting Components:
- Build Result System
- Internationalization (i18n)
- Configuration Management
- Error Handling

##### Component Relationships

**[Input Source Code] → [Lexer System] → [Token Stream] → [Parser System] → [Abstract Syntax Tree]**

##### Detailed Component Breakdown

Lexer System (src/sly/lexer):
- Token Definition Management
- FSM Lexer Implementation
- Mode Management
- Channel Management
- Generic Lexer Features

Parser System (src/sly/parser):
- Parser Generator
- Expression Rules Generator
- Syntax Tree Builder
- Rule Management
- EBNF/BNF Support

##### Special Features to Highlight

Create dedicated sections for:
- Indentation Support
- Expression Parsing
- Channel System
- Generic Lexer Features

##### Implementation Details

Implementation aspects:
- Builder Pattern usage
- Attribute-based configuration
- FSM-based lexing
- Recursive descent parsing
- Expression precedence handling

##### External Interactions

Interfaces for:
- Input handling
- Error reporting
- AST output
- Configuration input

##### The configuration options

Remember to:
- Keep the main flow clear and centered
- Related components visually
- Brief descriptions for complex interactions
- Version/configuration management

This design should reflect CSLY's core strength as a lightweight, embeddable parser generator that doesn't require build-time steps while supporting advanced features like expression parsing and indentation-aware parsing.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        A[Component]:::component
        B[(Database)]:::db
        C{Decision Point}:::decision
        D[/API/]:::api
        E([External System]):::external
    end

    subgraph Input
        SRC([Source Code]):::external
    end

    subgraph "Lexer System"
        LB[Lexer Builder]:::core
        GL[Generic Lexer]:::core
        FSM[FSM Lexer]:::core
        TM[Token Management]:::core
        
        LB --> GL
        LB --> FSM
        GL & FSM --> TM
    end

    subgraph "Parser System"
        PB[Parser Builder]:::core
        BNF[BNF Parser]:::core
        EBNF[EBNF Parser]:::core
        EPG[Expression Parser Generator]:::core
        STM[Syntax Tree Management]:::core
        
        PB --> BNF & EBNF
        PB --> EPG
        BNF & EBNF --> STM
        EPG --> STM
    end

    subgraph "Support Systems"
        BR[Build Result System]:::support
        I18N[Internationalization]:::support
        CM[Configuration Management]:::support
        EH[Error Handling]:::support
    end

    SRC --> LB
    TM --> PB
    STM --> AST([Abstract Syntax Tree]):::external

    CM --> LB & PB
    EH --> BR
    BR --> I18N

    classDef core fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef support fill:#90EE90,stroke:#333,stroke-width:2px
    classDef decision fill:#FFD700,stroke:#333,stroke-width:2px
    classDef error fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef external fill:#F0F0F0,stroke:#333,stroke-width:2px
    classDef api fill:#FF9900,stroke:#333,stroke-width:2px
    classDef component fill:#FFFFFF,stroke:#333,stroke-width:2px
    classDef db fill:#F8F8F8,stroke:#333,stroke-width:2px

    click GL "https://github.com/b3b00/csly/blob/dev/src/sly/lexer/GenericLexer.cs"
    click FSM "https://github.com/b3b00/csly/blob/dev/src/sly/lexer/fsm/FSMLexer.cs"
    click LB "https://github.com/b3b00/csly/blob/dev/src/sly/lexer/LexerBuilder.cs"
    click TM "https://github.com/b3b00/csly/blob/dev/src/sly/lexer/Token.cs"
    click BNF "https://github.com/b3b00/csly/blob/dev/src/sly/parser/parser/llparser/bnf/RecursiveDescentSyntaxParser.cs"
    click EBNF "https://github.com/b3b00/csly/blob/dev/src/sly/parser/parser/llparser/ebnf/EBNFRecursiveDescentSyntaxParser.cs"
    click EPG "https://github.com/b3b00/csly/blob/dev/src/sly/parser/generator/ExpressionRulesGenerator.cs"
    click PB "https://github.com/b3b00/csly/blob/dev/src/sly/parser/generator/ParserBuilder.cs"
    click STM "https://github.com/b3b00/csly/tree/dev/src/sly/parser/syntax/tree"
    click BR "https://github.com/b3b00/csly/blob/dev/src/sly/buildresult/BuildResult.cs"
    click I18N "https://github.com/b3b00/csly/blob/dev/src/sly/i18n/I18N.cs"
    click EH "https://github.com/b3b00/csly/blob/dev/src/sly/buildresult/ErrorCodes.cs"
    click CM "https://github.com/b3b00/csly/blob/dev/src/sly/parser/generator/ParserConfiguration.cs"
```
