34
src/main.rs
Normal file
34
src/main.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
mod object;
|
||||
mod syn;
|
||||
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
use syn::lexer::Lexer;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
struct Opt {
|
||||
#[structopt(name = "PATH", parse(from_os_str))]
|
||||
path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
type Result<T = (), E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
|
||||
|
||||
fn main() -> Result {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
let text = if let Some(path) = opt.path.as_ref() {
|
||||
std::fs::read_to_string(path)?
|
||||
} else {
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_to_string(&mut input)?;
|
||||
input
|
||||
};
|
||||
|
||||
let mut lexer = Lexer::new(&text);
|
||||
while let Some(token) = lexer.next()? {
|
||||
println!("{:?}", token);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user