35 lines
733 B
Rust
35 lines
733 B
Rust
|
|
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(())
|
||
|
|
}
|