mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 23:24:29 +00:00
Move raw_delimiter_count
to syntax
crate
This commit is contained in:
parent
e8c9ca2a2f
commit
6cd458f3d0
2 changed files with 13 additions and 10 deletions
|
@ -59,21 +59,21 @@ fn literal_to_external(literal: ast::LiteralKind) -> Option<proc_macro::bridge::
|
|||
Some(match lit.kind() {
|
||||
ast::LiteralKind::String(data) => {
|
||||
if data.is_raw() {
|
||||
bridge::LitKind::StrRaw(raw_delimiter_count(data)?)
|
||||
bridge::LitKind::StrRaw(data.raw_delimiter_count()?)
|
||||
} else {
|
||||
bridge::LitKind::Str
|
||||
}
|
||||
}
|
||||
ast::LiteralKind::ByteString(data) => {
|
||||
if data.is_raw() {
|
||||
bridge::LitKind::ByteStrRaw(raw_delimiter_count(data)?)
|
||||
bridge::LitKind::ByteStrRaw(data.raw_delimiter_count()?)
|
||||
} else {
|
||||
bridge::LitKind::ByteStr
|
||||
}
|
||||
}
|
||||
ast::LiteralKind::CString(data) => {
|
||||
if data.is_raw() {
|
||||
bridge::LitKind::CStrRaw(raw_delimiter_count(data)?)
|
||||
bridge::LitKind::CStrRaw(data.raw_delimiter_count()?)
|
||||
} else {
|
||||
bridge::LitKind::CStr
|
||||
}
|
||||
|
@ -86,13 +86,6 @@ fn literal_to_external(literal: ast::LiteralKind) -> Option<proc_macro::bridge::
|
|||
})
|
||||
}
|
||||
|
||||
fn raw_delimiter_count<S: IsString>(s: S) -> Option<u8> {
|
||||
let text = s.text();
|
||||
let quote_range = s.text_range_between_quotes()?;
|
||||
let range_start = s.syntax().text_range().start();
|
||||
text[TextRange::up_to((quote_range - range_start).start())].matches('#').count().try_into().ok()
|
||||
}
|
||||
|
||||
fn str_to_lit_node(input: &str) -> Option<ast::Literal> {
|
||||
let input = input.trim();
|
||||
let source_code = format!("fn f() {{ let _ = {input}; }}");
|
||||
|
|
|
@ -204,6 +204,16 @@ pub trait IsString: AstToken {
|
|||
assert!(TextRange::up_to(contents_range.len()).contains_range(range));
|
||||
Some(range + contents_range.start())
|
||||
}
|
||||
fn raw_delimiter_count(&self) -> Option<u8> {
|
||||
let text = self.text();
|
||||
let quote_range = self.text_range_between_quotes()?;
|
||||
let range_start = self.syntax().text_range().start();
|
||||
text[TextRange::up_to((quote_range - range_start).start())]
|
||||
.matches('#')
|
||||
.count()
|
||||
.try_into()
|
||||
.ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl IsString for ast::String {
|
||||
|
|
Loading…
Reference in a new issue