diff options
author | Aleksey Kladov <[email protected]> | 2018-01-21 23:12:26 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-21 23:12:26 +0000 |
commit | 05ad469ac33965f76ccc0f5b8a9959695b8979a0 (patch) | |
tree | 1212adb51b8970a458c322cf687f625c5ef612e7 /tests/parser.rs | |
parent | c8cf1d8cdac48f48caf9505bd5dc20dd2b962317 (diff) |
Command-line utilty to print the parse tree
Diffstat (limited to 'tests/parser.rs')
-rw-r--r-- | tests/parser.rs | 34 |
1 files changed, 2 insertions, 32 deletions
diff --git a/tests/parser.rs b/tests/parser.rs index 02cef938d..370b02c74 100644 --- a/tests/parser.rs +++ b/tests/parser.rs | |||
@@ -2,9 +2,8 @@ extern crate file; | |||
2 | extern crate libsyntax2; | 2 | extern crate libsyntax2; |
3 | extern crate testutils; | 3 | extern crate testutils; |
4 | 4 | ||
5 | use std::fmt::Write; | 5 | use libsyntax2::{tokenize, parse}; |
6 | 6 | use libsyntax2::utils::dump_tree; | |
7 | use libsyntax2::{tokenize, parse, Node, File}; | ||
8 | use testutils::dir_tests; | 7 | use testutils::dir_tests; |
9 | 8 | ||
10 | #[test] | 9 | #[test] |
@@ -18,32 +17,3 @@ fn parser_tests() { | |||
18 | } | 17 | } |
19 | ) | 18 | ) |
20 | } | 19 | } |
21 | |||
22 | fn dump_tree(file: &File) -> String { | ||
23 | let mut result = String::new(); | ||
24 | go(file.root(), &mut result, 0); | ||
25 | return result; | ||
26 | |||
27 | fn go(node: Node, buff: &mut String, level: usize) { | ||
28 | buff.push_str(&String::from(" ").repeat(level)); | ||
29 | write!(buff, "{:?}\n", node).unwrap(); | ||
30 | let my_errors = node.errors().filter(|e| e.after_child().is_none()); | ||
31 | let parent_errors = node.parent().into_iter() | ||
32 | .flat_map(|n| n.errors()) | ||
33 | .filter(|e| e.after_child() == Some(node)); | ||
34 | |||
35 | for err in my_errors { | ||
36 | buff.push_str(&String::from(" ").repeat(level)); | ||
37 | write!(buff, "err: `{}`\n", err.message()).unwrap(); | ||
38 | } | ||
39 | |||
40 | for child in node.children() { | ||
41 | go(child, buff, level + 1) | ||
42 | } | ||
43 | |||
44 | for err in parent_errors { | ||
45 | buff.push_str(&String::from(" ").repeat(level)); | ||
46 | write!(buff, "err: `{}`\n", err.message()).unwrap(); | ||
47 | } | ||
48 | } | ||
49 | } | ||