Created
November 17, 2019 07:01
-
-
Save AchalaSB/4b40d78b2be6253afd66cd67f54ffe20 to your computer and use it in GitHub Desktop.
Syn parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main() { | |
| println!("Hello, world!"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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