A lightweight functional language and parser.
flt (pronounced "flight") is a Rust workspace with:
flt: parser + AST libraryflt-cli: REPL and expression evaluator
The language supports literals, identifiers, unary/binary operators, function calls, interpolation, comments, and an Elixir-style pipe operator.
[dependencies]
flt = "0.0.2"use flt::parser::parse_expr;
fn main() {
let input = "1 + 2";
match parse_expr(input) {
Ok((remainder, expr)) if remainder.trim().is_empty() => {
println!("Parsed expression: {expr}");
}
Ok((remainder, _)) => {
eprintln!("Unconsumed input: {:?}", remainder);
}
Err(err) => {
eprintln!("Parse error: {:?}", err);
}
}
}- Number:
42,3.14,+7,-2 - String:
"hello","path\\to\\file" - Boolean:
true,false - Symbol:
:name,:"display name"
Identifiers start with a letter, then can include letters, digits, _, or -.
- Valid:
foo,foo_1,foo-1,READ - Invalid:
_foo,-foo,123foo
Both forms are supported:
- Parenthesized:
add(1, 2) - Without parentheses:
add 1, 2
Interpolated strings support {expr} and compile into concatenation (<>) expressions.
"Hello, {name}!"
"Answer: {1 + 2}"Inside interpolated strings, \{ escapes a literal {.
# starts a comment that runs to end-of-line.
1 + 2 # inline comment
# full line commentUnary operators:
!(logical not)+(unary plus)-(unary minus)
Binary operators:
- Arithmetic:
+,-,*,/ - String concat:
<> - Logical:
&&,||,^^ - Bitwise:
&,|,^ - Pipe:
|>
|> -> || -> && -> ^^ -> | -> ^ -> & -> +/-/<> -> *//
Parentheses override precedence as expected.
use flt::parser::parse_expr;
parse_expr("42");
parse_expr(r#""hello""#);
parse_expr(":id");
parse_expr("add(1, 2)");
parse_expr("add 1, 2");
parse_expr(r#""Hello, {who}!""#);
parse_expr(r#""foo" <> "bar""#);
parse_expr("1 + 2 * 3");
parse_expr("(1 + 2) * 3");
parse_expr("READ(\"input\") |> WRITE(\"output\")");
parse_expr("1 # comment\n+ 2");Run the REPL:
cargo run -p flt-cliPrint version:
cargo run -p flt-cli -- versionThe CLI evaluates literals and supported unary/binary expressions. Function calls and pipe execution are parsed but currently not executed by the evaluator.
flt::parser:parse_exprparse_literalparse_identifierparse_numberparse_stringparse_symbolparse_binary_opparse_unary_op
flt::ast:ExprLiteralIdentifierNumericBinaryOpUnaryOp
flt::Errorandflt::errors::RuntimeError
cargo test
cargo clippy --all-targets --all-featuresMIT