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)]

View file

@ -1325,6 +1325,7 @@ impl ToOwned for ImplBlock {
impl ast::TypeParamsOwner for ImplBlock {}
impl ast::AttrsOwner for ImplBlock {}
impl ImplBlock {
pub fn item_list(&self) -> Option<&ItemList> {
super::child_opt(self)

View file

@ -341,7 +341,7 @@ Grammar(
],
options: ["TypeRef"]
),
"ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner"]),
"ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner", "AttrsOwner"]),
"ParenType": (options: ["TypeRef"]),
"TupleType": ( collections: [["fields", "TypeRef"]] ),