Skip to content

Instantly share code, notes, and snippets.

@AchalaSB
Created November 17, 2019 07:01
Show Gist options
  • Select an option

  • Save AchalaSB/4b40d78b2be6253afd66cd67f54ffe20 to your computer and use it in GitHub Desktop.

Select an option

Save AchalaSB/4b40d78b2be6253afd66cd67f54ffe20 to your computer and use it in GitHub Desktop.
Syn parser
[package]
name = "hello_rust"
version = "0.1.0"
authors = ["AchalaSB <achalasbhatt@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
syn = {version = "0.13", features = ["full", "extra-traits"] }
fn main() {
println!("Hello, world!");
}
extern crate syn;
use std::env;
use std::fs::File;
use std::io::Read;
fn main() {
let mut args = env::args();
args.next();
match args.next() {
Some(fname) => {
let mut src = String::new();
let mut file = File::open(&fname).expect("Unable to open file");
file.read_to_string(&mut src).expect("Unable to read file");
let syntax = syn::parse_file(&src).expect("Unable to parse file");
println!("{:#?}", syntax);
}
_ => {
println!("Please supply the file to compile");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment