diff options
author | Aleksey Kladov <[email protected]> | 2018-08-10 20:33:29 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-10 20:33:29 +0100 |
commit | 7c67612b8a894187fa3b64725531a5459f9211bf (patch) | |
tree | 9e2a536efa0c880d921fd8d4d74423afc9451fd4 /src/utils.rs | |
parent | 26262aaf05983c5b7f41cc438e287523268fe1eb (diff) |
organizize
Diffstat (limited to 'src/utils.rs')
-rw-r--r-- | src/utils.rs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/src/utils.rs b/src/utils.rs deleted file mode 100644 index 1fbb872a5..000000000 --- a/src/utils.rs +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | use std::fmt::Write; | ||
2 | use { | ||
3 | algo::walk::{walk, WalkEvent}, | ||
4 | SyntaxNode, | ||
5 | }; | ||
6 | |||
7 | /// Parse a file and create a string representation of the resulting parse tree. | ||
8 | pub fn dump_tree(syntax: &SyntaxNode) -> String { | ||
9 | let syntax = syntax.as_ref(); | ||
10 | let mut errors: Vec<_> = syntax.root.errors.iter().cloned().collect(); | ||
11 | errors.sort_by_key(|e| e.offset); | ||
12 | let mut err_pos = 0; | ||
13 | let mut level = 0; | ||
14 | let mut buf = String::new(); | ||
15 | macro_rules! indent { | ||
16 | () => { | ||
17 | for _ in 0..level { | ||
18 | buf.push_str(" "); | ||
19 | } | ||
20 | }; | ||
21 | } | ||
22 | |||
23 | for event in walk(syntax) { | ||
24 | match event { | ||
25 | WalkEvent::Enter(node) => { | ||
26 | indent!(); | ||
27 | writeln!(buf, "{:?}", node).unwrap(); | ||
28 | if node.first_child().is_none() { | ||
29 | let off = node.range().end(); | ||
30 | while err_pos < errors.len() && errors[err_pos].offset <= off { | ||
31 | indent!(); | ||
32 | writeln!(buf, "err: `{}`", errors[err_pos].msg).unwrap(); | ||
33 | err_pos += 1; | ||
34 | } | ||
35 | } | ||
36 | level += 1; | ||
37 | } | ||
38 | WalkEvent::Exit(_) => level -= 1, | ||
39 | } | ||
40 | } | ||
41 | |||
42 | assert_eq!(level, 0); | ||
43 | for err in errors[err_pos..].iter() { | ||
44 | writeln!(buf, "err: `{}`", err.msg).unwrap(); | ||
45 | } | ||
46 | |||
47 | return buf; | ||
48 | } | ||