diff options
author | Christopher Durham <[email protected]> | 2018-01-27 23:51:12 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2018-01-27 23:51:12 +0000 |
commit | e6e61251abb68b3e6a47fd3708f4dea6059a9ec3 (patch) | |
tree | c22cfa06a26add11f3aefca3806f0009dd25d923 /src/tree/mod.rs | |
parent | 357cd3358167daa38f3ff34d225e1501faff6015 (diff) | |
parent | 9140b3e7286efae57ee8c49c7bfcad8737f9c6fc (diff) |
Merge pull request #12 from CAD97/enforce-fmt
Enforce rustfmt format
Diffstat (limited to 'src/tree/mod.rs')
-rw-r--r-- | src/tree/mod.rs | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 3315b926e..a330caf54 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use text::{TextUnit, TextRange}; | 1 | use text::{TextRange, TextUnit}; |
2 | use syntax_kinds::syntax_info; | 2 | use syntax_kinds::syntax_info; |
3 | 3 | ||
4 | use std::fmt; | 4 | use std::fmt; |
@@ -11,15 +11,10 @@ pub use self::file_builder::{FileBuilder, Sink}; | |||
11 | pub struct SyntaxKind(pub(crate) u32); | 11 | pub struct SyntaxKind(pub(crate) u32); |
12 | 12 | ||
13 | pub(crate) const EOF: SyntaxKind = SyntaxKind(!0); | 13 | pub(crate) const EOF: SyntaxKind = SyntaxKind(!0); |
14 | pub(crate) const EOF_INFO: SyntaxInfo = SyntaxInfo { | 14 | pub(crate) const EOF_INFO: SyntaxInfo = SyntaxInfo { name: "EOF" }; |
15 | name: "EOF" | ||
16 | }; | ||
17 | 15 | ||
18 | pub(crate) const TOMBSTONE: SyntaxKind = SyntaxKind(!0 - 1); | 16 | pub(crate) const TOMBSTONE: SyntaxKind = SyntaxKind(!0 - 1); |
19 | pub(crate) const TOMBSTONE_INFO: SyntaxInfo = SyntaxInfo { | 17 | pub(crate) const TOMBSTONE_INFO: SyntaxInfo = SyntaxInfo { name: "TOMBSTONE" }; |
20 | name: "TOMBSTONE" | ||
21 | }; | ||
22 | |||
23 | 18 | ||
24 | impl SyntaxKind { | 19 | impl SyntaxKind { |
25 | fn info(self) -> &'static SyntaxInfo { | 20 | fn info(self) -> &'static SyntaxInfo { |
@@ -38,7 +33,6 @@ impl fmt::Debug for SyntaxKind { | |||
38 | } | 33 | } |
39 | } | 34 | } |
40 | 35 | ||
41 | |||
42 | pub(crate) struct SyntaxInfo { | 36 | pub(crate) struct SyntaxInfo { |
43 | pub name: &'static str, | 37 | pub name: &'static str, |
44 | } | 38 | } |
@@ -58,7 +52,10 @@ pub struct File { | |||
58 | impl File { | 52 | impl File { |
59 | pub fn root<'f>(&'f self) -> Node<'f> { | 53 | pub fn root<'f>(&'f self) -> Node<'f> { |
60 | assert!(!self.nodes.is_empty()); | 54 | assert!(!self.nodes.is_empty()); |
61 | Node { file: self, idx: NodeIdx(0) } | 55 | Node { |
56 | file: self, | ||
57 | idx: NodeIdx(0), | ||
58 | } | ||
62 | } | 59 | } |
63 | } | 60 | } |
64 | 61 | ||
@@ -86,14 +83,17 @@ impl<'f> Node<'f> { | |||
86 | } | 83 | } |
87 | 84 | ||
88 | pub fn children(&self) -> Children<'f> { | 85 | pub fn children(&self) -> Children<'f> { |
89 | Children { next: self.as_node(self.data().first_child) } | 86 | Children { |
87 | next: self.as_node(self.data().first_child), | ||
88 | } | ||
90 | } | 89 | } |
91 | 90 | ||
92 | pub fn errors(&self) -> SyntaxErrors<'f> { | 91 | pub fn errors(&self) -> SyntaxErrors<'f> { |
93 | let pos = self.file.errors.iter().position(|e| e.node == self.idx); | 92 | let pos = self.file.errors.iter().position(|e| e.node == self.idx); |
94 | let next = pos | 93 | let next = pos.map(|i| ErrorIdx(i as u32)).map(|idx| SyntaxError { |
95 | .map(|i| ErrorIdx(i as u32)) | 94 | file: self.file, |
96 | .map(|idx| SyntaxError { file: self.file, idx }); | 95 | idx, |
96 | }); | ||
97 | SyntaxErrors { next } | 97 | SyntaxErrors { next } |
98 | } | 98 | } |
99 | 99 | ||
@@ -102,7 +102,10 @@ impl<'f> Node<'f> { | |||
102 | } | 102 | } |
103 | 103 | ||
104 | fn as_node(&self, idx: Option<NodeIdx>) -> Option<Node<'f>> { | 104 | fn as_node(&self, idx: Option<NodeIdx>) -> Option<Node<'f>> { |
105 | idx.map(|idx| Node { file: self.file, idx }) | 105 | idx.map(|idx| Node { |
106 | file: self.file, | ||
107 | idx, | ||
108 | }) | ||
106 | } | 109 | } |
107 | } | 110 | } |
108 | 111 | ||
@@ -118,8 +121,7 @@ impl<'f> cmp::PartialEq<Node<'f>> for Node<'f> { | |||
118 | } | 121 | } |
119 | } | 122 | } |
120 | 123 | ||
121 | impl<'f> cmp::Eq for Node<'f> { | 124 | impl<'f> cmp::Eq for Node<'f> {} |
122 | } | ||
123 | 125 | ||
124 | #[derive(Clone, Copy)] | 126 | #[derive(Clone, Copy)] |
125 | pub struct SyntaxError<'f> { | 127 | pub struct SyntaxError<'f> { |
@@ -134,7 +136,10 @@ impl<'f> SyntaxError<'f> { | |||
134 | 136 | ||
135 | pub fn after_child(&self) -> Option<Node<'f>> { | 137 | pub fn after_child(&self) -> Option<Node<'f>> { |
136 | let idx = self.data().after_child?; | 138 | let idx = self.data().after_child?; |
137 | Some(Node { file: self.file, idx }) | 139 | Some(Node { |
140 | file: self.file, | ||
141 | idx, | ||
142 | }) | ||
138 | } | 143 | } |
139 | 144 | ||
140 | fn data(&self) -> &'f SyntaxErrorData { | 145 | fn data(&self) -> &'f SyntaxErrorData { |
@@ -148,7 +153,7 @@ impl<'f> SyntaxError<'f> { | |||
148 | } | 153 | } |
149 | let result = SyntaxError { | 154 | let result = SyntaxError { |
150 | file: self.file, | 155 | file: self.file, |
151 | idx: ErrorIdx(next_idx) | 156 | idx: ErrorIdx(next_idx), |
152 | }; | 157 | }; |
153 | if result.data().node != self.data().node { | 158 | if result.data().node != self.data().node { |
154 | return None; | 159 | return None; |
@@ -185,7 +190,6 @@ impl<'f> Iterator for SyntaxErrors<'f> { | |||
185 | } | 190 | } |
186 | } | 191 | } |
187 | 192 | ||
188 | |||
189 | #[derive(Clone, Copy, PartialEq, Eq)] | 193 | #[derive(Clone, Copy, PartialEq, Eq)] |
190 | struct NodeIdx(u32); | 194 | struct NodeIdx(u32); |
191 | 195 | ||