diff options
author | Aleksey Kladov <[email protected]> | 2018-07-29 12:37:48 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-07-29 12:37:48 +0100 |
commit | ad188d4c3db34f035408afbdd6d2f3c308121f0a (patch) | |
tree | 0c6cdea50ab664a361fa4c0f6b99cb53ce00529b /src/lib.rs | |
parent | c12450fb4e30c3418555e47d045bb9fd4318a10a (diff) |
kill old tree
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 45 |
1 files changed, 4 insertions, 41 deletions
diff --git a/src/lib.rs b/src/lib.rs index cf2e97024..619ad62e5 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
@@ -26,53 +26,22 @@ mod yellow; | |||
26 | 26 | ||
27 | pub mod syntax_kinds; | 27 | pub mod syntax_kinds; |
28 | pub use text_unit::{TextRange, TextUnit}; | 28 | pub use text_unit::{TextRange, TextUnit}; |
29 | pub use tree::{File, Node, SyntaxKind, Token}; | 29 | pub use tree::{SyntaxKind, Token}; |
30 | pub(crate) use tree::{ErrorMsg, FileBuilder, Sink, GreenBuilder}; | 30 | pub(crate) use tree::{Sink, GreenBuilder}; |
31 | pub use lexer::{next_token, tokenize}; | 31 | pub use lexer::{next_token, tokenize}; |
32 | pub use yellow::SyntaxNode; | 32 | pub use yellow::SyntaxNode; |
33 | pub(crate) use yellow::SError; | 33 | pub(crate) use yellow::SError; |
34 | pub use parser::{parse, parse_green}; | 34 | pub use parser::{parse_green}; |
35 | 35 | ||
36 | /// Utilities for simple uses of the parser. | 36 | /// Utilities for simple uses of the parser. |
37 | pub mod utils { | 37 | pub mod utils { |
38 | use std::fmt::Write; | 38 | use std::fmt::Write; |
39 | 39 | ||
40 | use {File, Node, SyntaxNode}; | 40 | use {SyntaxNode}; |
41 | use std::collections::BTreeSet; | 41 | use std::collections::BTreeSet; |
42 | use SError; | 42 | use SError; |
43 | 43 | ||
44 | /// Parse a file and create a string representation of the resulting parse tree. | 44 | /// Parse a file and create a string representation of the resulting parse tree. |
45 | pub fn dump_tree(file: &File) -> String { | ||
46 | let mut result = String::new(); | ||
47 | go(file.root(), &mut result, 0); | ||
48 | return result; | ||
49 | |||
50 | fn go(node: Node, buff: &mut String, level: usize) { | ||
51 | buff.push_str(&String::from(" ").repeat(level)); | ||
52 | write!(buff, "{:?}\n", node).unwrap(); | ||
53 | let my_errors = node.errors().filter(|e| e.after_child().is_none()); | ||
54 | let parent_errors = node.parent() | ||
55 | .into_iter() | ||
56 | .flat_map(|n| n.errors()) | ||
57 | .filter(|e| e.after_child() == Some(node)); | ||
58 | |||
59 | for err in my_errors { | ||
60 | buff.push_str(&String::from(" ").repeat(level)); | ||
61 | write!(buff, "err: `{}`\n", err.message()).unwrap(); | ||
62 | } | ||
63 | |||
64 | for child in node.children() { | ||
65 | go(child, buff, level + 1) | ||
66 | } | ||
67 | |||
68 | for err in parent_errors { | ||
69 | buff.push_str(&String::from(" ").repeat(level)); | ||
70 | write!(buff, "err: `{}`\n", err.message()).unwrap(); | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | /// Parse a file and create a string representation of the resulting parse tree. | ||
76 | pub fn dump_tree_green(syntax: &SyntaxNode) -> String { | 45 | pub fn dump_tree_green(syntax: &SyntaxNode) -> String { |
77 | let mut errors: BTreeSet<_> = syntax.root.errors.iter().cloned().collect(); | 46 | let mut errors: BTreeSet<_> = syntax.root.errors.iter().cloned().collect(); |
78 | let mut result = String::new(); | 47 | let mut result = String::new(); |
@@ -82,12 +51,6 @@ pub mod utils { | |||
82 | fn go(node: &SyntaxNode, buff: &mut String, level: usize, errors: &mut BTreeSet<SError>) { | 51 | fn go(node: &SyntaxNode, buff: &mut String, level: usize, errors: &mut BTreeSet<SError>) { |
83 | buff.push_str(&String::from(" ").repeat(level)); | 52 | buff.push_str(&String::from(" ").repeat(level)); |
84 | write!(buff, "{:?}\n", node).unwrap(); | 53 | write!(buff, "{:?}\n", node).unwrap(); |
85 | // let my_errors = node.errors().filter(|e| e.after_child().is_none()); | ||
86 | // let parent_errors = node.parent() | ||
87 | // .into_iter() | ||
88 | // .flat_map(|n| n.errors()) | ||
89 | // .filter(|e| e.after_child() == Some(node)); | ||
90 | // | ||
91 | let my_errors: Vec<_> = errors.iter().filter(|e| e.offset == node.range().start()) | 54 | let my_errors: Vec<_> = errors.iter().filter(|e| e.offset == node.range().start()) |
92 | .cloned().collect(); | 55 | .cloned().collect(); |
93 | for err in my_errors { | 56 | for err in my_errors { |