1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
use serde::Deserialize; #[derive(Debug, Clone)] pub struct NodeList(pub Vec<Node>); impl NodeList { pub(crate) fn new(nodes: Vec<Node>) -> Self { Self(nodes) } pub fn map(&self, f: &dyn Fn(&Node) -> String) -> Vec<String> { self.0.iter().map(f).collect() } } #[derive(Deserialize, Debug, Clone)] pub struct Node { pub struct_name: String, pub str_type: String, pub filename: String, pub fields: NodeFieldList, pub comment: String, } impl Node { pub fn render_comment(&self, prefix: &str, offset: usize) -> String { crate::comment::Comment::new(&self.comment, prefix).to_string(offset) } pub fn camelcase_name(&self) -> String { self.struct_name.to_string() } pub fn upper_name(&self) -> String { crate::helpers::camel_case_to_underscored(&self.camelcase_name()).to_uppercase() } pub fn lower_name(&self) -> String { crate::helpers::camel_case_to_underscored(&self.camelcase_name()).to_lowercase() } } #[derive(Deserialize, Debug, Clone)] pub struct NodeFieldList(pub Vec<NodeField>); impl NodeFieldList { pub fn any_field_has_type(&self, field_type: NodeFieldType) -> bool { self.0.iter().any(|f| f.field_type == field_type) } pub fn map(&self, f: &dyn Fn(&NodeField) -> String) -> Vec<String> { self.0.iter().map(f).collect() } } #[derive(Debug, Clone, Deserialize)] pub struct NodeField { pub field_name: String, pub field_type: NodeFieldType, pub always_print: bool, pub comment: String, } impl NodeField { pub fn render_comment(&self, prefix: &str, offset: usize) -> String { crate::comment::Comment::new(&self.comment, prefix).to_string(offset) } } #[derive(PartialEq, Clone, Deserialize, Debug)] pub enum NodeFieldType { Node, Nodes, MaybeNode, Loc, MaybeLoc, Str, MaybeStr, Chars, StringValue, U8, Usize, RawString, RegexOptions, } impl NodeFieldType {}