Skip to content

Commit e9eeadb

Browse files
authored
Handle rbs_node and rbs_node_list types (#59)
Enable nested AST traversal by exposing rbs_node and rbs_node_list fields Nested structure traversal (e.g., class members, constant types) depends on access to rbs_node and rbs_node_list fields. Making these fields accessible aligns the Rust bindings with the C API. Fields named "type" are accessible via type_ to avoid a Rust keyword collision
1 parent ea7ec90 commit e9eeadb

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

rust/ruby-rbs/build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,30 @@ fn generate(config: &Config) -> Result<(), Box<dyn Error>> {
147147
)?;
148148
writeln!(file, " }}")?;
149149
}
150+
"rbs_node" => {
151+
let name = if field.name == "type" {
152+
"type_"
153+
} else {
154+
field.name.as_str()
155+
};
156+
157+
writeln!(file, " pub fn {}(&self) -> Node {{", name)?;
158+
writeln!(
159+
file,
160+
" unsafe {{ Node::new(self.parser, (*self.pointer).{}) }}",
161+
name
162+
)?;
163+
writeln!(file, " }}")?;
164+
}
165+
"rbs_node_list" => {
166+
writeln!(file, " pub fn {}(&self) -> NodeList {{", field.name)?;
167+
writeln!(
168+
file,
169+
" NodeList::new(self.parser, unsafe {{ (*self.pointer).{} }})",
170+
field.name
171+
)?;
172+
writeln!(file, " }}")?;
173+
}
150174
_ => eprintln!("Unknown field type: {}", field.c_type),
151175
}
152176
}

rust/ruby-rbs/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ pub struct NodeList {
6666
}
6767

6868
impl NodeList {
69+
pub fn new(parser: *mut rbs_parser_t, pointer: *mut rbs_node_list_t) -> Self {
70+
Self { parser, pointer }
71+
}
72+
6973
/// Returns an iterator over the nodes.
7074
#[must_use]
7175
pub fn iter(&self) -> NodeListIter {

0 commit comments

Comments
 (0)