flt
A lightweight functional language and parser.
Overview
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.
Crate version
[]
= "0.0.2"
Quick start
use parse_expr;
Language syntax
Literals
- Number:
42,3.14,+7,-2 - String:
"hello","path\\to\\file" - Boolean:
true,false - Symbol:
:name,:"display name"
Identifiers
Identifiers start with a letter, then can include letters, digits, _, or -.
- Valid:
foo,foo_1,foo-1,READ - Invalid:
_foo,-foo,123foo
Function calls
Both forms are supported:
- Parenthesized:
add(1, 2) - Without parentheses:
add 1, 2
String interpolation
Interpolated strings support {expr} and compile into concatenation (<>) expressions.
"Hello, {name}!"
"Answer: {1 + 2}"
Inside interpolated strings, \{ escapes a literal {.
Comments
# starts a comment that runs to end-of-line.
1 + 2 # inline comment
# full line comment
Operators
Unary operators:
!(logical not)+(unary plus)-(unary minus)
Binary operators:
- Arithmetic:
+,-,*,/ - String concat:
<> - Logical:
&&,||,^^ - Bitwise:
&,|,^ - Pipe:
|>
Precedence (lowest to highest)
|> -> || -> && -> ^^ -> | -> ^ -> & -> +/-/<> -> *//
Parentheses override precedence as expected.
Parse examples
use parse_expr;
parse_expr;
parse_expr;
parse_expr;
parse_expr;
parse_expr;
parse_expr;
parse_expr;
parse_expr;
parse_expr;
parse_expr;
parse_expr;
CLI (workspace binary)
Run the REPL:
Print version:
The CLI evaluates literals and supported unary/binary expressions. Function calls and pipe execution are parsed but currently not executed by the evaluator.
Public API
flt::parser:parse_exprparse_literalparse_identifierparse_numberparse_stringparse_symbolparse_binary_opparse_unary_op
flt::ast:ExprLiteralIdentifierNumericBinaryOpUnaryOp
flt::Errorandflt::errors::RuntimeError
Development
License
MIT