xidl_parser/typed_ast/
bitmask.rs1use super::*;
37use serde::{Deserialize, Serialize};
38
39#[derive(Debug, Parser, Serialize, Deserialize)]
40pub struct BitsetDcl {
41 pub ident: Identifier,
42 pub parent: Option<ScopedName>,
43 #[ts(id = "bitfield")]
44 pub field: Vec<BitField>,
45}
46
47#[derive(Debug, Parser, Serialize, Deserialize)]
48#[ts(id = "bitfield")]
49pub struct BitField {
50 pub spec: BitfieldSpec,
51 pub ident: Vec<Identifier>,
52}
53
54#[derive(Debug, Parser, Serialize, Deserialize)]
55pub struct BitfieldSpec {
56 pub pos: PositiveIntConst,
57 pub dst_ty: Option<DestinationType>,
58}
59
60#[derive(Debug, Parser, Serialize, Deserialize)]
61pub enum DestinationType {
62 BooleanType(BooleanType),
63 OctetType(OctetType),
64 IntegerType(IntegerType),
65}
66
67#[derive(Debug, Parser, Serialize, Deserialize)]
68pub struct BitmaskDcl {
69 pub ident: Identifier,
70
71 pub value: Vec<BitValue>,
72}
73
74#[derive(Debug, Serialize, Deserialize)]
75pub struct BitValue {
76 pub annotations: Vec<AnnotationAppl>,
77 pub ident: Identifier,
78}
79
80impl<'a> crate::parser::FromTreeSitter<'a> for BitValue {
81 fn from_node(
82 node: tree_sitter::Node<'a>,
83 ctx: &mut crate::parser::ParseContext<'a>,
84 ) -> crate::error::ParserResult<Self> {
85 assert_eq!(node.kind_id(), xidl_parser_derive::node_id!("bit_value"));
86 let mut annotations = Vec::new();
87 let mut ident = None;
88 for ch in node.children(&mut node.walk()) {
89 match ch.kind_id() {
90 xidl_parser_derive::node_id!("annotation_appl")
91 | xidl_parser_derive::node_id!("extend_annotation_appl") => {
92 annotations.push(AnnotationAppl::from_node(ch, ctx)?);
93 }
94 xidl_parser_derive::node_id!("identifier") => {
95 ident = Some(Identifier::from_node(ch, ctx)?);
96 }
97 _ => {}
98 }
99 }
100 Ok(Self {
101 annotations,
102 ident: ident.ok_or_else(|| {
103 crate::error::ParseError::UnexpectedNode(format!(
104 "parent: {}, got: missing identifier",
105 node.kind()
106 ))
107 })?,
108 })
109 }
110}