A lightweight functional language with a parser, REPL, and a rudimentary interpreter/runtime.
flt (pronounced "flight") is a single Rust crate that provides:
- a parser + AST (
flt::parser,flt::ast) - a REPL (
flt::repl) backed by a simple interpreter/runtime (flt::runtime)
The language supports literals, identifiers, unary/binary operators, function calls, interpolation, comments, and an Elixir-style pipe operator. The runtime currently evaluates a subset of that syntax.
[dependencies]
flt = "0.1.1"use flt::parser::parse_statement;
use flt::runtime::Runtime;
use flt::runtime::SimpleRuntime;
fn main() {
let input = "1 + 2";
let (_remainder, statement) =
parse_statement(input).expect("input should parse as a statement");
let mut runtime = SimpleRuntime::default();
let value = runtime.eval(&statement).expect("evaluation should succeed");
println!("{}", value);
}- 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 runPrint version:
cargo run -- versionThe runtime evaluates basic expressions and statements (literals, identifiers, unary/binary operators, if expressions, and let bindings). Function calls and pipe execution are parsed but currently not executed by the runtime; maps/arrays/keyword expressions are also not yet supported.
flt::parser:parse_exprparse_statementparse_literalparse_identifierparse_numberparse_stringparse_symbolparse_binary_opparse_unary_op
flt::ast:ExprLiteralIdentifierNumericBinaryOpUnaryOp
flt::repl:Repl
flt::runtime:RuntimeSimpleRuntimeValue
flt::eval:eval(evaluate a parsedExprwith a fresh runtime)
flt::Errorandflt::errors::RuntimeError
cargo test
cargo clippy --all-targets --all-featuresMIT