1 unstable release

Uses new Rust 2024

new 0.1.10 Mar 29, 2025

#1293 in Data structures


Used in 4 crates (3 directly)

MIT license

13KB
250 lines

Swamp Source Map

Manages source files for the Swamp programming language compiler, providing mapping between file IDs, paths, and source locations (line/column).

Overview

This crate provides the SourceMap struct, which is responsible for:

  • Mounting Directories: Associates symbolic names ("mounts") with file system directories containing source code.
  • Reading & Caching: Reads source files either by absolute path or relative to a mount point, caching their contents and metadata.
  • File IDs: Assigns a unique FileId (u16) to each loaded file.
  • Location Mapping: Efficiently converts byte offsets within a file (often obtained from parsers or lexers using crates like swamp-node) into human-readable line and column numbers.
  • Source Snippets: Retrieves the source text corresponding to a given span (file ID, offset, length).

Installation

Add this to your Cargo.toml:

[dependencies]
swamp-source-map = "0.1.10"

License

This project is licensed under the MIT License - see the LICENSE file for details.

Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/swamp/swamp

Dependencies

~27KB