fmasion / excelParser

Scala lib that tries to understand excel formulas
1 stars 0 forks source link

Understanding the working of this project #1

Open hhsadiq opened 7 years ago

hhsadiq commented 7 years ago

Hey @fmasion Just came across your awesome work. Will be interested in getting a little more detail of this project. I am little confused about tries to understand excel formulas, what exactly this will mean?

Thanks

fmasion commented 7 years ago

Hi @hhsadiq

In fact this project served as a demo for a talk. You can try it by opening index.html

What I meant was : I spent much time reverse engineering excel formulas that are badly documented but the work isn't completed there's a type coersion problem some time (eg : Date + Int => Date but Int + Date => Int

so let say it's a good code base that need to be completed

cheer

hhsadiq commented 7 years ago

So basically this project is trying to backtrack (reverse-engineer) the formulae. Let's say, a formula is using two cells and performing some calculation on them, those two cells also contain formulae which are further using other cells, and so. So this project is trying to build some sort of tree or hierarchy structure which will show the final formula at the root level, dependent formulae (if exists) as intermediate nodes and explicit values as leaf nodes. This may give us a good picture of how formulae worked?

And sorry for asking these questions and not looking too much into code. Actually, I am not proficient in the Scala and mainly work as a javascript/node.js/react.js engineer.

And thanks for taking out time to answer the questions. Really appreciate that.

fmasion commented 7 years ago

Hi Scala can cross-compile in javascript the same way typescript does the project is in 2 parts :

Parse any valid excel formula in an abstract syntax tree representing the formula in an AST. The ast is defined in the model directory and the parser itself is defined in the parser directory

the tests can give you a good understanding on how it works I encourage you to take a look.

To acheive this I use a PEG parser writen in scala (but in JS you can use peg.js)

Has you explain you need to connect all these cell definitions (some contain values and other contain formulas referencing other cells and so on...) To do this I use scalaRX if you are more a javascript guy take a look to rxjs with RX you can define how the cells are related and let RX propagate changes to the dependent cells

once you've undersand how RX works you can take a look at the evaluator which is the solver it's role is to "wire" recursively all the cells together using the operator found in each node of the formula's AST

Hope this is helpfull

The main objective of this project was to demonstrate how scala.js was mature in it's early stage and how it can make sense to use it over js for complicated projects. I don't think I would have been able to acheive the same in 2 weeks in js

Don't hesitate if you have more questions