diff options
Diffstat (limited to 'src/yellow/green.rs')
-rw-r--r-- | src/yellow/green.rs | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/yellow/green.rs b/src/yellow/green.rs index cb9dff128..507e4d57e 100644 --- a/src/yellow/green.rs +++ b/src/yellow/green.rs | |||
@@ -1,5 +1,8 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | use {SyntaxKind::{self, *}, TextUnit}; | 2 | use { |
3 | SyntaxKind::{self, *}, | ||
4 | TextUnit, | ||
5 | }; | ||
3 | 6 | ||
4 | #[derive(Clone, Debug)] | 7 | #[derive(Clone, Debug)] |
5 | pub(crate) enum GreenNode { | 8 | pub(crate) enum GreenNode { |
@@ -36,9 +39,7 @@ impl GreenNode { | |||
36 | fn go(node: &GreenNode, buff: &mut String) { | 39 | fn go(node: &GreenNode, buff: &mut String) { |
37 | match node { | 40 | match node { |
38 | GreenNode::Leaf(l) => buff.push_str(&l.text()), | 41 | GreenNode::Leaf(l) => buff.push_str(&l.text()), |
39 | GreenNode::Branch(b) => { | 42 | GreenNode::Branch(b) => b.children().iter().for_each(|child| go(child, buff)), |
40 | b.children().iter().for_each(|child| go(child, buff)) | ||
41 | } | ||
42 | } | 43 | } |
43 | } | 44 | } |
44 | } | 45 | } |
@@ -71,7 +72,6 @@ impl GreenNodeBuilder { | |||
71 | } | 72 | } |
72 | } | 73 | } |
73 | 74 | ||
74 | |||
75 | #[test] | 75 | #[test] |
76 | fn assert_send_sync() { | 76 | fn assert_send_sync() { |
77 | fn f<T: Send + Sync>() {} | 77 | fn f<T: Send + Sync>() {} |
@@ -80,14 +80,8 @@ fn assert_send_sync() { | |||
80 | 80 | ||
81 | #[derive(Clone, Debug)] | 81 | #[derive(Clone, Debug)] |
82 | pub(crate) enum GreenLeaf { | 82 | pub(crate) enum GreenLeaf { |
83 | Whitespace { | 83 | Whitespace { newlines: u8, spaces: u8 }, |
84 | newlines: u8, | 84 | Token { kind: SyntaxKind, text: Arc<str> }, |
85 | spaces: u8, | ||
86 | }, | ||
87 | Token { | ||
88 | kind: SyntaxKind, | ||
89 | text: Arc<str>, | ||
90 | }, | ||
91 | } | 85 | } |
92 | 86 | ||
93 | impl GreenLeaf { | 87 | impl GreenLeaf { |
@@ -96,10 +90,16 @@ impl GreenLeaf { | |||
96 | let newlines = text.bytes().take_while(|&b| b == b'\n').count(); | 90 | let newlines = text.bytes().take_while(|&b| b == b'\n').count(); |
97 | let spaces = text[newlines..].bytes().take_while(|&b| b == b' ').count(); | 91 | let spaces = text[newlines..].bytes().take_while(|&b| b == b' ').count(); |
98 | if newlines + spaces == text.len() && newlines <= N_NEWLINES && spaces <= N_SPACES { | 92 | if newlines + spaces == text.len() && newlines <= N_NEWLINES && spaces <= N_SPACES { |
99 | return GreenLeaf::Whitespace { newlines: newlines as u8, spaces: spaces as u8 }; | 93 | return GreenLeaf::Whitespace { |
94 | newlines: newlines as u8, | ||
95 | spaces: spaces as u8, | ||
96 | }; | ||
100 | } | 97 | } |
101 | } | 98 | } |
102 | GreenLeaf::Token { kind, text: text.to_owned().into_boxed_str().into() } | 99 | GreenLeaf::Token { |
100 | kind, | ||
101 | text: text.to_owned().into_boxed_str().into(), | ||
102 | } | ||
103 | } | 103 | } |
104 | 104 | ||
105 | pub(crate) fn kind(&self) -> SyntaxKind { | 105 | pub(crate) fn kind(&self) -> SyntaxKind { |
@@ -141,7 +141,11 @@ pub(crate) struct GreenBranch { | |||
141 | impl GreenBranch { | 141 | impl GreenBranch { |
142 | fn new(kind: SyntaxKind, children: Vec<GreenNode>) -> GreenBranch { | 142 | fn new(kind: SyntaxKind, children: Vec<GreenNode>) -> GreenBranch { |
143 | let text_len = children.iter().map(|x| x.text_len()).sum::<TextUnit>(); | 143 | let text_len = children.iter().map(|x| x.text_len()).sum::<TextUnit>(); |
144 | GreenBranch { text_len, kind, children } | 144 | GreenBranch { |
145 | text_len, | ||
146 | kind, | ||
147 | children, | ||
148 | } | ||
145 | } | 149 | } |
146 | 150 | ||
147 | pub fn kind(&self) -> SyntaxKind { | 151 | pub fn kind(&self) -> SyntaxKind { |
@@ -156,4 +160,3 @@ impl GreenBranch { | |||
156 | self.children.as_slice() | 160 | self.children.as_slice() |
157 | } | 161 | } |
158 | } | 162 | } |
159 | |||