mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 19:22:01 +03:00
Removes the csv example
This commit is contained in:
parent
0d71b00b3c
commit
0cfcc8d55f
@ -1,5 +0,0 @@
|
|||||||
65279,1179403647,1463895090
|
|
||||||
3.1415927,2.7182817,1.618034
|
|
||||||
-40,-273.15
|
|
||||||
13,42
|
|
||||||
65537
|
|
|
@ -1,3 +0,0 @@
|
|||||||
field = { (ASCII_DIGIT | "." | "-")+ }
|
|
||||||
record = { field ~ ("," ~ field)* }
|
|
||||||
file = { SOI ~ (record ~ ("\r\n" | "\n"))* ~ EOI }
|
|
@ -1,44 +0,0 @@
|
|||||||
extern crate pest;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate pest_derive;
|
|
||||||
|
|
||||||
use pest::Parser;
|
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
|
||||||
#[grammar = "csv.pest"]
|
|
||||||
pub struct CSVParser;
|
|
||||||
|
|
||||||
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") // unwrap the parse result
|
|
||||||
.next().unwrap(); // get and unwrap the `file` rule; never fails
|
|
||||||
|
|
||||||
let mut field_sum: f64 = 0.0;
|
|
||||||
let mut record_count: u64 = 0;
|
|
||||||
|
|
||||||
for record in file.into_inner() {
|
|
||||||
match record.as_rule() {
|
|
||||||
Rule::record => {
|
|
||||||
record_count += 1;
|
|
||||||
|
|
||||||
for field in record.into_inner() {
|
|
||||||
field_sum += field.as_str().parse::<f64>().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Rule::EOI => (),
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Sum of fields: {}", field_sum);
|
|
||||||
println!("Number of records: {}", record_count);
|
|
||||||
|
|
||||||
// let successful_parse = CSVParser::parse(Rule::field, "-273.15");
|
|
||||||
// println!("{:?}", successful_parse);
|
|
||||||
//
|
|
||||||
// let unsuccessful_parse = CSVParser::parse(Rule::field, "this is not a number");
|
|
||||||
// println!("{:?}", unsuccessful_parse);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user