From b5021411a84822cb3f1e3aeffad9550dd15bdeb6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 16 Sep 2018 12:54:24 +0300 Subject: rename all things --- crates/cli/Cargo.toml | 12 ------- crates/cli/src/main.rs | 97 -------------------------------------------------- 2 files changed, 109 deletions(-) delete mode 100644 crates/cli/Cargo.toml delete mode 100644 crates/cli/src/main.rs (limited to 'crates/cli') diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml deleted file mode 100644 index 7dbbe3f4e..000000000 --- a/crates/cli/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "cli" -version = "0.1.0" -authors = ["Aleksey Kladov "] -publish = false - -[dependencies] -clap = "2.32.0" -failure = "0.1.1" -libsyntax2 = { path = "../libsyntax2" } -libeditor = { path = "../libeditor" } -tools = { path = "../tools" } diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs deleted file mode 100644 index 68a531f93..000000000 --- a/crates/cli/src/main.rs +++ /dev/null @@ -1,97 +0,0 @@ -extern crate clap; -#[macro_use] -extern crate failure; -extern crate libsyntax2; -extern crate libeditor; -extern crate tools; - -use std::{ - fs, io::Read, path::Path, - time::Instant -}; -use clap::{App, Arg, SubCommand}; -use tools::collect_tests; -use libsyntax2::File; -use libeditor::{syntax_tree, file_structure}; - -type Result = ::std::result::Result; - -fn main() -> Result<()> { - let matches = App::new("libsyntax2-cli") - .setting(clap::AppSettings::SubcommandRequiredElseHelp) - .subcommand( - SubCommand::with_name("render-test") - .arg( - Arg::with_name("line") - .long("--line") - .required(true) - .takes_value(true), - ) - .arg( - Arg::with_name("file") - .long("--file") - .required(true) - .takes_value(true), - ), - ) - .subcommand( - SubCommand::with_name("parse") - .arg(Arg::with_name("no-dump").long("--no-dump")) - ) - .subcommand(SubCommand::with_name("symbols")) - .get_matches(); - match matches.subcommand() { - ("parse", Some(matches)) => { - let start = Instant::now(); - let file = file()?; - let elapsed = start.elapsed(); - if !matches.is_present("no-dump") { - println!("{}", syntax_tree(&file)); - } - eprintln!("parsing: {:?}", elapsed); - ::std::mem::forget(file); - } - ("symbols", _) => { - let file = file()?; - for s in file_structure(&file) { - println!("{:?}", s); - } - } - ("render-test", Some(matches)) => { - let file = matches.value_of("file").unwrap(); - let file = Path::new(file); - let line: usize = matches.value_of("line").unwrap().parse()?; - let line = line - 1; - let (test, tree) = render_test(file, line)?; - println!("{}\n{}", test, tree); - } - _ => unreachable!(), - } - Ok(()) -} - -fn file() -> Result { - let text = read_stdin()?; - Ok(File::parse(&text)) -} - -fn read_stdin() -> Result { - let mut buff = String::new(); - ::std::io::stdin().read_to_string(&mut buff)?; - Ok(buff) -} - -fn render_test(file: &Path, line: usize) -> Result<(String, String)> { - let text = fs::read_to_string(file)?; - let tests = collect_tests(&text); - let test = tests.into_iter().find(|(start_line, t)| { - *start_line <= line && line <= *start_line + t.text.lines().count() - }); - let test = match test { - None => bail!("No test found at line {} at {}", line, file.display()), - Some((_start_line, test)) => test, - }; - let file = File::parse(&test.text); - let tree = syntax_tree(&file); - Ok((test.text, tree)) -} -- cgit v1.2.3