Skip to content

Commit eb2d567

Browse files
committed
Generate location() accessor for Node enum (#76)
Adds `location()` accessor to the `Node` enum, delegating to each variant's `location()` method. A previous commit added `location()` to individual node types but missed the enum itself. This allows getting the location of the entire node definition when working with the `Node` enum directly.
1 parent 8bdef0e commit eb2d567

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

rust/ruby-rbs/build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,20 @@ fn generate(config: &Config) -> Result<(), Box<dyn Error>> {
529529
)?;
530530
writeln!(file, " }}")?;
531531
writeln!(file, " }}")?;
532+
writeln!(file)?;
533+
writeln!(file, " /// Returns the location of the entire node.")?;
534+
writeln!(file, " #[must_use]")?;
535+
writeln!(file, " pub fn location(&self) -> RBSLocation {{")?;
536+
writeln!(file, " match self {{")?;
537+
for node in &config.nodes {
538+
writeln!(
539+
file,
540+
" Node::{}(node) => node.location(),",
541+
node.variant_name()
542+
)?;
543+
}
544+
writeln!(file, " }}")?;
545+
writeln!(file, " }}")?;
532546
writeln!(file, "}}")?;
533547
writeln!(file)?;
534548

0 commit comments

Comments
 (0)