NLCalc
A natural language calculator for Rust and the command line, with pluggable parsing and operations.
Supports arithmetic, units, percentages, dates and time zones, finance, algebra, statistics, and supplied physical models. See the guide for supported expressions and examples.
Rust
Add the crate to your project:
[]
= "0.1"
use Calculator;
Calculator::extended() includes natural-language and model adapters; Calculator::standard() provides the standard expression parser. Results include display text and highlight spans as UTF-8 byte offsets into the input.
Use evaluate_with(input, &context) with nlcalc::Context to supply the clock, timezone, rates, or unit settings. The default timezone is UTC. Custom calculators can register implementations of nlcalc::Plugin through Calculator::empty(context).with_plugin(plugin).
Command line
Install with Cargo:
Without an argument, NLCalc reads requests from stdin. Use single quotes for expressions containing dollar signs. Run nlcalc --help for options.
Currency rates are offline by default. Set NLCALC_RATES to a local rates JSON file, or use --online for cached daily ECB fiat rates via curl. Library callers supply rates through Context; the library does not fetch them.
Development