Expand description
Ruchy - A systems-oriented scripting language that transpiles to Rust
Ruchy provides a high-level, expressive syntax with features like pipeline operators, pattern matching, type inference, and method calls, all while transpiling to efficient Rust code.
§Features
- Type Inference: Hindley-Milner type system with Algorithm W
- Method Calls: Familiar
x.method()syntax - Gradual Typing: Mix typed and untyped code
- Pipeline Operators: Chain operations with
|> - Pattern Matching: Powerful pattern matching with exhaustiveness checking
§Quick Start
use ruchy::frontend::parser::Parser;
use ruchy::backend::transpiler::Transpiler;
use ruchy::middleend::InferenceContext;
// Parse Ruchy code
let mut parser = Parser::new("1 + 2 * 3");
let expr = parser.parse().expect("Failed to parse");
// Infer types
let mut ctx = InferenceContext::new();
let ty = ctx.infer(&expr).expect("Failed to infer type");
println!("Type: {}", ty); // Type: i32
// Transpile to Rust
let transpiler = Transpiler::new();
let rust_code = transpiler.transpile_expr(&expr).expect("Failed to transpile");§Features
- Pipeline Operators: Chain operations with
|>for readable data transformations - Pattern Matching: Powerful pattern matching with exhaustiveness checking
- Actor System: Built-in actor model for concurrent programming
- Type Inference: Hindley-Milner type inference with extensions
- Zero-Cost Abstractions: All features compile to efficient Rust code
§Examples
§Pipeline Operations
use ruchy::frontend::parser::Parser;
let code = r#"
[1, 2, 3, 4, 5]
|> filter(x => x % 2 == 0)
|> map(x => x * 2)
|> sum()
"#;
let mut parser = Parser::new(code);
let expr = parser.parse().expect("Failed to parse pipeline");§Method Calls
use ruchy::frontend::parser::Parser;
let code = r#"
let text = "hello"
text.len()
"#;
let mut parser = Parser::new(code);
let expr = parser.parse().expect("Failed to parse method call");§Pattern Matching
use ruchy::frontend::parser::Parser;
let code = r#"
match x {
1 => "one",
2 => "two",
_ => "other",
}
"#;
let mut parser = Parser::new(code);
let expr = parser.parse().expect("Failed to parse match expression");§Actor Definition
ⓘ
use ruchy::frontend::parser::Parser;
let code = r#"
actor Counter {
mut count: i32 = 0;
pub fn increment() {
self.count += 1;
}
pub fn get() -> i32 {
self.count
}
}
"#;
let mut parser = Parser::new(code);
let expr = parser.parse().expect("Failed to parse actor");Re-exports§
pub use backend::transpiler::Transpiler;pub use frontend::ast::Expr;pub use frontend::ast::ExprKind;pub use frontend::parser::Parser;pub use parser::error_recovery::ErrorNode;pub use parser::error_recovery::ErrorRecovery;pub use runtime::repl::Repl;
Modules§
- backend
- Backend code generation and transpilation
- frontend
- Frontend parsing and lexical analysis
- middleend
- Middle-end compiler passes (type checking, inference, optimization)
- parser
- Parser module with error recovery
- runtime
- Runtime execution and REPL support
- transpiler
- Transpiler module implementing extreme quality engineering
Functions§
- compile
- Parse and transpile Ruchy code to Rust in one step.
- get_
parse_ error - Get a formatted error message for invalid Ruchy code.
- is_
valid_ syntax - Check if a string contains valid Ruchy syntax.