aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/yellow.rs52
1 files changed, 45 insertions, 7 deletions
diff --git a/crates/ra_syntax/src/yellow.rs b/crates/ra_syntax/src/yellow.rs
index 6dc846f33..38e680a9c 100644
--- a/crates/ra_syntax/src/yellow.rs
+++ b/crates/ra_syntax/src/yellow.rs
@@ -18,19 +18,56 @@ impl Types for RaTypes {
18 type RootData = Vec<SyntaxError>; 18 type RootData = Vec<SyntaxError>;
19} 19}
20 20
21pub type GreenNode = ::rowan::GreenNode<RaTypes>; 21pub type GreenNode = rowan::GreenNode<RaTypes>;
22pub type TreePtr<T> = ::rowan::TreePtr<RaTypes, T>; 22
23#[derive(Clone, PartialEq, Eq, Hash)]
24pub struct TreePtr<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>(
25 pub(crate) rowan::TreePtr<RaTypes, T>,
26);
27
28impl<T> TreePtr<T>
29where
30 T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,
31{
32 pub(crate) fn cast<U>(this: TreePtr<T>) -> TreePtr<U>
33 where
34 U: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,
35 {
36 TreePtr(rowan::TreePtr::cast(this.0))
37 }
38}
39
40impl<T> std::ops::Deref for TreePtr<T>
41where
42 T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,
43{
44 type Target = T;
45 fn deref(&self) -> &T {
46 self.0.deref()
47 }
48}
49
50impl<T> fmt::Debug for TreePtr<T>
51where
52 T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,
53 T: fmt::Debug,
54{
55 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
56 fmt::Debug::fmt(&self.0, fmt)
57 }
58}
23 59
24#[derive(PartialEq, Eq, Hash)] 60#[derive(PartialEq, Eq, Hash)]
25#[repr(transparent)] 61#[repr(transparent)]
26pub struct SyntaxNode(pub(crate) ::rowan::SyntaxNode<RaTypes>); 62pub struct SyntaxNode(pub(crate) rowan::SyntaxNode<RaTypes>);
27unsafe impl TransparentNewType for SyntaxNode { 63unsafe impl TransparentNewType for SyntaxNode {
28 type Repr = ::rowan::SyntaxNode<RaTypes>; 64 type Repr = rowan::SyntaxNode<RaTypes>;
29} 65}
30 66
31impl SyntaxNode { 67impl SyntaxNode {
32 pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> TreePtr<SyntaxNode> { 68 pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> TreePtr<SyntaxNode> {
33 TreePtr::cast(::rowan::SyntaxNode::new(green, errors)) 69 let ptr = TreePtr(rowan::SyntaxNode::new(green, errors));
70 TreePtr::cast(ptr)
34 } 71 }
35} 72}
36 73
@@ -75,7 +112,8 @@ impl SyntaxNode {
75 self.0.replace_self(replacement) 112 self.0.replace_self(replacement)
76 } 113 }
77 pub fn to_owned(&self) -> TreePtr<SyntaxNode> { 114 pub fn to_owned(&self) -> TreePtr<SyntaxNode> {
78 TreePtr::cast(self.0.to_owned()) 115 let ptr = TreePtr(self.0.to_owned());
116 TreePtr::cast(ptr)
79 } 117 }
80 pub fn kind(&self) -> SyntaxKind { 118 pub fn kind(&self) -> SyntaxKind {
81 self.0.kind() 119 self.0.kind()
@@ -120,7 +158,7 @@ impl fmt::Debug for SyntaxNode {
120} 158}
121 159
122#[derive(Debug)] 160#[derive(Debug)]
123pub struct SyntaxNodeChildren<'a>(::rowan::SyntaxNodeChildren<'a, RaTypes>); 161pub struct SyntaxNodeChildren<'a>(rowan::SyntaxNodeChildren<'a, RaTypes>);
124 162
125impl<'a> Iterator for SyntaxNodeChildren<'a> { 163impl<'a> Iterator for SyntaxNodeChildren<'a> {
126 type Item = &'a SyntaxNode; 164 type Item = &'a SyntaxNode;