diff options
author | Aleksey Kladov <[email protected]> | 2018-08-05 17:06:14 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-05 17:06:14 +0100 |
commit | 80366e90f5c1b809c8902e42dced42c0dc9d92ac (patch) | |
tree | d0c7c97a47bdb9375325569020290738e859eff7 /cli/src | |
parent | 60ba52b3e022aa88b011295b38fcf50fe440d1f9 (diff) |
File symnols
Diffstat (limited to 'cli/src')
-rw-r--r-- | cli/src/main.rs | 35 |
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 @@ | |||
1 | extern crate clap; | 1 | extern crate clap; |
2 | #[macro_use] | 2 | #[macro_use] |
3 | extern crate failure; | 3 | extern crate failure; |
4 | extern crate libsyntax2; | 4 | extern crate libeditor; |
5 | extern crate tools; | 5 | extern crate tools; |
6 | 6 | ||
7 | use std::{ | ||
8 | fs, io::Read, path::Path, | ||
9 | time::Instant | ||
10 | }; | ||
7 | use clap::{App, Arg, SubCommand}; | 11 | use clap::{App, Arg, SubCommand}; |
8 | use std::time::Instant; | ||
9 | use std::{fs, io::Read, path::Path}; | ||
10 | use tools::collect_tests; | 12 | use tools::collect_tests; |
13 | use libeditor::File; | ||
11 | 14 | ||
12 | type Result<T> = ::std::result::Result<T, failure::Error>; | 15 | type 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 | ||
52 | fn parse() -> Result<String> { | 65 | fn 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 | ||
61 | fn read_stdin() -> Result<String> { | 70 | fn 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 | } |