A parser and evaluator of spreadsheet-like formulas

Overview

Crates.io Workflow Status

Formula

A parser and evaluator of spreadsheet-like formulas

Formula is in its early stages, so it's better to be used cautiously.

So far we have the following features:

  • 18 date time functions
  • 26 text functions
  • 26 math functions
  • 7 logical functions
  • 2 web functions
  • plus all arithmetic and comparison operators

Installation and usage

Add this library to your project with cargo add formula or add formula = "*" to your Cargo.toml file.

Use it similar to the following code:

use formula::{Formula, Expr, Result};

fn main() -> Result<()> {
    let formula = Formula::new("=UPPER(TRIM('   Hello '))")?;
    let value = formula.parse()?;
    assert_eq!(value, Expr::String("HELLO".to_string()));
    Ok(())
}

What we do not support, yet:

  • Support of functions are so limited at the moment, but we would like to add more of them, like Excel functions, Google Sheets functions, and so on
  • At the moment, we don't support table data, so you need to pass values to the formula as arguments by yourself
  • We do not support simple formulas like 1+1 or as argument like AND(1>3, 1<3) or SUM(2-1, 2). Instead, you can use our F. functions like AND(F.GT(1, 3), F.LT(1, 3)) or SUM(F.SUB(2, 1), 2)
  • We still do not support parentheses to change the order of operations, but you can use our F. functions. So for example instead of 2*(1+1), you should use F.MUL(2, F.ADD(1, 1))

Contributing

We would love to have your contribution! Please read our contributing guidelines to get started.

Inspired by

License

This project is licensed under the MIT license. See the LICENSE file for more info.

You might also like...
Docopt for Rust (command line argument parser).

THIS CRATE IS UNMAINTAINED This crate is unlikely to see significant future evolution. The primary reason to choose this crate for a new project is if

A minimal argument parser

Pieces An argument parser built with control in mind. Parsing The results you get are dependent on what order you parse in. If you want to say only pa

A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

Simple command line flag parser for rust.

easy_flag Simple command line flag parser for rust. use easy_flag::FlagSet; fn main() - Result(), String{ let mut help = false; let mut my

Parser for CARGO_ENCODED_RUSTFLAGS

Parser for CARGO_ENCODED_RUSTFLAGS CARGO_ENCODED_RUSTFLAGS is one of the environment variables provided by Cargo to build scripts. It synthesizes seve

Next-generation, type-safe CLI parser for Rust

Next-generation, type-safe CLI parser for Rust

Python wrapper for Rust's httparse HTTP parser

httparse Python wrapper for Rust's httparse. See this project on GitHub. Example from httparse import RequestParser parser = RequestParser() buff =

Alpha Hyprland/Hyprpaper/Hypr configuration file parser

Hyprland/Hyprpaper/Hypr configuration file parser [maintainer=@yavko]

Here we will show you how to build a simple parser.

A Rustic invitation to parsing: Calculator demo This is the code repository that accompanies the Rustic invitation to parsing blog post. It provides a

Releases(v0.1.0)
  • v0.1.0(Nov 11, 2022)

  • v0.0.3(Sep 11, 2022)

    Added

    • Support of basic mathematics functions
    • Excel array type, eg. {cell1, cell2; cell3, cell4}. It's not in use yet, but we may need it in some implementations

    Changed

    • Change the Error type from anyhow::Error to formula::error::Error and remove the dep of anyhow
    Source code(tar.gz)
    Source code(zip)
  • v0.0.2(Sep 8, 2022)

    Added

    • Support of basic MS Excel logical functions
    • Support of most MS Excel web functions
    • Support of arithmetic and comparison operators of MS Excel as functions. Use AND(F.GT(1, 3), F.LT(1, 3)) instead of AND(1>3, 1<3)
    • There is a new error type for not yet implemented functions, Error::NotImplemented
    • There is a new expression variant for null values, Expr::Null
    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Sep 5, 2022)

    Added

    • It's the initial release!
    • Support of basic variable types, like String, Number, Boolean, Date, Time, DateTime and ...
    • Support of basic MS Excel date and time functions
    • Support of basic MS Excel text functions
    Source code(tar.gz)
    Source code(zip)
Owner
Omid Rad
Omid Rad
A bit like tee, a bit like script, but all with a fake tty. Lets you remote control and watch a process

teetty teetty is a wrapper binary to execute a command in a pty while providing remote control facilities. This allows logging the stdout of a process

Armin Ronacher 259 Jan 3, 2023
Pure-Rust rewrite of the Linux fontconfig library (no system dependencies) - using ttf-parser and allsorts

rust-fontconfig Pure-Rust rewrite of the Linux fontconfig library (no system dependencies) - using allsorts as a font parser in order to parse .woff,

Felix Schütt 28 Oct 29, 2022
lemmy-help is a emmylua parser as well as a CLI which takes that parsed tree and converts it into vim help docs.

lemmy-help is a emmylua parser as well as a CLI which takes that parsed tree and converts it into vim help docs.

Vikas Raj 117 Jan 3, 2023
A simple, lightweight and extensible command line argument parser for rust codebases

A simple, lightweight and extensible command line argument parser for rust codebases. This crate aims to provide you with an easy-to-use and extensibl

Victor Ndaba 20 Nov 12, 2022
A parser and matcher for route patterns in Rust 🦀

Route Pattern A parser and matcher for a popular way to create route patterns. Patterns like these that include regular expressions, delimited in this

Dotan J. Nahum 3 Nov 24, 2022
SP3 Precise GNSS Orbit and Clock parser :artificial_satellite:

SP3 SP3 Precise GNSS Orbit files parser. SP3 is specifid by IGS. The parser only supports Revisions C & D at the moment and rejects revisions A & B. G

gwbres 4 Aug 31, 2023
A parser combinator that is fully statically dispatched and supports both sync/async.

XParse A parser combinator that is fully statically dispatched and supports both sync & async parsing. How to use An example of a very simple JSON par

Alsein 4 Nov 27, 2023
A device-tree source parser, analyzer and language server.

Ginko A device-tree source parser, analyzer and language server. The main goal of this project is to make working with device-trees easy. For example,

Lukas Scheller 4 Feb 28, 2024
Devops kafka like ls, tail, head,and echo with kls, ktail, khead and kecho

Kafka CLI Tools DevOps topics of Message Queue(eg kafka, pulsar, rabbitmq) like ls, echo, head and tail with kls, kecho, khead and ktail Getting Start

imotai 4 Dec 31, 2021
A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

null 10.4k Jan 10, 2023