| Crates.io | oxide-lang |
| lib.rs | oxide-lang |
| version | 0.1.0 |
| created_at | 2025-09-04 07:06:09.360899+00 |
| updated_at | 2025-09-04 07:06:09.360899+00 |
| description | Oxide — an experimental programming language written in Rust. Includes a lexer, parser, and REPL. Early-stage project. |
| homepage | https://github.com/KushalMeghani1644/Oxide |
| repository | https://github.com/KushalMeghani1644/Oxide |
| max_upload_size | |
| id | 1823783 |
| size | 100,584 |
A modern programming language implementation in Rust, featuring a complete lexer and recursive descent parser.
Oxide is a simple programming language that supports:
letlet x = 42;
let name = identifier;
let sum = 1 + 2;
let product = 3 * 4;
let complex = (1 + 2) * 3 - 4 / 2;
let negative = -42;
let double_neg = --x;
{
let x = 5;
let y = 10;
x + y;
}
42;
1 + 2 * 3;
(x + y) / 2;
src/lexer/)The lexer tokenizes source code into the following tokens:
42), Identifiers (variable)let=, +, -, *, /;, (, ), {, }EOF, Illegalsrc/parser/)The parser uses recursive descent parsing with operator precedence to build an Abstract Syntax Tree (AST):
Add to your Cargo.toml:
[dependencies]
oxide = "0.1.0"
Parse source code:
use oxide::parse_source;
let source = "let x = 1 + 2 * 3;";
match parse_source(source) {
Ok(program) => {
println!("Parsed {} statements", program.statements.len());
for stmt in &program.statements {
println!("{}", stmt);
}
}
Err(errors) => {
println!("Parse errors: {}", errors);
}
}
Run the interactive REPL:
cargo run --bin oxide-repl
Commands:
help - Show help messagequit - Exit the REPLclear - Clear screenRun the demo:
cargo run --example parser_demo
Oxide/
├── src/
│ ├── lib.rs # Library root
│ ├── lexer/
│ │ ├── mod.rs # Lexer module
│ │ └── lexer.rs # Lexer implementation
│ ├── parser/
│ │ ├── mod.rs # Parser module
│ │ ├── ast.rs # AST node definitions
│ │ ├── error.rs # Error types and handling
│ │ └── parse.rs # Parser implementation
│ └── bin/
│ └── repl.rs # Interactive REPL
├── examples/
│ └── parser_demo.rs # Usage examples
├── Cargo.toml # Project configuration
└── README.md # This file
The language follows this grammar (in EBNF):
program = statement* ;
statement = letStmt | blockStmt | exprStmt ;
letStmt = "let" IDENTIFIER "=" expression ";" ;
blockStmt = "{" statement* "}" ;
exprStmt = expression ";" ;
expression = binary ;
binary = unary ( ( "+" | "-" | "*" | "/" ) unary )* ;
unary = ( "-" ) unary | primary ;
primary = NUMBER | IDENTIFIER | "(" expression ")" ;
*, / (highest)+, - (lowest)Parentheses can override precedence: (1 + 2) * 3 vs 1 + 2 * 3
The parser provides detailed error messages with position information:
Run all tests:
cargo test
Run specific test modules:
cargo test lexer
cargo test parser
let x = 42;
AST: Let { name: "x", value: Number(42) }
let result = (1 + 2) * 3 - 4;
AST:
Let {
name: "result",
value: Binary {
left: Binary {
left: Grouping(Binary { left: Number(1), op: Add, right: Number(2) }),
op: Multiply,
right: Number(3)
},
op: Subtract,
right: Number(4)
}
}
{
let x = 5;
let y = x + 10;
y;
}
Build the project:
cargo build
Run with debug output:
RUST_LOG=debug cargo run --bin oxide-repl
Format code:
cargo fmt
Lint code:
cargo clippy
This project is LICENSED under the GPLv3 license, you can check at LICENSE