relix 0.1.1

A Pratt parser implementation for a custom language with support for expressions, statements, and type annotations
Documentation
  • Coverage
  • 99.16%
    236 out of 238 items documented4 out of 71 items with examples
  • Size
  • Source code size: 81.55 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.79 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • seanrobmerriam/relix
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • seanrobmerriam

Relix

A Pratt parser implementation in Rust.

Overview

Relix provides a complete lexing and parsing pipeline built on Pratt parsing (top-down operator precedence) techniques. It tokenizes source code via a regex-driven lexer, then builds an abstract syntax tree (AST) using configurable binding-power tables.

It can parse a custom language with support for:

  • Expressions (arithmetic, logical, comparison, assignment)
  • Statements (variable declarations, functions, conditionals, loops, classes)
  • Type annotations
  • Member access and function calls

Project Structure

src/
├── lexer/          # Tokenization
│   ├── token.rs    # Token types and kinds
│   └── tokenizer.rs # Regex-based lexer
├── parser/         # Parsing
│   ├── parser.rs   # Parser struct and main entry
│   ├── expr.rs     # Expression parsing
│   ├── stmt.rs     # Statement parsing
│   ├── types.rs    # Type parsing
│   └── lookups.rs  # Binding power and handler tables
├── ast/            # AST node definitions
│   └── mod.rs      # All expression, statement, and type nodes
├── lib.rs          # Library root
└── main.rs         # Binary entry point

Building

cargo build

Testing

cargo test

Usage

Create a test.lang file with your source code:

// Variable declarations
let x = 10;
const name = "hello";

// Functions
fn add(a: number, b: number): number {
    return a + b;
}

// Conditionals
if x > 5 {
    let y = x * 2;
} else {
    let y = 0;
}

// Loops
foreach item in items {
    print(item);
}

// Classes
class Point {
    let x: number;
    let y: number;
}

// Expressions
let result = add(1, 2) + 3 * 4;
let arr = [1, 2, 3];
let p = new Point();

Run the parser:

cargo run

Or use as a library:

use relix::parser::parse;

let source = r#"
    let x = 10;
    fn add(a: number, b: number): number {
        return a + b;
    }
"#;

let ast = parse(source);
println!("{:#?}", ast);

Documentation

Full API documentation is available on docs.rs once published.

To generate documentation locally:

cargo doc --open

License

MIT