Skip to content

Commit db28f1b

Browse files
committed
Rust: use macro to inject extraction functions for detached properties
1 parent 8372a2e commit db28f1b

File tree

3 files changed

+159
-3
lines changed

3 files changed

+159
-3
lines changed

rust/ast-generator/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,9 @@ fn write_extractor(grammar: &AstSrc) -> std::io::Result<String> {
419419
"//! Generated by `ast-generator`, do not edit by hand.\n
420420
#![cfg_attr(any(), rustfmt::skip)]
421421
422-
use crate::generated;
423422
use super::base::{{TextValue, Translator}};
423+
use crate::emit_detached;
424+
use crate::generated;
424425
use crate::trap::{{Label, TrapId}};
425426
use ra_ap_syntax::ast::{{
426427
HasArgList, HasAttrs, HasGenericArgs, HasGenericParams, HasLoopBody, HasModuleItem, HasName,
@@ -520,6 +521,11 @@ impl Translator<'_> {{
520521
}
521522
writeln!(buf, " }});")?;
522523
writeln!(buf, " self.emit_location(label, &node);")?;
524+
writeln!(
525+
buf,
526+
" emit_detached!({}, self, node, label);",
527+
class_name
528+
)?;
523529
writeln!(
524530
buf,
525531
" self.emit_tokens(&node, label.into(), node.syntax().children_with_tokens());"

rust/extractor/src/translate/base.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ use ra_ap_syntax::ast::RangeItem;
1414
use ra_ap_syntax::{
1515
ast, AstNode, NodeOrToken, SyntaxElementChildren, SyntaxError, SyntaxToken, TextRange,
1616
};
17+
18+
#[macro_export]
19+
macro_rules! emit_detached {
20+
(MacroCall, $self:ident, $node:ident, $label:ident) => {
21+
$self.extract_macro_call_expanded(&$node, $label.into());
22+
};
23+
($($_:tt)*) => {};
24+
}
25+
1726
pub trait TextValue {
1827
fn try_get_text(&self) -> Option<String>;
1928
}

0 commit comments

Comments
 (0)