From 133d4f679298e61fe4c51b69d21a722f58a0c0bf Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 25 Feb 2019 12:48:40 -0300 Subject: [PATCH] Skeleton, initial parsing --- .gitignore | 4 ++++ Cargo.lock | 14 ++++++++++++++ Cargo.toml | 8 ++++++++ src/main.rs | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b974e59 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target +**/*.rs.bk + +*.sw? diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..69a778b --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,14 @@ +[[package]] +name = "RustyXML" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "enexparser" +version = "0.1.0" +dependencies = [ + "RustyXML 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum RustyXML 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9222d58bccd9e6e3b82098a2ec142ad34e5d433de986d46cec03ad3a2b5fd529" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..9b00de0 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "enexparser" +version = "0.1.0" +authors = ["Julio Biason "] +edition = "2018" + +[dependencies] +RustyXML = "0.1.1" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..3675285 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,36 @@ +use std::env; +use xml::{Event, Parser}; +use std::fs::File; +use std::io::prelude::*; + +fn main() { + let args:Vec<_> = env::args().collect(); + if args.len() != 2 { + println!("Required: filename."); + std::process::exit(2); + } + + let filename = &args[1]; + + println!("Will process {}", filename); + + // Need to find a way to load small chunks and feed it to the parser while parsing. + // (E.g., load 1024 bytes, feed it to the parser and, if the parser can't continue, + // feed more data, till the end of file). + let mut file = File::open(filename).unwrap(); + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + + let mut parser = Parser::new(); + parser.feed_str(&contents); + + for event in parser { + match event.unwrap() { + Event::ElementStart(tag) => println!("Start: {}", tag.name), + Event::ElementEnd(tag) => println!("End: {}", tag.name), + Event::Characters(data) => println!("Data: {}", data), + Event::CDATA(data) => println!("CDATA: {}", data), + _ => () + } + } +}