flycatcher_parser/ast/meta.rs
1//! Exposes a data structure for information about AST items.
2
3use crate::ast::Ast;
4use std::ops::Range;
5
6/// Describes where an AST item was found in the source input string.
7#[derive(Clone)]
8pub struct AstMeta {
9
10 // The range of characters where the AST item in this metadata structure was found.
11 pub range: Range<usize>,
12
13 /// The item that this metadata structure describes.
14 pub item: Ast,
15
16 /// Whether or not the AST item has a semicolon after it.
17 pub has_semi: bool,
18
19}
20
21impl AstMeta {
22
23 /// Creates a new AST metadata data structure.
24 pub fn new(range: Range<usize>, item: Ast) -> Self {
25 Self {
26 range,
27 item,
28 has_semi: false,
29 }
30 }
31
32 /// Creates a new AST metadata object, then boxing it.
33 pub fn boxed(range: Range<usize>, item: Ast) -> Box<Self> {
34 Box::new(
35 Self {
36 range,
37 item,
38 has_semi: false,
39 }
40 )
41 }
42
43 /// Converts this AST metadata object into a boxed AST metadata object.
44 pub fn as_box(self) -> Box<Self> {
45 Box::new(self)
46 }
47
48}
49
50impl std::fmt::Debug for AstMeta {
51
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 self.item.fmt(f)
54 }
55
56}