petr_utils/
lib.rs

1//! Turning on the "Debug" feature for this crate will use an inefficient
2//! global lock to store the symbol names and render them as readable.
3//! For production uses, these IDs are turned into usizes.
4
5pub use common_types::*;
6pub use index_map::IndexMap;
7pub use pretty_print::PrettyPrint;
8pub use sources::{error_printing::render as render_error, SourceId, Span, SpannedItem};
9
10mod common_types;
11mod index_map;
12mod sources;
13mod pretty_print {
14    //! Trait for pretty-printing compiler internals
15    //! Primarily used for testing and debugging purposes
16
17    use crate::{Identifier, SpannedItem, SymbolInterner};
18    pub trait PrettyPrint {
19        fn pretty_print(
20            &self,
21            interner: &SymbolInterner,
22            indentation: usize,
23        ) -> String;
24    }
25    impl PrettyPrint for Identifier {
26        fn pretty_print(
27            &self,
28            interner: &SymbolInterner,
29            _: usize,
30        ) -> String {
31            interner.get(self.id).to_string()
32        }
33    }
34    impl<T> PrettyPrint for SpannedItem<T>
35    where
36        T: PrettyPrint,
37    {
38        fn pretty_print(
39            &self,
40            interner: &SymbolInterner,
41            indentation: usize,
42        ) -> String {
43            self.item().pretty_print(interner, indentation)
44        }
45    }
46}