Coder Social home page Coder Social logo

vogtb / f7 Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 350 KB

F7 is a spreadsheet formula execution library

License: MIT License

Makefile 0.13% ANTLR 0.48% Java 48.58% TypeScript 42.64% JavaScript 8.17%
antlr4 formulas java javascript parser spreadsheet typescript

f7's Introduction

F7

F7 is the spreadsheet formula execution library. It contains a parser, executor, and formulas necessary to run a spreadsheet. That means you can do things like =(SUM(A1:A9) / COUNT(A1:A9)) * MAX(Sheet1!A1:A) or basically anything else you'd want to write in a cell in a common spreadsheet.

I built it back in 2019 for a product that never ended up launching, and thought I'd open source it. I'm not sure how usable it is in your application. It's not exactly plug-and-play, so to speak, but there might be something that someone can learn from it.

I used ANTLR G4 to write grammars that produce JS/TS parser/lexers to get the AST, and then uses an engine and some formulas to compute the cell values.

It mostly supports:

  • Basic math, including order of operations.
  • Relative and absolute A1-notation references.
  • Sheets.
  • Sheet references.
  • Formulas for engineering, info, logic, math, parser, statistical, and text.
  • Most formulas check types, so they behave similarly to common spreadsheets.
  • Named ranges.
  • Excel-like data types: Boolean, Number, Error, String, Date, Empty.
  • Some Google Sheets formulas, some Excel formulas.
  • Errors that work like Google Sheets including #DIV, and, for example, circular-dependency errors.
  • Array projection using = {1, 2, 3} notation.
  • Grid projection using = {1, 2; 3; 4; 5, 6} notation.

Here are the things it does not support:

  • XML import or export. Since this seemed like the easiest part, I didn't worry about it, assuming I'd be able to find a good XML parser to wrap the models.
  • Good memory management. It stores basically everything using in-memory hash maps.
  • Performance. For example, it mostly uses iteration for hashmap lookups when doing range-based queries.
  • Google Sheets LTR-style, left-hand association of the ^ power operator. (Google Sheets, and Excel are different, so =2^3^4 in Excel is 4096, but something like 2.417851639E24 in Google Sheets.)
  • Row-column notation.

One thing to note is that exponential operators are left-hand associative. Google Sheets, and Excel are different, so =2^3^4 in Excel is 4096, but something like 2.417851639E24 in Google Sheets. You can find out more about these strange discrepancies if you grep the code for "HACK" or "TODO".

If I had to do this again, I would do it very differently. But I certainly had fun the first time.

License

Copyright 2022 Ben Vogt.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

f7's People

Contributors

vogtb avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.