From 80366e90f5c1b809c8902e42dced42c0dc9d92ac Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 5 Aug 2018 19:06:14 +0300 Subject: File symnols --- cli/Cargo.toml | 2 +- cli/src/main.rs | 35 ++++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) (limited to 'cli') diff --git a/cli/Cargo.toml b/cli/Cargo.toml index a259eef63..ac89a48d3 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -7,5 +7,5 @@ publish = false [dependencies] clap = "2.32.0" failure = "0.1.1" -libsyntax2 = { path = "../" } +libeditor = { path = "../libeditor" } tools = { path = "../tools" } 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 @@ 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 std::time::Instant; -use std::{fs, io::Read, path::Path}; use tools::collect_tests; +use libeditor::File; type Result = ::std::result::Result; @@ -30,11 +33,21 @@ fn main() -> Result<()> { ), ) .subcommand(SubCommand::with_name("parse")) + .subcommand(SubCommand::with_name("symbols")) .get_matches(); match matches.subcommand() { ("parse", _) => { - let tree = parse()?; - println!("{}", tree); + let start = Instant::now(); + let file = file()?; + let elapsed = start.elapsed(); + println!("{}", file.syntax_tree()); + eprintln!("parsing: {:?}", elapsed); + } + ("symbols", _) => { + let file = file()?; + for s in file.symbols() { + println!("{:?}", s); + } } ("render-test", Some(matches)) => { let file = matches.value_of("file").unwrap(); @@ -49,13 +62,9 @@ fn main() -> Result<()> { Ok(()) } -fn parse() -> Result { +fn file() -> Result { let text = read_stdin()?; - let start = Instant::now(); - let file = libsyntax2::parse(&text); - eprintln!("elapsed {:?}", start.elapsed()); - let tree = libsyntax2::utils::dump_tree(&file); - Ok(tree) + Ok(File::new(&text)) } fn read_stdin() -> Result { @@ -74,7 +83,7 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> { None => bail!("No test found at line {} at {}", line, file.display()), Some((_start_line, test)) => test, }; - let file = libsyntax2::parse(&test.text); - let tree = libsyntax2::utils::dump_tree(&file); + let file = File::new(&test.text); + let tree = file.syntax_tree(); Ok((test.text, tree)) } -- cgit v1.2.3