From 6d3266134a4ddad9818cb9ddd89785289216e5fa Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Sun, 7 Jul 2019 18:49:27 +1000 Subject: Initial commit --- .gitignore | 2 ++ Cargo.lock | 35 +++++++++++++++++++++++++++++++++++ Cargo.toml | 8 ++++++++ src/main.rs | 25 +++++++++++++++++++++++++ 4 files changed, 70 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..53eaa21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..7a56626 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,35 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "annotate-rust" +version = "0.1.0" +dependencies = [ + "syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "syn" +version = "0.15.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +"checksum syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d960b829a55e56db167e861ddb43602c003c7be0bee1d345021703fac2fb7c" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5b899f6 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "annotate-rust" +version = "0.1.0" +authors = ["Wesley Moore "] +edition = "2018" + +[dependencies] +syn = { version = "0.15.39", default-features = false, features = ["full", "parsing", "visit", "extra-traits"] } diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5ec8f34 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,25 @@ +use std::env; +use std::fs::File; +use std::io::Read; +use std::process; + +fn main() { + let mut args = env::args(); + let _ = args.next(); // executable name + + let filename = match (args.next(), args.next()) { + (Some(filename), None) => filename, + _ => { + eprintln!("Usage: dump-syntax path/to/filename.rs"); + process::exit(1); + } + }; + + let mut file = File::open(&filename).expect("Unable to open file"); + + let mut src = String::new(); + file.read_to_string(&mut src).expect("Unable to read file"); + + let syntax = syn::parse_file(&src).expect("Unable to parse file"); + println!("{:#?}", syntax); +} -- cgit v1.2.3