6d3266134a4ddad9818cb9ddd89785289216e5fa — Wesley Moore 4 months ago
Initial commit
4 files changed, 70 insertions(+), 0 deletions(-)

A .gitignore
A Cargo.lock
A Cargo.toml
A src/main.rs
A  => .gitignore +2 -0
@@ 1,2 @@
+/target
+**/*.rs.bk

A  => Cargo.lock +35 -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"

A  => Cargo.toml +8 -0
@@ 1,8 @@
+[package]
+name = "annotate-rust"
+version = "0.1.0"
+authors = ["Wesley Moore <wes@wezm.net>"]
+edition = "2018"
+
+[dependencies]
+syn = { version = "0.15.39", default-features = false, features = ["full", "parsing", "visit", "extra-traits"] }

A  => src/main.rs +25 -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);
+}