summaryrefslogtreecommitdiff
path: root/xmd/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xmd/src/main.rs')
-rw-r--r--xmd/src/main.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/xmd/src/main.rs b/xmd/src/main.rs
new file mode 100644
index 0000000..42406df
--- /dev/null
+++ b/xmd/src/main.rs
@@ -0,0 +1,34 @@
+use pest::Parser;
+use std::fs;
+
+use xmd::CSVParser;
+use xmd::Rule;
+
+fn main() {
+ let unparsed_file = fs::read_to_string("numbers.csv").expect("cannot read file");
+
+ let file = CSVParser::parse(Rule::file, &unparsed_file)
+ .expect("unsuccessful parse")
+ .next()
+ .unwrap();
+
+ let mut sum: f64 = 0.0;
+ let mut records: i64 = 0;
+
+ for record in file.into_inner() {
+ match record.as_rule() {
+ Rule::record => {
+ records += 1;
+
+ for field in record.into_inner() {
+ sum += field.as_str().parse::<f64>().unwrap();
+ }
+ }
+ Rule::EOI => (),
+ _ => unreachable!(),
+ }
+ }
+
+ println!("Sum of fields: {}", sum);
+ println!("Number of records: {}", records);
+}