#ast #pest-parser #swamp #source #programming-language

swamp-parser

Parses Swamp programming language source code into an Abstract Syntax Tree (AST) defined in the swamp-ast crate, using the pest parsing library

35 releases

Uses new Rust 2024

0.2.26 Aug 18, 2025
0.2.25 Aug 16, 2025
0.2.19 Jul 30, 2025
0.1.16 Apr 7, 2025
0.0.14 Apr 1, 2025

#930 in Programming languages

36 downloads per month
Used in 12 crates (3 directly)

MIT license

160KB
3.5K SLoC

Rust 3.5K SLoC // 0.0% comments Pest 431 SLoC // 0.1% comments

Swamp Parser

Parses Swamp programming language source code text into an Abstract Syntax Tree (AST).

Overview

This crate takes a string containing Swamp source code and attempts to parse it according to the grammar defined in src/grammar.pest. If successful, it produces an AST representation using the data structures defined in the swamp-ast crate. If the source code contains syntax errors, it returns a ParseError.

The parser is built using the pest parser generator library.

Key Features

  • Input: Swamp source code as a &str.
  • Output: A Result<swamp_ast::Module, ParseError>.
  • AST: The success variant contains the root of the Abstract Syntax Tree (swamp_ast::Module).
  • Error Handling: The error variant (ParseError) provides information about the location and nature of the syntax error.
  • Span Information: Attaches source location information (swamp_ast::Node containing SpanWithoutFileId) to the generated AST nodes.

Installation

Add this to your Cargo.toml:

[dependencies]
swamp-parser = "0.2.26"

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

~6–9MB
~96K SLoC