diff options
Diffstat (limited to 'src/yellow')
-rw-r--r-- | src/yellow/green.rs | 12 | ||||
-rw-r--r-- | src/yellow/mod.rs | 2 | ||||
-rw-r--r-- | src/yellow/red.rs | 5 | ||||
-rw-r--r-- | src/yellow/syntax.rs | 12 |
4 files changed, 18 insertions, 13 deletions
diff --git a/src/yellow/green.rs b/src/yellow/green.rs index cda4e2167..8ddcc74b8 100644 --- a/src/yellow/green.rs +++ b/src/yellow/green.rs | |||
@@ -80,8 +80,14 @@ 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 { newlines: u8, spaces: u8 }, | 83 | Whitespace { |
84 | Token { kind: SyntaxKind, text: Option<Arc<str>> }, | 84 | newlines: u8, |
85 | spaces: u8, | ||
86 | }, | ||
87 | Token { | ||
88 | kind: SyntaxKind, | ||
89 | text: Option<Arc<str>>, | ||
90 | }, | ||
85 | } | 91 | } |
86 | 92 | ||
87 | impl GreenLeaf { | 93 | impl GreenLeaf { |
@@ -121,7 +127,7 @@ impl GreenLeaf { | |||
121 | assert!(newlines <= N_NEWLINES && spaces <= N_SPACES); | 127 | assert!(newlines <= N_NEWLINES && spaces <= N_SPACES); |
122 | &WS[N_NEWLINES - newlines..N_NEWLINES + spaces] | 128 | &WS[N_NEWLINES - newlines..N_NEWLINES + spaces] |
123 | } | 129 | } |
124 | GreenLeaf::Token { kind, text, } => match text { | 130 | GreenLeaf::Token { kind, text } => match text { |
125 | None => kind.static_text().unwrap(), | 131 | None => kind.static_text().unwrap(), |
126 | Some(t) => t, | 132 | Some(t) => t, |
127 | }, | 133 | }, |
diff --git a/src/yellow/mod.rs b/src/yellow/mod.rs index 0cc90adbd..f20be356d 100644 --- a/src/yellow/mod.rs +++ b/src/yellow/mod.rs | |||
@@ -8,5 +8,5 @@ pub(crate) use self::{ | |||
8 | builder::GreenBuilder, | 8 | builder::GreenBuilder, |
9 | green::{GreenNode, GreenNodeBuilder}, | 9 | green::{GreenNode, GreenNodeBuilder}, |
10 | red::RedNode, | 10 | red::RedNode, |
11 | syntax::{SyntaxError}, | 11 | syntax::SyntaxError, |
12 | }; | 12 | }; |
diff --git a/src/yellow/red.rs b/src/yellow/red.rs index a30318c6e..c3d6c5f4f 100644 --- a/src/yellow/red.rs +++ b/src/yellow/red.rs | |||
@@ -36,7 +36,8 @@ impl RedNode { | |||
36 | 36 | ||
37 | fn new(green: GreenNode, parent: Option<ParentData>) -> RedNode { | 37 | fn new(green: GreenNode, parent: Option<ParentData>) -> RedNode { |
38 | let n_children = green.children().len(); | 38 | let n_children = green.children().len(); |
39 | let children = (0..n_children).map(|_| None) | 39 | let children = (0..n_children) |
40 | .map(|_| None) | ||
40 | .collect::<Vec<_>>() | 41 | .collect::<Vec<_>>() |
41 | .into_boxed_slice(); | 42 | .into_boxed_slice(); |
42 | RedNode { | 43 | RedNode { |
@@ -63,7 +64,7 @@ impl RedNode { | |||
63 | 64 | ||
64 | pub(crate) fn get_child(&self, idx: usize) -> Option<ptr::NonNull<RedNode>> { | 65 | pub(crate) fn get_child(&self, idx: usize) -> Option<ptr::NonNull<RedNode>> { |
65 | if idx >= self.n_children() { | 66 | if idx >= self.n_children() { |
66 | return None | 67 | return None; |
67 | } | 68 | } |
68 | match &self.children.read().unwrap()[idx] { | 69 | match &self.children.read().unwrap()[idx] { |
69 | Some(child) => return Some(child.into()), | 70 | Some(child) => return Some(child.into()), |
diff --git a/src/yellow/syntax.rs b/src/yellow/syntax.rs index 41dcf3761..487a4ef1d 100644 --- a/src/yellow/syntax.rs +++ b/src/yellow/syntax.rs | |||
@@ -6,7 +6,7 @@ use { | |||
6 | TextRange, TextUnit, | 6 | TextRange, TextUnit, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | pub trait TreeRoot: Deref<Target=SyntaxRoot> + Clone {} | 9 | pub trait TreeRoot: Deref<Target = SyntaxRoot> + Clone {} |
10 | 10 | ||
11 | impl TreeRoot for Arc<SyntaxRoot> {} | 11 | impl TreeRoot for Arc<SyntaxRoot> {} |
12 | 12 | ||
@@ -83,14 +83,12 @@ impl<R: TreeRoot> SyntaxNode<R> { | |||
83 | self.red().green().text() | 83 | self.red().green().text() |
84 | } | 84 | } |
85 | 85 | ||
86 | pub fn children<'a>(&'a self) -> impl Iterator<Item=SyntaxNode<R>> + 'a { | 86 | pub fn children<'a>(&'a self) -> impl Iterator<Item = SyntaxNode<R>> + 'a { |
87 | let red = self.red(); | 87 | let red = self.red(); |
88 | let n_children = red.n_children(); | 88 | let n_children = red.n_children(); |
89 | (0..n_children).map(move |i| { | 89 | (0..n_children).map(move |i| SyntaxNode { |
90 | SyntaxNode { | 90 | root: self.root.clone(), |
91 | root: self.root.clone(), | 91 | red: red.get_child(i).unwrap(), |
92 | red: red.get_child(i).unwrap(), | ||
93 | } | ||
94 | }) | 92 | }) |
95 | } | 93 | } |
96 | 94 | ||