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

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

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

#578 in Programming languages

Download history 369/week @ 2025-03-26 294/week @ 2025-04-02 48/week @ 2025-04-09 18/week @ 2025-04-16 13/week @ 2025-04-23 1/week @ 2025-04-30 16/week @ 2025-05-07 3/week @ 2025-05-14 4/week @ 2025-05-28 3/week @ 2025-06-18 949/week @ 2025-07-02

952 downloads per month
Used in 11 crates (3 directly)

MIT license

160KB
3.5K SLoC

Rust 3.5K SLoC // 0.0% comments Pest 421 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.7"

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

~2.3–3MB
~61K SLoC