aboutsummaryrefslogtreecommitdiff
path: root/crates/cli
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-16 10:54:24 +0100
committerAleksey Kladov <[email protected]>2018-09-16 11:07:39 +0100
commitb5021411a84822cb3f1e3aeffad9550dd15bdeb6 (patch)
tree9dca564f8e51b298dced01c4ce669c756dce3142 /crates/cli
parentba0bfeee12e19da40b5eabc8d0408639af10e96f (diff)
rename all things
Diffstat (limited to 'crates/cli')
-rw-r--r--crates/cli/Cargo.toml12
-rw-r--r--crates/cli/src/main.rs97
2 files changed, 0 insertions, 109 deletions
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 @@
1[package]
2name = "cli"
3version = "0.1.0"
4authors = ["Aleksey Kladov <[email protected]>"]
5publish = false
6
7[dependencies]
8clap = "2.32.0"
9failure = "0.1.1"
10libsyntax2 = { path = "../libsyntax2" }
11libeditor = { path = "../libeditor" }
12tools = { 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 @@
1extern crate clap;
2#[macro_use]
3extern crate failure;
4extern crate libsyntax2;
5extern crate libeditor;
6extern crate tools;
7
8use std::{
9 fs, io::Read, path::Path,
10 time::Instant
11};
12use clap::{App, Arg, SubCommand};
13use tools::collect_tests;
14use libsyntax2::File;
15use libeditor::{syntax_tree, file_structure};
16
17type Result<T> = ::std::result::Result<T, failure::Error>;
18
19fn main() -> Result<()> {
20 let matches = App::new("libsyntax2-cli")
21 .setting(clap::AppSettings::SubcommandRequiredElseHelp)
22 .subcommand(
23 SubCommand::with_name("render-test")
24 .arg(
25 Arg::with_name("line")
26 .long("--line")
27 .required(true)
28 .takes_value(true),
29 )
30 .arg(
31 Arg::with_name("file")
32 .long("--file")
33 .required(true)
34 .takes_value(true),
35 ),
36 )
37 .subcommand(
38 SubCommand::with_name("parse")
39 .arg(Arg::with_name("no-dump").long("--no-dump"))
40 )
41 .subcommand(SubCommand::with_name("symbols"))
42 .get_matches();
43 match matches.subcommand() {
44 ("parse", Some(matches)) => {
45 let start = Instant::now();
46 let file = file()?;
47 let elapsed = start.elapsed();
48 if !matches.is_present("no-dump") {
49 println!("{}", syntax_tree(&file));
50 }
51 eprintln!("parsing: {:?}", elapsed);
52 ::std::mem::forget(file);
53 }
54 ("symbols", _) => {
55 let file = file()?;
56 for s in file_structure(&file) {
57 println!("{:?}", s);
58 }
59 }
60 ("render-test", Some(matches)) => {
61 let file = matches.value_of("file").unwrap();
62 let file = Path::new(file);
63 let line: usize = matches.value_of("line").unwrap().parse()?;
64 let line = line - 1;
65 let (test, tree) = render_test(file, line)?;
66 println!("{}\n{}", test, tree);
67 }
68 _ => unreachable!(),
69 }
70 Ok(())
71}
72
73fn file() -> Result<File> {
74 let text = read_stdin()?;
75 Ok(File::parse(&text))
76}
77
78fn read_stdin() -> Result<String> {
79 let mut buff = String::new();
80 ::std::io::stdin().read_to_string(&mut buff)?;
81 Ok(buff)
82}
83
84fn render_test(file: &Path, line: usize) -> Result<(String, String)> {
85 let text = fs::read_to_string(file)?;
86 let tests = collect_tests(&text);
87 let test = tests.into_iter().find(|(start_line, t)| {
88 *start_line <= line && line <= *start_line + t.text.lines().count()
89 });
90 let test = match test {
91 None => bail!("No test found at line {} at {}", line, file.display()),
92 Some((_start_line, test)) => test,
93 };
94 let file = File::parse(&test.text);
95 let tree = syntax_tree(&file);
96 Ok((test.text, tree))
97}