lib/grammar/ast/
comment.rs

1use pest::iterators::Pair;
2use serde::Serialize;
3
4use crate::grammar::ast::literal::LiteralTypes;
5use crate::grammar::parser::Rule;
6
7#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
8#[serde(tag = "kind")]
9pub struct Comment {
10    comment: LiteralTypes,
11}
12
13impl Default for Comment {
14    fn default() -> Self {
15        Self {
16            comment: LiteralTypes::String(String::from("")),
17        }
18    }
19}
20
21impl<'r> From<Pair<'r, Rule>> for Comment {
22    fn from(pair: Pair<'r, Rule>) -> Self {
23        let comment = LiteralTypes::String(pair.as_span().as_str().to_string());
24        Self { comment }
25    }
26}