aboutsummaryrefslogtreecommitdiff
path: root/cli/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-05 17:06:14 +0100
committerAleksey Kladov <[email protected]>2018-08-05 17:06:14 +0100
commit80366e90f5c1b809c8902e42dced42c0dc9d92ac (patch)
treed0c7c97a47bdb9375325569020290738e859eff7 /cli/src
parent60ba52b3e022aa88b011295b38fcf50fe440d1f9 (diff)
File symnols
Diffstat (limited to 'cli/src')
-rw-r--r--cli/src/main.rs35
1 files changed, 22 insertions, 13 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs
index 0044841ed..a3a317c69 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -1,13 +1,16 @@
1extern crate clap; 1extern crate clap;
2#[macro_use] 2#[macro_use]
3extern crate failure; 3extern crate failure;
4extern crate libsyntax2; 4extern crate libeditor;
5extern crate tools; 5extern crate tools;
6 6
7use std::{
8 fs, io::Read, path::Path,
9 time::Instant
10};
7use clap::{App, Arg, SubCommand}; 11use clap::{App, Arg, SubCommand};
8use std::time::Instant;
9use std::{fs, io::Read, path::Path};
10use tools::collect_tests; 12use tools::collect_tests;
13use libeditor::File;
11 14
12type Result<T> = ::std::result::Result<T, failure::Error>; 15type Result<T> = ::std::result::Result<T, failure::Error>;
13 16
@@ -30,11 +33,21 @@ fn main() -> Result<()> {
30 ), 33 ),
31 ) 34 )
32 .subcommand(SubCommand::with_name("parse")) 35 .subcommand(SubCommand::with_name("parse"))
36 .subcommand(SubCommand::with_name("symbols"))
33 .get_matches(); 37 .get_matches();
34 match matches.subcommand() { 38 match matches.subcommand() {
35 ("parse", _) => { 39 ("parse", _) => {
36 let tree = parse()?; 40 let start = Instant::now();
37 println!("{}", tree); 41 let file = file()?;
42 let elapsed = start.elapsed();
43 println!("{}", file.syntax_tree());
44 eprintln!("parsing: {:?}", elapsed);
45 }
46 ("symbols", _) => {
47 let file = file()?;
48 for s in file.symbols() {
49 println!("{:?}", s);
50 }
38 } 51 }
39 ("render-test", Some(matches)) => { 52 ("render-test", Some(matches)) => {
40 let file = matches.value_of("file").unwrap(); 53 let file = matches.value_of("file").unwrap();
@@ -49,13 +62,9 @@ fn main() -> Result<()> {
49 Ok(()) 62 Ok(())
50} 63}
51 64
52fn parse() -> Result<String> { 65fn file() -> Result<File> {
53 let text = read_stdin()?; 66 let text = read_stdin()?;
54 let start = Instant::now(); 67 Ok(File::new(&text))
55 let file = libsyntax2::parse(&text);
56 eprintln!("elapsed {:?}", start.elapsed());
57 let tree = libsyntax2::utils::dump_tree(&file);
58 Ok(tree)
59} 68}
60 69
61fn read_stdin() -> Result<String> { 70fn read_stdin() -> Result<String> {
@@ -74,7 +83,7 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> {
74 None => bail!("No test found at line {} at {}", line, file.display()), 83 None => bail!("No test found at line {} at {}", line, file.display()),
75 Some((_start_line, test)) => test, 84 Some((_start_line, test)) => test,
76 }; 85 };
77 let file = libsyntax2::parse(&test.text); 86 let file = File::new(&test.text);
78 let tree = libsyntax2::utils::dump_tree(&file); 87 let tree = file.syntax_tree();
79 Ok((test.text, tree)) 88 Ok((test.text, tree))
80} 89}