Skip to main content

treesitter_types_json/
generated.rs

1#[derive(Debug, Clone, PartialEq, Eq)]
2pub enum Value<'tree> {
3    Array(::std::boxed::Box<Array<'tree>>),
4    False(::std::boxed::Box<False<'tree>>),
5    Null(::std::boxed::Box<Null<'tree>>),
6    Number(::std::boxed::Box<Number<'tree>>),
7    Object(::std::boxed::Box<Object<'tree>>),
8    String(::std::boxed::Box<String<'tree>>),
9    True(::std::boxed::Box<True<'tree>>),
10}
11impl<'tree> ::treesitter_types::FromNode<'tree> for Value<'tree> {
12    #[allow(clippy::collapsible_else_if)]
13    fn from_node(
14        node: ::tree_sitter::Node<'tree>,
15        src: &'tree [u8],
16    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
17        match node.kind() {
18            "array" => Ok(Self::Array(::std::boxed::Box::new(
19                <Array as ::treesitter_types::FromNode>::from_node(node, src)?,
20            ))),
21            "false" => Ok(Self::False(::std::boxed::Box::new(
22                <False as ::treesitter_types::FromNode>::from_node(node, src)?,
23            ))),
24            "null" => Ok(Self::Null(::std::boxed::Box::new(
25                <Null as ::treesitter_types::FromNode>::from_node(node, src)?,
26            ))),
27            "number" => Ok(Self::Number(::std::boxed::Box::new(
28                <Number as ::treesitter_types::FromNode>::from_node(node, src)?,
29            ))),
30            "object" => Ok(Self::Object(::std::boxed::Box::new(
31                <Object as ::treesitter_types::FromNode>::from_node(node, src)?,
32            ))),
33            "string" => Ok(Self::String(::std::boxed::Box::new(
34                <String as ::treesitter_types::FromNode>::from_node(node, src)?,
35            ))),
36            "true" => Ok(Self::True(::std::boxed::Box::new(
37                <True as ::treesitter_types::FromNode>::from_node(node, src)?,
38            ))),
39            other => Err(::treesitter_types::ParseError::unexpected_kind(other, node)),
40        }
41    }
42}
43impl ::treesitter_types::Spanned for Value<'_> {
44    fn span(&self) -> ::treesitter_types::Span {
45        match self {
46            Self::Array(inner) => inner.span(),
47            Self::False(inner) => inner.span(),
48            Self::Null(inner) => inner.span(),
49            Self::Number(inner) => inner.span(),
50            Self::Object(inner) => inner.span(),
51            Self::String(inner) => inner.span(),
52            Self::True(inner) => inner.span(),
53        }
54    }
55}
56#[derive(Debug, Clone, PartialEq, Eq)]
57pub struct Array<'tree> {
58    pub span: ::treesitter_types::Span,
59    pub children: ::std::vec::Vec<Value<'tree>>,
60}
61impl<'tree> ::treesitter_types::FromNode<'tree> for Array<'tree> {
62    #[allow(clippy::match_single_binding, clippy::suspicious_else_formatting)]
63    fn from_node(
64        node: ::tree_sitter::Node<'tree>,
65        src: &'tree [u8],
66    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
67        debug_assert_eq!(node.kind(), "array");
68        Ok(Self {
69            span: ::treesitter_types::Span::from(node),
70            children: {
71                #[allow(clippy::suspicious_else_formatting)]
72                let non_field_children = {
73                    let mut cursor = node.walk();
74                    let mut result = ::std::vec::Vec::new();
75                    if cursor.goto_first_child() {
76                        loop {
77                            if cursor.field_name().is_none()
78                                && cursor.node().is_named()
79                                && !cursor.node().is_extra()
80                            {
81                                result.push(cursor.node());
82                            }
83                            if !cursor.goto_next_sibling() {
84                                break;
85                            }
86                        }
87                    }
88                    result
89                };
90                let mut items = ::std::vec::Vec::new();
91                for child in non_field_children {
92                    items.push(<Value as ::treesitter_types::FromNode>::from_node(
93                        child, src,
94                    )?);
95                }
96                items
97            },
98        })
99    }
100}
101impl ::treesitter_types::Spanned for Array<'_> {
102    fn span(&self) -> ::treesitter_types::Span {
103        self.span
104    }
105}
106#[derive(Debug, Clone, PartialEq, Eq)]
107pub struct Document<'tree> {
108    pub span: ::treesitter_types::Span,
109    pub children: ::std::vec::Vec<Value<'tree>>,
110}
111impl<'tree> ::treesitter_types::FromNode<'tree> for Document<'tree> {
112    #[allow(clippy::match_single_binding, clippy::suspicious_else_formatting)]
113    fn from_node(
114        node: ::tree_sitter::Node<'tree>,
115        src: &'tree [u8],
116    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
117        debug_assert_eq!(node.kind(), "document");
118        Ok(Self {
119            span: ::treesitter_types::Span::from(node),
120            children: {
121                #[allow(clippy::suspicious_else_formatting)]
122                let non_field_children = {
123                    let mut cursor = node.walk();
124                    let mut result = ::std::vec::Vec::new();
125                    if cursor.goto_first_child() {
126                        loop {
127                            if cursor.field_name().is_none()
128                                && cursor.node().is_named()
129                                && !cursor.node().is_extra()
130                            {
131                                result.push(cursor.node());
132                            }
133                            if !cursor.goto_next_sibling() {
134                                break;
135                            }
136                        }
137                    }
138                    result
139                };
140                let mut items = ::std::vec::Vec::new();
141                for child in non_field_children {
142                    items.push(<Value as ::treesitter_types::FromNode>::from_node(
143                        child, src,
144                    )?);
145                }
146                items
147            },
148        })
149    }
150}
151impl ::treesitter_types::Spanned for Document<'_> {
152    fn span(&self) -> ::treesitter_types::Span {
153        self.span
154    }
155}
156#[derive(Debug, Clone, PartialEq, Eq)]
157pub struct Object<'tree> {
158    pub span: ::treesitter_types::Span,
159    pub children: ::std::vec::Vec<Pair<'tree>>,
160}
161impl<'tree> ::treesitter_types::FromNode<'tree> for Object<'tree> {
162    #[allow(clippy::match_single_binding, clippy::suspicious_else_formatting)]
163    fn from_node(
164        node: ::tree_sitter::Node<'tree>,
165        src: &'tree [u8],
166    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
167        debug_assert_eq!(node.kind(), "object");
168        Ok(Self {
169            span: ::treesitter_types::Span::from(node),
170            children: {
171                #[allow(clippy::suspicious_else_formatting)]
172                let non_field_children = {
173                    let mut cursor = node.walk();
174                    let mut result = ::std::vec::Vec::new();
175                    if cursor.goto_first_child() {
176                        loop {
177                            if cursor.field_name().is_none()
178                                && cursor.node().is_named()
179                                && !cursor.node().is_extra()
180                            {
181                                result.push(cursor.node());
182                            }
183                            if !cursor.goto_next_sibling() {
184                                break;
185                            }
186                        }
187                    }
188                    result
189                };
190                let mut items = ::std::vec::Vec::new();
191                for child in non_field_children {
192                    items.push(<Pair as ::treesitter_types::FromNode>::from_node(
193                        child, src,
194                    )?);
195                }
196                items
197            },
198        })
199    }
200}
201impl ::treesitter_types::Spanned for Object<'_> {
202    fn span(&self) -> ::treesitter_types::Span {
203        self.span
204    }
205}
206#[derive(Debug, Clone, PartialEq, Eq)]
207pub struct Pair<'tree> {
208    pub span: ::treesitter_types::Span,
209    pub key: String<'tree>,
210    pub value: Value<'tree>,
211}
212impl<'tree> ::treesitter_types::FromNode<'tree> for Pair<'tree> {
213    #[allow(clippy::match_single_binding, clippy::suspicious_else_formatting)]
214    fn from_node(
215        node: ::tree_sitter::Node<'tree>,
216        src: &'tree [u8],
217    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
218        debug_assert_eq!(node.kind(), "pair");
219        Ok(Self {
220            span: ::treesitter_types::Span::from(node),
221            key: {
222                let child = node
223                    .child_by_field_name("key")
224                    .ok_or_else(|| ::treesitter_types::ParseError::missing_field("key", node))?;
225                <String as ::treesitter_types::FromNode>::from_node(child, src)?
226            },
227            value: {
228                let child = node
229                    .child_by_field_name("value")
230                    .ok_or_else(|| ::treesitter_types::ParseError::missing_field("value", node))?;
231                <Value as ::treesitter_types::FromNode>::from_node(child, src)?
232            },
233        })
234    }
235}
236impl ::treesitter_types::Spanned for Pair<'_> {
237    fn span(&self) -> ::treesitter_types::Span {
238        self.span
239    }
240}
241#[derive(Debug, Clone, PartialEq, Eq)]
242pub struct String<'tree> {
243    pub span: ::treesitter_types::Span,
244    pub children: ::std::vec::Vec<StringChildren<'tree>>,
245}
246impl<'tree> ::treesitter_types::FromNode<'tree> for String<'tree> {
247    #[allow(clippy::match_single_binding, clippy::suspicious_else_formatting)]
248    fn from_node(
249        node: ::tree_sitter::Node<'tree>,
250        src: &'tree [u8],
251    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
252        debug_assert_eq!(node.kind(), "string");
253        Ok(Self {
254            span: ::treesitter_types::Span::from(node),
255            children: {
256                #[allow(clippy::suspicious_else_formatting)]
257                let non_field_children = {
258                    let mut cursor = node.walk();
259                    let mut result = ::std::vec::Vec::new();
260                    if cursor.goto_first_child() {
261                        loop {
262                            if cursor.field_name().is_none()
263                                && cursor.node().is_named()
264                                && !cursor.node().is_extra()
265                            {
266                                result.push(cursor.node());
267                            }
268                            if !cursor.goto_next_sibling() {
269                                break;
270                            }
271                        }
272                    }
273                    result
274                };
275                let mut items = ::std::vec::Vec::new();
276                for child in non_field_children {
277                    items.push(<StringChildren as ::treesitter_types::FromNode>::from_node(
278                        child, src,
279                    )?);
280                }
281                items
282            },
283        })
284    }
285}
286impl ::treesitter_types::Spanned for String<'_> {
287    fn span(&self) -> ::treesitter_types::Span {
288        self.span
289    }
290}
291#[derive(Debug, Clone, PartialEq, Eq)]
292pub struct Comment<'tree> {
293    pub span: ::treesitter_types::Span,
294    text: &'tree str,
295}
296impl<'tree> ::treesitter_types::FromNode<'tree> for Comment<'tree> {
297    fn from_node(
298        node: ::tree_sitter::Node<'tree>,
299        src: &'tree [u8],
300    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
301        debug_assert_eq!(node.kind(), "comment");
302        Ok(Self {
303            span: ::treesitter_types::Span::from(node),
304            text: node.utf8_text(src)?,
305        })
306    }
307}
308impl<'tree> ::treesitter_types::LeafNode<'tree> for Comment<'tree> {
309    fn text(&self) -> &'tree str {
310        self.text
311    }
312}
313impl ::treesitter_types::Spanned for Comment<'_> {
314    fn span(&self) -> ::treesitter_types::Span {
315        self.span
316    }
317}
318#[derive(Debug, Clone, PartialEq, Eq)]
319pub struct EscapeSequence<'tree> {
320    pub span: ::treesitter_types::Span,
321    text: &'tree str,
322}
323impl<'tree> ::treesitter_types::FromNode<'tree> for EscapeSequence<'tree> {
324    fn from_node(
325        node: ::tree_sitter::Node<'tree>,
326        src: &'tree [u8],
327    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
328        debug_assert_eq!(node.kind(), "escape_sequence");
329        Ok(Self {
330            span: ::treesitter_types::Span::from(node),
331            text: node.utf8_text(src)?,
332        })
333    }
334}
335impl<'tree> ::treesitter_types::LeafNode<'tree> for EscapeSequence<'tree> {
336    fn text(&self) -> &'tree str {
337        self.text
338    }
339}
340impl ::treesitter_types::Spanned for EscapeSequence<'_> {
341    fn span(&self) -> ::treesitter_types::Span {
342        self.span
343    }
344}
345#[derive(Debug, Clone, PartialEq, Eq)]
346pub struct False<'tree> {
347    pub span: ::treesitter_types::Span,
348    text: &'tree str,
349}
350impl<'tree> ::treesitter_types::FromNode<'tree> for False<'tree> {
351    fn from_node(
352        node: ::tree_sitter::Node<'tree>,
353        src: &'tree [u8],
354    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
355        debug_assert_eq!(node.kind(), "false");
356        Ok(Self {
357            span: ::treesitter_types::Span::from(node),
358            text: node.utf8_text(src)?,
359        })
360    }
361}
362impl<'tree> ::treesitter_types::LeafNode<'tree> for False<'tree> {
363    fn text(&self) -> &'tree str {
364        self.text
365    }
366}
367impl ::treesitter_types::Spanned for False<'_> {
368    fn span(&self) -> ::treesitter_types::Span {
369        self.span
370    }
371}
372#[derive(Debug, Clone, PartialEq, Eq)]
373pub struct Null<'tree> {
374    pub span: ::treesitter_types::Span,
375    text: &'tree str,
376}
377impl<'tree> ::treesitter_types::FromNode<'tree> for Null<'tree> {
378    fn from_node(
379        node: ::tree_sitter::Node<'tree>,
380        src: &'tree [u8],
381    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
382        debug_assert_eq!(node.kind(), "null");
383        Ok(Self {
384            span: ::treesitter_types::Span::from(node),
385            text: node.utf8_text(src)?,
386        })
387    }
388}
389impl<'tree> ::treesitter_types::LeafNode<'tree> for Null<'tree> {
390    fn text(&self) -> &'tree str {
391        self.text
392    }
393}
394impl ::treesitter_types::Spanned for Null<'_> {
395    fn span(&self) -> ::treesitter_types::Span {
396        self.span
397    }
398}
399#[derive(Debug, Clone, PartialEq, Eq)]
400pub struct Number<'tree> {
401    pub span: ::treesitter_types::Span,
402    text: &'tree str,
403}
404impl<'tree> ::treesitter_types::FromNode<'tree> for Number<'tree> {
405    fn from_node(
406        node: ::tree_sitter::Node<'tree>,
407        src: &'tree [u8],
408    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
409        debug_assert_eq!(node.kind(), "number");
410        Ok(Self {
411            span: ::treesitter_types::Span::from(node),
412            text: node.utf8_text(src)?,
413        })
414    }
415}
416impl<'tree> ::treesitter_types::LeafNode<'tree> for Number<'tree> {
417    fn text(&self) -> &'tree str {
418        self.text
419    }
420}
421impl ::treesitter_types::Spanned for Number<'_> {
422    fn span(&self) -> ::treesitter_types::Span {
423        self.span
424    }
425}
426#[derive(Debug, Clone, PartialEq, Eq)]
427pub struct StringContent<'tree> {
428    pub span: ::treesitter_types::Span,
429    text: &'tree str,
430}
431impl<'tree> ::treesitter_types::FromNode<'tree> for StringContent<'tree> {
432    fn from_node(
433        node: ::tree_sitter::Node<'tree>,
434        src: &'tree [u8],
435    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
436        debug_assert_eq!(node.kind(), "string_content");
437        Ok(Self {
438            span: ::treesitter_types::Span::from(node),
439            text: node.utf8_text(src)?,
440        })
441    }
442}
443impl<'tree> ::treesitter_types::LeafNode<'tree> for StringContent<'tree> {
444    fn text(&self) -> &'tree str {
445        self.text
446    }
447}
448impl ::treesitter_types::Spanned for StringContent<'_> {
449    fn span(&self) -> ::treesitter_types::Span {
450        self.span
451    }
452}
453#[derive(Debug, Clone, PartialEq, Eq)]
454pub struct True<'tree> {
455    pub span: ::treesitter_types::Span,
456    text: &'tree str,
457}
458impl<'tree> ::treesitter_types::FromNode<'tree> for True<'tree> {
459    fn from_node(
460        node: ::tree_sitter::Node<'tree>,
461        src: &'tree [u8],
462    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
463        debug_assert_eq!(node.kind(), "true");
464        Ok(Self {
465            span: ::treesitter_types::Span::from(node),
466            text: node.utf8_text(src)?,
467        })
468    }
469}
470impl<'tree> ::treesitter_types::LeafNode<'tree> for True<'tree> {
471    fn text(&self) -> &'tree str {
472        self.text
473    }
474}
475impl ::treesitter_types::Spanned for True<'_> {
476    fn span(&self) -> ::treesitter_types::Span {
477        self.span
478    }
479}
480#[derive(Debug, Clone, PartialEq, Eq)]
481pub enum StringChildren<'tree> {
482    EscapeSequence(::std::boxed::Box<EscapeSequence<'tree>>),
483    StringContent(::std::boxed::Box<StringContent<'tree>>),
484}
485impl<'tree> ::treesitter_types::FromNode<'tree> for StringChildren<'tree> {
486    #[allow(clippy::collapsible_else_if)]
487    fn from_node(
488        node: ::tree_sitter::Node<'tree>,
489        src: &'tree [u8],
490    ) -> ::core::result::Result<Self, ::treesitter_types::ParseError> {
491        match node.kind() {
492            "escape_sequence" => Ok(Self::EscapeSequence(::std::boxed::Box::new(
493                <EscapeSequence as ::treesitter_types::FromNode>::from_node(node, src)?,
494            ))),
495            "string_content" => Ok(Self::StringContent(::std::boxed::Box::new(
496                <StringContent as ::treesitter_types::FromNode>::from_node(node, src)?,
497            ))),
498            other => Err(::treesitter_types::ParseError::unexpected_kind(other, node)),
499        }
500    }
501}
502impl ::treesitter_types::Spanned for StringChildren<'_> {
503    fn span(&self) -> ::treesitter_types::Span {
504        match self {
505            Self::EscapeSequence(inner) => inner.span(),
506            Self::StringContent(inner) => inner.span(),
507        }
508    }
509}
510#[derive(Debug, Clone, PartialEq, Eq)]
511pub enum AnyNode<'tree> {
512    Value(Value<'tree>),
513    Array(Array<'tree>),
514    Document(Document<'tree>),
515    Object(Object<'tree>),
516    Pair(Pair<'tree>),
517    String(String<'tree>),
518    Comment(Comment<'tree>),
519    EscapeSequence(EscapeSequence<'tree>),
520    False(False<'tree>),
521    Null(Null<'tree>),
522    Number(Number<'tree>),
523    StringContent(StringContent<'tree>),
524    True(True<'tree>),
525    Unknown(::tree_sitter::Node<'tree>),
526}
527impl<'tree> AnyNode<'tree> {
528    pub fn from_node(node: ::tree_sitter::Node<'tree>, src: &'tree [u8]) -> Self {
529        match node.kind() {
530            "_value" => <Value as ::treesitter_types::FromNode>::from_node(node, src)
531                .map(Self::Value)
532                .unwrap_or(Self::Unknown(node)),
533            "array" => <Array as ::treesitter_types::FromNode>::from_node(node, src)
534                .map(Self::Array)
535                .unwrap_or(Self::Unknown(node)),
536            "document" => <Document as ::treesitter_types::FromNode>::from_node(node, src)
537                .map(Self::Document)
538                .unwrap_or(Self::Unknown(node)),
539            "object" => <Object as ::treesitter_types::FromNode>::from_node(node, src)
540                .map(Self::Object)
541                .unwrap_or(Self::Unknown(node)),
542            "pair" => <Pair as ::treesitter_types::FromNode>::from_node(node, src)
543                .map(Self::Pair)
544                .unwrap_or(Self::Unknown(node)),
545            "string" => <String as ::treesitter_types::FromNode>::from_node(node, src)
546                .map(Self::String)
547                .unwrap_or(Self::Unknown(node)),
548            "comment" => <Comment as ::treesitter_types::FromNode>::from_node(node, src)
549                .map(Self::Comment)
550                .unwrap_or(Self::Unknown(node)),
551            "escape_sequence" => {
552                <EscapeSequence as ::treesitter_types::FromNode>::from_node(node, src)
553                    .map(Self::EscapeSequence)
554                    .unwrap_or(Self::Unknown(node))
555            }
556            "false" => <False as ::treesitter_types::FromNode>::from_node(node, src)
557                .map(Self::False)
558                .unwrap_or(Self::Unknown(node)),
559            "null" => <Null as ::treesitter_types::FromNode>::from_node(node, src)
560                .map(Self::Null)
561                .unwrap_or(Self::Unknown(node)),
562            "number" => <Number as ::treesitter_types::FromNode>::from_node(node, src)
563                .map(Self::Number)
564                .unwrap_or(Self::Unknown(node)),
565            "string_content" => {
566                <StringContent as ::treesitter_types::FromNode>::from_node(node, src)
567                    .map(Self::StringContent)
568                    .unwrap_or(Self::Unknown(node))
569            }
570            "true" => <True as ::treesitter_types::FromNode>::from_node(node, src)
571                .map(Self::True)
572                .unwrap_or(Self::Unknown(node)),
573            _ => Self::Unknown(node),
574        }
575    }
576}
577impl ::treesitter_types::Spanned for AnyNode<'_> {
578    fn span(&self) -> ::treesitter_types::Span {
579        match self {
580            Self::Value(inner) => inner.span(),
581            Self::Array(inner) => inner.span(),
582            Self::Document(inner) => inner.span(),
583            Self::Object(inner) => inner.span(),
584            Self::Pair(inner) => inner.span(),
585            Self::String(inner) => inner.span(),
586            Self::Comment(inner) => inner.span(),
587            Self::EscapeSequence(inner) => inner.span(),
588            Self::False(inner) => inner.span(),
589            Self::Null(inner) => inner.span(),
590            Self::Number(inner) => inner.span(),
591            Self::StringContent(inner) => inner.span(),
592            Self::True(inner) => inner.span(),
593            Self::Unknown(node) => ::treesitter_types::Span::from(*node),
594        }
595    }
596}