Removes the csv example

This commit is contained in:
howardwu 2020-04-20 21:28:47 -07:00
parent 0d71b00b3c
commit 0cfcc8d55f
3 changed files with 0 additions and 52 deletions

View File

@ -1,5 +0,0 @@
65279,1179403647,1463895090
3.1415927,2.7182817,1.618034
-40,-273.15
13,42
65537
1 65279,1179403647,1463895090
2 3.1415927,2.7182817,1.618034
3 -40,-273.15
4 13,42
5 65537

View File

@ -1,3 +0,0 @@
field = { (ASCII_DIGIT | "." | "-")+ }
record = { field ~ ("," ~ field)* }
file = { SOI ~ (record ~ ("\r\n" | "\n"))* ~ EOI }

View File

@ -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);
}