#embedding #printing #structure

swamp-pretty-print

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

4 releases

Uses new Rust 2024

new 0.1.13 Mar 30, 2025
0.1.12 Mar 30, 2025
0.1.11 Mar 29, 2025
0.1.10 Mar 29, 2025

#66 in Value formatting

Download history

85 downloads per month
Used in 4 crates (via swamp-compile)

MIT license

155KB
4K 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.1.13"

Dependencies

~575KB