Commit 69b80d85 authored by Christopher Silva's avatar Christopher Silva

make a separate crate for work on the formula parser

parent 3d4df460
......@@ -107,6 +107,14 @@ name = "fixedbitset"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "formula"
version = "0.1.0"
dependencies = [
"pest 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "generic-array"
version = "0.12.3"
......@@ -242,7 +250,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "pest"
version = "2.1.2"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ucd-trie 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -253,7 +261,7 @@ name = "pest_derive"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"pest 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pest 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"pest_generator 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -262,7 +270,7 @@ name = "pest_generator"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"pest 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pest 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"pest_meta 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -275,7 +283,7 @@ version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pest 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pest 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -405,7 +413,7 @@ name = "spreadsheet_core"
version = "0.1.0"
dependencies = [
"anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"pest 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pest 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -481,7 +489,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
"checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
"checksum pest 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e4fb201c5c22a55d8b24fef95f78be52738e5e1361129be1b5e862ecdb6894a"
"checksum pest 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53"
"checksum pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0"
"checksum pest_generator 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9fcf299b5712d06ee128a556c94709aaa04512c4dffb8ead07c5c998447fc0"
"checksum pest_meta 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "df43fd99896fd72c485fe47542c7b500e4ac1e8700bf995544d1317a60ded547"
......
......@@ -2,4 +2,5 @@
members = [
"spreadsheet",
"spreadsheet_core",
"formula"
]
[package]
name = "formula"
version = "0.1.0"
authors = ["csos95 <csoscss@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pest = "2.1.3"
pest_derive = "2.1.0"
formula = _{ SOI ~ "=" ~ expr ~ EOI }
expr = _{ term ~ (operation ~ term)* }
term = _{
parenExpr |
number |
function |
position
}
parenExpr = { "(" ~ expr ~ ")" }
operation = _{ add | subtract | multiply | divide | power }
add = { "+" }
subtract = { "-" }
multiply = { "*" }
divide = { "/" }
power = { "^" }
function = { identifier ~ "(" ~ parameter ~ ("," ~ parameter)* ~ ")" }
parameter = { range | position | criteria }
range = { position ~ ":" ~ position }
position = { "r" ~ index ~ "c" ~ index }
index = _{ absIndex | relIndex }
absIndex = { uint }
relIndex = { ("[" ~ int ~ "]")? }
criteria = { "\"" ~ comparison? ~ value ~ "\"" }
comparison = _{ greaterEqual | lessEqual | notEqual | greater | less | equal }
greaterEqual = { ">=" }
lessEqual = { "<=" }
notEqual = { "<>" }
greater = { ">" }
less = { "<" }
equal = { "=" }
value = { number | string }
uint = { ASCII_DIGIT+ }
int = { "-"? ~ ASCII_DIGIT+ }
number = { "-"? ~ ASCII_DIGIT+ ~ ("." ~ ASCII_DIGIT+)? }
string = { ANY+ }
identifier = { ASCII_ALPHA+ }
#[macro_use]
extern crate pest_derive;
use pest::Parser;
#[derive(Parser)]
#[grammar = "formula.pest"]
pub struct FormulaParser;
fn main() {
let formula = FormulaParser::parse(Rule::formula, "=(2+2)*3");
println!("{:#?}", formula);
let formula = FormulaParser::parse(Rule::formula, "=rc[-2]*rc[-1]");
println!("{:#?}", formula);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment