diff options
author | Aleksey Kladov <[email protected]> | 2018-09-16 10:54:24 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-16 11:07:39 +0100 |
commit | b5021411a84822cb3f1e3aeffad9550dd15bdeb6 (patch) | |
tree | 9dca564f8e51b298dced01c4ce669c756dce3142 /crates/libsyntax2/src/yellow/green.rs | |
parent | ba0bfeee12e19da40b5eabc8d0408639af10e96f (diff) |
rename all things
Diffstat (limited to 'crates/libsyntax2/src/yellow/green.rs')
-rw-r--r-- | crates/libsyntax2/src/yellow/green.rs | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/crates/libsyntax2/src/yellow/green.rs b/crates/libsyntax2/src/yellow/green.rs deleted file mode 100644 index 8fb691643..000000000 --- a/crates/libsyntax2/src/yellow/green.rs +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use smol_str::SmolStr; | ||
4 | |||
5 | use {SyntaxKind, TextUnit}; | ||
6 | |||
7 | #[derive(Clone, Debug)] | ||
8 | pub(crate) enum GreenNode { | ||
9 | Leaf { | ||
10 | kind: SyntaxKind, | ||
11 | text: SmolStr, | ||
12 | }, | ||
13 | Branch(Arc<GreenBranch>), | ||
14 | } | ||
15 | |||
16 | impl GreenNode { | ||
17 | pub(crate) fn new_leaf(kind: SyntaxKind, text: &str) -> GreenNode { | ||
18 | GreenNode::Leaf { kind, text: SmolStr::new(text) } | ||
19 | } | ||
20 | |||
21 | pub(crate) fn new_branch(kind: SyntaxKind, children: Box<[GreenNode]>) -> GreenNode { | ||
22 | GreenNode::Branch(Arc::new(GreenBranch::new(kind, children))) | ||
23 | } | ||
24 | |||
25 | pub fn kind(&self) -> SyntaxKind { | ||
26 | match self { | ||
27 | GreenNode::Leaf { kind, .. } => *kind, | ||
28 | GreenNode::Branch(b) => b.kind(), | ||
29 | } | ||
30 | } | ||
31 | |||
32 | pub fn text_len(&self) -> TextUnit { | ||
33 | match self { | ||
34 | GreenNode::Leaf { text, .. } => TextUnit::from(text.len() as u32), | ||
35 | GreenNode::Branch(b) => b.text_len(), | ||
36 | } | ||
37 | } | ||
38 | |||
39 | pub fn children(&self) -> &[GreenNode] { | ||
40 | match self { | ||
41 | GreenNode::Leaf { .. } => &[], | ||
42 | GreenNode::Branch(b) => b.children(), | ||
43 | } | ||
44 | } | ||
45 | |||
46 | pub fn leaf_text_ref(&self) -> Option<&SmolStr> { | ||
47 | match self { | ||
48 | GreenNode::Leaf { text, .. } => Some(text), | ||
49 | GreenNode::Branch(_) => None, | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | #[derive(Clone, Debug)] | ||
55 | pub(crate) struct GreenBranch { | ||
56 | text_len: TextUnit, | ||
57 | kind: SyntaxKind, | ||
58 | children: Box<[GreenNode]>, | ||
59 | } | ||
60 | |||
61 | impl GreenBranch { | ||
62 | fn new(kind: SyntaxKind, children: Box<[GreenNode]>) -> GreenBranch { | ||
63 | let text_len = children.iter().map(|x| x.text_len()).sum::<TextUnit>(); | ||
64 | GreenBranch { | ||
65 | text_len, | ||
66 | kind, | ||
67 | children, | ||
68 | } | ||
69 | } | ||
70 | |||
71 | pub fn kind(&self) -> SyntaxKind { | ||
72 | self.kind | ||
73 | } | ||
74 | |||
75 | pub fn text_len(&self) -> TextUnit { | ||
76 | self.text_len | ||
77 | } | ||
78 | |||
79 | pub fn children(&self) -> &[GreenNode] { | ||
80 | &*self.children | ||
81 | } | ||
82 | } | ||
83 | |||
84 | #[test] | ||
85 | fn test_sizes() { | ||
86 | use std::mem::size_of; | ||
87 | println!("GreenBranch = {}", size_of::<GreenBranch>()); | ||
88 | println!("GreenNode = {}", size_of::<GreenNode>()); | ||
89 | println!("SmolStr = {}", size_of::<SmolStr>()); | ||
90 | } | ||