teo_parser/ast/
constant_declaration.rs

1use std::cell::{Cell, RefCell};
2use crate::ast::expression::Expression;
3use crate::ast::identifier::Identifier;
4use crate::ast::type_expr::TypeExpr;
5use crate::{declare_container_node, impl_container_node_defaults, node_child_fn, node_optional_child_fn};
6use crate::ast::doc_comment::DocComment;
7use crate::format::Writer;
8use crate::traits::has_availability::HasAvailability;
9use crate::traits::info_provider::InfoProvider;
10use crate::traits::resolved::Resolve;
11use crate::traits::write::Write;
12use crate::expr::ExprInfo;
13
14declare_container_node!(ConstantDeclaration, named, availability,
15    pub(crate) comment: Option<usize>,
16    pub(crate) identifier: usize,
17    pub(crate) type_expr: Option<usize>,
18    pub(crate) expression: usize,
19    pub(crate) use_count: Cell<usize>,
20    pub(crate) resolved: RefCell<Option<ExprInfo >>,
21);
22
23impl_container_node_defaults!(ConstantDeclaration, named, availability);
24
25impl ConstantDeclaration {
26
27    node_child_fn!(identifier, Identifier);
28
29    node_optional_child_fn!(comment, DocComment);
30
31    node_optional_child_fn!(type_expr, TypeExpr);
32
33    node_child_fn!(expression, Expression);
34}
35
36impl InfoProvider for ConstantDeclaration {
37    fn namespace_skip(&self) -> usize {
38        1
39    }
40}
41
42impl Resolve<ExprInfo> for ConstantDeclaration {
43    fn resolved_ref_cell(&self) -> &RefCell<Option<ExprInfo>> {
44        &self.resolved
45    }
46}
47
48impl Write for ConstantDeclaration {
49    fn write<'a>(&'a self, writer: &mut Writer<'a>) {
50        writer.write_children(self, self.children.values());
51    }
52
53    fn is_block_level_element(&self) -> bool {
54        true
55    }
56}