From fcce07d2d1b07cf4578af65b00a243e743a67f05 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 20:16:04 +0200 Subject: Finalize attribute grammar --- crates/ra_hir_def/src/attr.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'crates/ra_hir_def/src/attr.rs') diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 70ccd4305..050832ce0 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs @@ -151,18 +151,15 @@ pub enum AttrInput { impl Attr { fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option { let path = ModPath::from_src(ast.path()?, hygiene)?; - let input = match ast.input() { - None => None, - Some(ast::AttrInput::Literal(lit)) => { - // FIXME: escape? raw string? - let value = lit.syntax().first_token()?.text().trim_matches('"').into(); - Some(AttrInput::Literal(value)) - } - Some(ast::AttrInput::TokenTree(tt)) => { - Some(AttrInput::TokenTree(ast_to_token_tree(&tt)?.0)) - } + let input = if let Some(lit) = ast.literal() { + // FIXME: escape? raw string? + let value = lit.syntax().first_token()?.text().trim_matches('"').into(); + Some(AttrInput::Literal(value)) + } else if let Some(tt) = ast.token_tree() { + Some(AttrInput::TokenTree(ast_to_token_tree(&tt)?.0)) + } else { + None }; - Some(Attr { path, input }) } } -- cgit v1.2.3