diff options
Diffstat (limited to 'crates/syntax')
-rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 50c1c157d..c5cd1c504 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs | |||
@@ -7,7 +7,7 @@ use itertools::Itertools; | |||
7 | use parser::SyntaxKind; | 7 | use parser::SyntaxKind; |
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | ast::{self, support, AstNode, NameOwner, SyntaxNode}, | 10 | ast::{self, support, token_ext::HasStringValue, AstNode, AstToken, NameOwner, SyntaxNode}, |
11 | SmolStr, SyntaxElement, SyntaxToken, T, | 11 | SmolStr, SyntaxElement, SyntaxToken, T, |
12 | }; | 12 | }; |
13 | 13 | ||
@@ -53,8 +53,16 @@ impl ast::Attr { | |||
53 | pub fn as_simple_key_value(&self) -> Option<(SmolStr, SmolStr)> { | 53 | pub fn as_simple_key_value(&self) -> Option<(SmolStr, SmolStr)> { |
54 | let lit = self.literal()?; | 54 | let lit = self.literal()?; |
55 | let key = self.simple_name()?; | 55 | let key = self.simple_name()?; |
56 | // FIXME: escape? raw string? | 56 | let value_token = lit.syntax().first_token()?; |
57 | let value = lit.syntax().first_token()?.text().trim_matches('"').into(); | 57 | |
58 | let value: SmolStr = if let Some(s) = ast::String::cast(value_token.clone()) { | ||
59 | s.value()?.into() | ||
60 | } else if let Some(s) = ast::RawString::cast(value_token) { | ||
61 | s.value()?.into() | ||
62 | } else { | ||
63 | return None; | ||
64 | }; | ||
65 | |||
58 | Some((key, value)) | 66 | Some((key, value)) |
59 | } | 67 | } |
60 | 68 | ||