yggdrasil_wasi/wit/
cst.rs

1use super::*;
2
3use crate::exports::peg::core::cst::*;
4
5impl Guest for YggdrasilHost {
6    type SyntaxRule = NativeSyntaxRule;
7    type SyntaxNode = Node<NativeSyntaxData>;
8    type SyntaxIterator = NativeSyntaxIterator;
9}
10
11impl GuestSyntaxRule for NativeSyntaxRule {
12    fn get_flags(&self) -> SnytaxFlags {
13        todo!()
14    }
15
16    fn get_language(&self) -> Language {
17        todo!()
18    }
19
20    fn get_tag(&self) -> String {
21        self.tag.to_string()
22    }
23
24    fn get_rule_name(&self) -> String {
25        self.name.to_string()
26    }
27
28    fn get_styles(&self) -> Vec<String> {
29        self.styles.iter().map(|s| s.to_string()).collect()
30    }
31}
32
33impl GuestSyntaxNode for Node<NativeSyntaxData> {
34    fn get_range(&self) -> TextRange {
35        let data = self.borrow();
36        let range = data.span.clone();
37        TextRange { head_offset: range.start as u32, tail_offset: range.end as u32 }
38    }
39
40    fn get_rule(&self) -> SyntaxRule {
41        todo!()
42    }
43
44    fn get_text(&self) -> String {
45        let data = self.borrow();
46        let range = data.span.clone();
47        match data.text.get(range) {
48            Some(s) => s.to_string(),
49            None => {
50                panic!("out of range")
51            }
52        }
53    }
54
55    fn has_parent(&self) -> bool {
56        self.parent().is_some()
57    }
58
59    fn get_parent(&self) -> Option<SyntaxNode> {
60        Some(SyntaxNode::new(self.parent()?))
61    }
62
63    fn get_ancestors(&self, include_self: bool) -> SyntaxIterator {
64        SyntaxIterator::new(NativeSyntaxIterator::Ancestors(RefCell::new(NativeAncestors::new(self, include_self))))
65    }
66
67    fn get_last(&self) -> Option<SyntaxNode> {
68        Some(SyntaxNode::new(self.previous_sibling()?))
69    }
70
71    fn get_last_iterator(&self, include_self: bool) -> SyntaxIterator {
72        todo!()
73    }
74
75    fn get_next(&self) -> Option<SyntaxNode> {
76        Some(SyntaxNode::new(self.next_sibling()?))
77    }
78
79    fn get_next_iterator(&self, include_self: bool) -> SyntaxIterator {
80        todo!()
81    }
82
83    fn get_silbing_head(&self) -> Option<SyntaxNode> {
84        Some(SyntaxNode::new(self.parent()?.first_child()?))
85    }
86
87    fn get_sibling_tail(&self) -> Option<SyntaxNode> {
88        Some(SyntaxNode::new(self.parent()?.last_child()?))
89    }
90
91    fn get_siblings(&self, reversed: bool) -> SyntaxIterator {
92        todo!()
93    }
94
95    fn has_child(&self) -> bool {
96        self.has_children()
97    }
98
99    fn get_child_head(&self) -> Option<SyntaxNode> {
100        Some(SyntaxNode::new(self.first_child()?))
101    }
102
103    fn get_child_tail(&self) -> Option<SyntaxNode> {
104        Some(SyntaxNode::new(self.last_child()?))
105    }
106
107    fn get_children(&self, reversed: bool) -> SyntaxIterator {
108        SyntaxIterator::new(NativeSyntaxIterator::Children(RefCell::new(NativeChildren::new(self, reversed))))
109    }
110
111    fn get_descendants(&self, depth_first: bool, reversed: bool) -> SyntaxIterator {
112        todo!()
113    }
114}
115
116impl GuestSyntaxIterator for NativeSyntaxIterator {
117    fn last(&self) -> Option<SyntaxNode> {
118        match self {
119            Self::Ancestors(i) => Some(SyntaxNode::new(i.borrow_mut().backward()?)),
120            Self::Siblings() => {
121                todo!()
122            }
123            Self::Previous() => {
124                todo!()
125            }
126            Self::Following() => {
127                todo!()
128            }
129            Self::Children(i) => Some(SyntaxNode::new(i.borrow_mut().backward()?)),
130            Self::Descendants() => {
131                todo!()
132            }
133        }
134    }
135
136    fn next(&self) -> Option<SyntaxNode> {
137        match self {
138            Self::Ancestors(i) => Some(SyntaxNode::new(i.borrow_mut().forward()?)),
139            Self::Siblings() => {
140                todo!()
141            }
142            Self::Previous() => {
143                todo!()
144            }
145            Self::Following() => {
146                todo!()
147            }
148            Self::Children(i) => Some(SyntaxNode::new(i.borrow_mut().forward()?)),
149            Self::Descendants() => {
150                todo!()
151            }
152        }
153    }
154
155    fn move_head(&self) {
156        todo!()
157    }
158
159    fn move_tail(&self) {
160        todo!()
161    }
162
163    fn skip(&self, count: u32) {
164        todo!()
165    }
166
167    fn reverse(&self) {
168        match self {
169            Self::Ancestors(v) => v.borrow_mut().reverse(),
170            Self::Siblings() => {}
171            Self::Previous() => {}
172            Self::Following() => {}
173            Self::Children(v) => v.borrow_mut().reverse(),
174            Self::Descendants() => {}
175        }
176    }
177}