php_parser_rs/parser/ast/
comments.rs

1use std::slice::Iter;
2
3use schemars::JsonSchema;
4use serde::Deserialize;
5use serde::Serialize;
6
7use crate::lexer::byte_string::ByteString;
8use crate::lexer::token::Span;
9use crate::node::Node;
10
11#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
12#[serde(tag = "type")]
13pub enum CommentFormat {
14    SingleLine,
15    MultiLine,
16    HashMark,
17    Document,
18}
19
20#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
21
22pub struct Comment {
23    pub span: Span,
24    pub format: CommentFormat,
25    pub content: ByteString,
26}
27
28impl Node for Comment {}
29
30#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
31
32pub struct CommentGroup {
33    pub comments: Vec<Comment>,
34}
35
36impl CommentGroup {
37    pub fn iter(&self) -> Iter<'_, Comment> {
38        self.comments.iter()
39    }
40}
41
42impl IntoIterator for CommentGroup {
43    type Item = Comment;
44    type IntoIter = std::vec::IntoIter<Self::Item>;
45
46    fn into_iter(self) -> Self::IntoIter {
47        self.comments.into_iter()
48    }
49}