#graph #compiler #pretty-print #human-readable #symbols #internal #semantic #swamp #colorized #expression

swamp-pretty-print

Pretty-prints Swamp compiler internal representations (Semantic Graph nodes, Types, Symbol Tables) into human-readable, colorized strings for debugging

16 releases

Uses new Rust 2024

new 0.2.7 Jul 9, 2025
0.2.6 Jul 8, 2025
0.1.16 Apr 7, 2025
0.1.13 Mar 30, 2025
0.0.14 Apr 1, 2025

#197 in Value formatting

Download history 372/week @ 2025-03-26 281/week @ 2025-04-02 42/week @ 2025-04-09 15/week @ 2025-04-16 4/week @ 2025-04-23 7/week @ 2025-05-07 943/week @ 2025-07-02

943 downloads per month
Used in 8 crates (via swamp-compile)

MIT license

180KB
4.5K SLoC

Swamp Pretty Printer

Provides functions to format and display internal data structures from the Swamp programming language compiler in a human-readable, colorized way.

Overview

This crate is a debugging and inspection tool for developers working on the Swamp compiler. It takes complex internal representations like the Abstract Semantic Graph (swamp_semantic::Expression), type structures (swamp_types::Type), symbol tables (swamp_modules::SymbolTable), etc., and formats them into indented, color-coded strings.

It utilizes swamp-source-map-lookup to include source text snippets and yansi for terminal colorization.

Key Features

  • Formats Internal Structures: Pretty-prints Expression, Type, SymbolTable, Modules, AssociatedImpls, and more.
  • Color Highlighting: Uses terminal colors to differentiate between different kinds of symbols, types, and syntax elements.
  • Indentation: Uses indentation to reflect the structure of the data (e.g., nested expressions, struct fields).
  • Source Integration: Leverages SourceMapLookup to display identifiers based on their source text.

Core Structures

  • SourceMapDisplay: A wrapper around a SourceMapLookup implementation that provides the core formatting methods.
  • SymbolTableDisplay, ExpressionDisplay, etc.: Wrapper structs that implement std::fmt::Display by using SourceMapDisplay to format the contained compiler structure.

Installation

This crate is primarily intended for use within the Swamp compiler or related debugging tools.

[dependencies]
swamp-pretty-print = "0.2.7"

Dependencies

~600KB