aboutsummaryrefslogtreecommitdiff
path: root/src/yellow/green.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-30 12:08:06 +0100
committerAleksey Kladov <[email protected]>2018-07-30 12:08:06 +0100
commit1edb58a802f183f79dc2c4bc15921394ef8abb31 (patch)
tree24114171c61a9f433b9a54008057fa0297f91302 /src/yellow/green.rs
parent6983091d6d255bcfd17c4f8c14015d8abc77928d (diff)
reformat
Diffstat (limited to 'src/yellow/green.rs')
-rw-r--r--src/yellow/green.rs37
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 @@
1use std::sync::Arc; 1use std::sync::Arc;
2use {SyntaxKind::{self, *}, TextUnit}; 2use {
3 SyntaxKind::{self, *},
4 TextUnit,
5};
3 6
4#[derive(Clone, Debug)] 7#[derive(Clone, Debug)]
5pub(crate) enum GreenNode { 8pub(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]
76fn assert_send_sync() { 76fn 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)]
82pub(crate) enum GreenLeaf { 82pub(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
93impl GreenLeaf { 87impl 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 {
141impl GreenBranch { 141impl 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