# sonarsource/sslr architecture

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

- Interactive diagram: https://gitdiagram.com/sonarsource/sslr
- Repository: https://github.com/sonarsource/sslr

## Overview

##### Main Components

a. Core Components (sslr-core):
- Lexical Analysis System
- Parser Framework
- AST (Abstract Syntax Tree) Management
- Grammar Building System
- Channel System

b. Supporting Components:
- XPath Query System (sslr-xpath)
- Testing Framework (sslr-testing-harness)
- Toolkit UI (sslr-toolkit)
- Benchmarking System (sslr-benchmarks)

##### Component Relationships

**[Input Source Code]**
- ↓
**[Lexical Analysis Layer]**
- Lexer
- Channels
- Token Management
- ↓
**[Parsing Layer]**
- Grammar Rules
- Parser Implementation
- Expression Handling
- ↓
**[AST Processing Layer]**
- AST Construction
- Node Management
- Tree Walking
- ↓
**[Analysis Tools]**
- → [XPath Query System]
- → [Testing Framework]
- → [Toolkit UI]

##### Important Implementation Details

a. Core Processing Pipeline:
- Flow from source code through lexical analysis, parsing, and AST creation
- Grammar building system's integration
- Channel system's role in lexical analysis

b. Extension Points:
- Where custom grammars can be implemented
- Testing integration points
- Toolkit integration possibilities

##### Specific Elements

a. API Layers:
- com.sonar.sslr.api package interfaces
- org.sonar.sslr.grammar interfaces
- Channel system interfaces

b. Implementation Components:
- Matcher system
- Parser implementation
- AST visitor pattern implementation

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef input fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef support fill:#FFA500,stroke:#333,stroke-width:2px
    classDef test fill:#D3D3D3,stroke:#333,stroke-width:2px
    
    %% Input Layer
    SourceCode["Source Code"]:::input
    
    %% Lexical Analysis Layer
    subgraph LexicalLayer["Lexical Analysis Layer"]
        Lexer["Lexer System"]:::core
        Channels["Channel System"]:::core
        TokenMgmt["Token Management"]:::core
    end
    
    %% Parsing Layer
    subgraph ParsingLayer["Parsing Layer"]
        Grammar["Grammar Building System"]:::core
        Parser["Parser Implementation"]:::core
        ExprHandler["Expression Handler"]:::core
    end
    
    %% AST Layer
    subgraph ASTLayer["AST Processing Layer"]
        ASTConst["AST Construction"]:::core
        NodeMgmt["Node Management"]:::core
        TreeWalk["Tree Walking"]:::core
    end
    
    %% Analysis Tools
    subgraph Tools["Analysis Tools"]
        XPath["XPath Query System"]:::support
        Testing["Testing Framework"]:::test
        Toolkit["Toolkit UI"]:::support
        Benchmark["Benchmarking System"]:::test
    end
    
    %% Relationships
    SourceCode --> Lexer
    Lexer --> TokenMgmt
    Channels --> Lexer
    
    TokenMgmt --> Parser
    Grammar --> Parser
    Parser --> ExprHandler
    
    ExprHandler --> ASTConst
    ASTConst --> NodeMgmt
    NodeMgmt --> TreeWalk
    
    TreeWalk --> XPath
    TreeWalk --> Testing
    TreeWalk --> Toolkit
    TreeWalk --> Benchmark
    
    %% Click events for component mapping
    click Lexer "https://github.com/SonarSource/sslr/blob/master/sslr-core/src/main/java/com/sonar/sslr/impl/Lexer.java"
    click Channels "https://github.com/SonarSource/sslr/tree/master/sslr-core/src/main/java/org/sonar/sslr/channel/"
    click Parser "https://github.com/SonarSource/sslr/blob/master/sslr-core/src/main/java/com/sonar/sslr/impl/Parser.java"
    click Grammar "https://github.com/SonarSource/sslr/tree/master/sslr-core/src/main/java/org/sonar/sslr/grammar/"
    click NodeMgmt "https://github.com/SonarSource/sslr/tree/master/sslr-core/src/main/java/com/sonar/sslr/impl/ast/"
    click ASTConst "https://github.com/SonarSource/sslr/blob/master/sslr-core/src/main/java/com/sonar/sslr/api/AstNode.java"
    click XPath "https://github.com/SonarSource/sslr/tree/master/sslr-xpath/src/main/java/com/sonar/sslr/xpath/"
    click Testing "https://github.com/SonarSource/sslr/tree/master/sslr-testing-harness/src/main/java/org/sonar/sslr/tests/"
    click Toolkit "https://github.com/SonarSource/sslr/tree/master/sslr-toolkit/src/main/java/org/sonar/sslr/toolkit/"
    click Benchmark "https://github.com/SonarSource/sslr/tree/master/sslr-benchmarks/src/main/java/org/sonar/sslr/benchmarks/"
    
    %% Legend
    subgraph Legend
        L1["Input/Output"]:::input
        L2["Core Components"]:::core
        L3["Support Tools"]:::support
        L4["Testing Components"]:::test
    end
```
