Initial support for lang items.

This commit is contained in:
Marco Groppo 2019-04-15 00:03:54 +02:00
parent d55f1136d6
commit e85ee60c42
11 changed files with 204 additions and 41 deletions

View file

@ -65,6 +65,20 @@ impl ast::Attr {
None
}
}
pub fn as_key_value(&self) -> Option<(SmolStr, SmolStr)> {
let tt = self.value()?;
let tt_node = tt.syntax();
let attr = tt_node.children_with_tokens().nth(1)?;
if attr.kind() == IDENT {
let key = attr.as_token()?.text().clone();
let val_node = tt_node.children_with_tokens().find(|t| t.kind() == STRING)?;
let val = val_node.as_token()?.text().trim_start_matches("\"").trim_end_matches("\"");
Some((key, SmolStr::new(val)))
} else {
None
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]