2019-04-02 10:02:23 +00:00
|
|
|
//! There are many AstNodes, but only a few tokens, so we hand-write them here.
|
|
|
|
|
2019-04-02 07:23:18 +00:00
|
|
|
use crate::{
|
2020-04-03 19:12:08 +00:00
|
|
|
ast::{AstToken, Comment, RawString, String, Whitespace},
|
|
|
|
TextRange, TextUnit,
|
2019-04-02 07:23:18 +00:00
|
|
|
};
|
|
|
|
|
2019-07-18 16:23:05 +00:00
|
|
|
impl Comment {
|
2019-04-02 09:18:52 +00:00
|
|
|
pub fn kind(&self) -> CommentKind {
|
|
|
|
kind_by_prefix(self.text())
|
2019-04-02 07:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn prefix(&self) -> &'static str {
|
2019-04-02 09:18:52 +00:00
|
|
|
prefix_by_kind(self.kind())
|
2019-04-02 07:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:18:52 +00:00
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
|
|
|
pub struct CommentKind {
|
|
|
|
pub shape: CommentShape,
|
|
|
|
pub doc: Option<CommentPlacement>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
|
|
|
pub enum CommentShape {
|
2019-04-02 07:23:18 +00:00
|
|
|
Line,
|
2019-04-02 09:18:52 +00:00
|
|
|
Block,
|
2019-04-02 07:23:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 09:18:52 +00:00
|
|
|
impl CommentShape {
|
|
|
|
pub fn is_line(self) -> bool {
|
|
|
|
self == CommentShape::Line
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_block(self) -> bool {
|
|
|
|
self == CommentShape::Block
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
|
|
|
pub enum CommentPlacement {
|
|
|
|
Inner,
|
|
|
|
Outer,
|
|
|
|
}
|
|
|
|
|
|
|
|
const COMMENT_PREFIX_TO_KIND: &[(&str, CommentKind)] = {
|
2019-07-04 20:05:17 +00:00
|
|
|
use {CommentPlacement::*, CommentShape::*};
|
2019-04-02 09:18:52 +00:00
|
|
|
&[
|
|
|
|
("///", CommentKind { shape: Line, doc: Some(Outer) }),
|
|
|
|
("//!", CommentKind { shape: Line, doc: Some(Inner) }),
|
|
|
|
("/**", CommentKind { shape: Block, doc: Some(Outer) }),
|
2019-04-02 11:42:47 +00:00
|
|
|
("/*!", CommentKind { shape: Block, doc: Some(Inner) }),
|
2019-04-02 09:18:52 +00:00
|
|
|
("//", CommentKind { shape: Line, doc: None }),
|
|
|
|
("/*", CommentKind { shape: Block, doc: None }),
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
fn kind_by_prefix(text: &str) -> CommentKind {
|
|
|
|
for (prefix, kind) in COMMENT_PREFIX_TO_KIND.iter() {
|
|
|
|
if text.starts_with(prefix) {
|
|
|
|
return *kind;
|
2019-04-02 07:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-02 09:18:52 +00:00
|
|
|
panic!("bad comment text: {:?}", text)
|
|
|
|
}
|
2019-04-02 07:23:18 +00:00
|
|
|
|
2019-04-02 09:18:52 +00:00
|
|
|
fn prefix_by_kind(kind: CommentKind) -> &'static str {
|
|
|
|
for (prefix, k) in COMMENT_PREFIX_TO_KIND.iter() {
|
|
|
|
if *k == kind {
|
|
|
|
return prefix;
|
2019-04-02 07:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-02 09:18:52 +00:00
|
|
|
unreachable!()
|
2019-04-02 07:23:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 16:23:05 +00:00
|
|
|
impl Whitespace {
|
2019-04-02 07:23:18 +00:00
|
|
|
pub fn spans_multiple_lines(&self) -> bool {
|
|
|
|
let text = self.text();
|
|
|
|
text.find('\n').map_or(false, |idx| text[idx + 1..].contains('\n'))
|
|
|
|
}
|
|
|
|
}
|
2019-11-16 19:50:41 +00:00
|
|
|
|
2020-02-27 16:19:53 +00:00
|
|
|
pub struct QuoteOffsets {
|
|
|
|
pub quotes: [TextRange; 2],
|
|
|
|
pub contents: TextRange,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QuoteOffsets {
|
|
|
|
fn new(literal: &str) -> Option<QuoteOffsets> {
|
|
|
|
let left_quote = literal.find('"')?;
|
|
|
|
let right_quote = literal.rfind('"')?;
|
|
|
|
if left_quote == right_quote {
|
|
|
|
// `literal` only contains one quote
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
let start = TextUnit::from(0);
|
|
|
|
let left_quote = TextUnit::from_usize(left_quote) + TextUnit::of_char('"');
|
|
|
|
let right_quote = TextUnit::from_usize(right_quote);
|
|
|
|
let end = TextUnit::of_str(literal);
|
|
|
|
|
|
|
|
let res = QuoteOffsets {
|
|
|
|
quotes: [TextRange::from_to(start, left_quote), TextRange::from_to(right_quote, end)],
|
|
|
|
contents: TextRange::from_to(left_quote, right_quote),
|
|
|
|
};
|
|
|
|
Some(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait HasQuotes: AstToken {
|
|
|
|
fn quote_offsets(&self) -> Option<QuoteOffsets> {
|
|
|
|
let text = self.text().as_str();
|
|
|
|
let offsets = QuoteOffsets::new(text)?;
|
|
|
|
let o = self.syntax().text_range().start();
|
|
|
|
let offsets = QuoteOffsets {
|
|
|
|
quotes: [offsets.quotes[0] + o, offsets.quotes[1] + o],
|
|
|
|
contents: offsets.contents + o,
|
|
|
|
};
|
|
|
|
Some(offsets)
|
|
|
|
}
|
|
|
|
fn open_quote_text_range(&self) -> Option<TextRange> {
|
|
|
|
self.quote_offsets().map(|it| it.quotes[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
fn close_quote_text_range(&self) -> Option<TextRange> {
|
|
|
|
self.quote_offsets().map(|it| it.quotes[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
fn text_range_between_quotes(&self) -> Option<TextRange> {
|
|
|
|
self.quote_offsets().map(|it| it.contents)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasQuotes for String {}
|
|
|
|
impl HasQuotes for RawString {}
|
|
|
|
|
|
|
|
pub trait HasStringValue: HasQuotes {
|
|
|
|
fn value(&self) -> Option<std::string::String>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasStringValue for String {
|
|
|
|
fn value(&self) -> Option<std::string::String> {
|
2019-11-16 19:50:41 +00:00
|
|
|
let text = self.text().as_str();
|
2020-02-27 16:19:53 +00:00
|
|
|
let text = &text[self.text_range_between_quotes()? - self.syntax().text_range().start()];
|
2019-11-16 19:50:41 +00:00
|
|
|
|
2020-02-27 16:19:53 +00:00
|
|
|
let mut buf = std::string::String::with_capacity(text.len());
|
2019-11-16 19:50:41 +00:00
|
|
|
let mut has_error = false;
|
2020-02-27 16:19:53 +00:00
|
|
|
rustc_lexer::unescape::unescape_str(text, &mut |_, unescaped_char| match unescaped_char {
|
|
|
|
Ok(c) => buf.push(c),
|
|
|
|
Err(_) => has_error = true,
|
2019-11-16 19:50:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if has_error {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
Some(buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-27 16:19:53 +00:00
|
|
|
impl HasStringValue for RawString {
|
|
|
|
fn value(&self) -> Option<std::string::String> {
|
2020-02-27 15:05:35 +00:00
|
|
|
let text = self.text().as_str();
|
2020-02-27 16:19:53 +00:00
|
|
|
let text = &text[self.text_range_between_quotes()? - self.syntax().text_range().start()];
|
|
|
|
Some(text.to_string())
|
2020-02-27 15:05:35 +00:00
|
|
|
}
|
2020-02-27 16:19:53 +00:00
|
|
|
}
|
2020-02-27 15:05:35 +00:00
|
|
|
|
2020-02-27 16:19:53 +00:00
|
|
|
impl RawString {
|
2020-02-27 15:05:35 +00:00
|
|
|
pub fn map_range_up(&self, range: TextRange) -> Option<TextRange> {
|
2020-02-27 16:19:53 +00:00
|
|
|
let contents_range = self.text_range_between_quotes()?;
|
|
|
|
assert!(range.is_subrange(&TextRange::offset_len(0.into(), contents_range.len())));
|
|
|
|
Some(range + contents_range.start())
|
2019-11-16 19:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-17 07:37:18 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum FormatSpecifier {
|
|
|
|
Open,
|
|
|
|
Close,
|
|
|
|
Integer,
|
|
|
|
Identifier,
|
|
|
|
Colon,
|
|
|
|
Fill,
|
|
|
|
Align,
|
|
|
|
Sign,
|
|
|
|
NumberSign,
|
|
|
|
Zero,
|
|
|
|
DollarSign,
|
|
|
|
Dot,
|
|
|
|
Asterisk,
|
|
|
|
QuestionMark,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait HasFormatSpecifier: AstToken {
|
2020-04-22 08:08:46 +00:00
|
|
|
fn lex_format_specifier<F>(&self, mut callback: F)
|
2020-04-17 07:37:18 +00:00
|
|
|
where
|
|
|
|
F: FnMut(TextRange, FormatSpecifier),
|
|
|
|
{
|
|
|
|
let src = self.text().as_str();
|
|
|
|
let initial_len = src.len();
|
|
|
|
let mut chars = src.chars();
|
|
|
|
|
|
|
|
while let Some(first_char) = chars.next() {
|
|
|
|
match first_char {
|
|
|
|
'{' => {
|
|
|
|
// Format specifier, see syntax at https://doc.rust-lang.org/std/fmt/index.html#syntax
|
|
|
|
if chars.clone().next() == Some('{') {
|
|
|
|
// Escaped format specifier, `{{`
|
|
|
|
chars.next();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let start = initial_len - chars.as_str().len() - first_char.len_utf8();
|
|
|
|
let end = initial_len - chars.as_str().len();
|
|
|
|
callback(
|
|
|
|
TextRange::from_to(TextUnit::from_usize(start), TextUnit::from_usize(end)),
|
|
|
|
FormatSpecifier::Open,
|
|
|
|
);
|
|
|
|
|
|
|
|
// check for integer/identifier
|
2020-04-22 08:08:46 +00:00
|
|
|
match chars.clone().next().unwrap_or_default() {
|
2020-04-17 07:37:18 +00:00
|
|
|
'0'..='9' => {
|
|
|
|
// integer
|
2020-04-22 08:08:46 +00:00
|
|
|
read_integer(&mut chars, initial_len, &mut callback);
|
2020-04-17 07:37:18 +00:00
|
|
|
}
|
|
|
|
'a'..='z' | 'A'..='Z' | '_' => {
|
|
|
|
// identifier
|
2020-04-22 08:08:46 +00:00
|
|
|
read_identifier(&mut chars, initial_len, &mut callback);
|
2020-04-17 07:37:18 +00:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
if chars.clone().next() == Some(':') {
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::Colon,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// check for fill/align
|
|
|
|
let mut cloned = chars.clone().take(2);
|
|
|
|
let first = cloned.next().unwrap_or_default();
|
|
|
|
let second = cloned.next().unwrap_or_default();
|
|
|
|
match second {
|
|
|
|
'<' | '^' | '>' => {
|
|
|
|
// alignment specifier, first char specifies fillment
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::Fill,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::Align,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
_ => match first {
|
|
|
|
'<' | '^' | '>' => {
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::Align,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for sign
|
|
|
|
match chars.clone().next().unwrap_or_default() {
|
|
|
|
'+' | '-' => {
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::Sign,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for `#`
|
|
|
|
if let Some('#') = chars.clone().next() {
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::NumberSign,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for `0`
|
|
|
|
let mut cloned = chars.clone().take(2);
|
|
|
|
let first = cloned.next();
|
|
|
|
let second = cloned.next();
|
|
|
|
|
|
|
|
if first == Some('0') && second != Some('$') {
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::Zero,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// width
|
|
|
|
match chars.clone().next().unwrap_or_default() {
|
|
|
|
'0'..='9' => {
|
2020-04-22 08:08:46 +00:00
|
|
|
read_integer(&mut chars, initial_len, &mut callback);
|
2020-04-17 07:37:18 +00:00
|
|
|
if chars.clone().next() == Some('$') {
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::DollarSign,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'a'..='z' | 'A'..='Z' | '_' => {
|
2020-04-22 08:08:46 +00:00
|
|
|
read_identifier(&mut chars, initial_len, &mut callback);
|
2020-04-17 07:37:18 +00:00
|
|
|
if chars.clone().next() != Some('$') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::DollarSign,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// precision
|
|
|
|
if chars.clone().next() == Some('.') {
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::Dot,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
match chars.clone().next().unwrap_or_default() {
|
|
|
|
'*' => {
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::Asterisk,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
'0'..='9' => {
|
2020-04-22 08:08:46 +00:00
|
|
|
read_integer(&mut chars, initial_len, &mut callback);
|
2020-04-17 07:37:18 +00:00
|
|
|
if chars.clone().next() == Some('$') {
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::DollarSign,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'a'..='z' | 'A'..='Z' | '_' => {
|
2020-04-22 08:08:46 +00:00
|
|
|
read_identifier(&mut chars, initial_len, &mut callback);
|
2020-04-17 07:37:18 +00:00
|
|
|
if chars.clone().next() != Some('$') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::DollarSign,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// type
|
|
|
|
match chars.clone().next().unwrap_or_default() {
|
|
|
|
'?' => {
|
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::QuestionMark,
|
2020-04-22 08:08:46 +00:00
|
|
|
&mut callback,
|
2020-04-17 07:37:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
'a'..='z' | 'A'..='Z' | '_' => {
|
2020-04-22 08:08:46 +00:00
|
|
|
read_identifier(&mut chars, initial_len, &mut callback);
|
2020-04-17 07:37:18 +00:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut cloned = chars.clone().take(2);
|
|
|
|
let first = cloned.next();
|
|
|
|
let second = cloned.next();
|
|
|
|
if first != Some('}') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if second == Some('}') {
|
|
|
|
// Escaped format end specifier, `}}`
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-22 08:08:46 +00:00
|
|
|
skip_char_and_emit(
|
|
|
|
&mut chars,
|
|
|
|
initial_len,
|
|
|
|
FormatSpecifier::Close,
|
|
|
|
&mut callback,
|
|
|
|
);
|
2020-04-17 07:37:18 +00:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
while let Some(next_char) = chars.clone().next() {
|
|
|
|
match next_char {
|
|
|
|
'{' => break,
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
chars.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn skip_char_and_emit<F>(
|
|
|
|
chars: &mut std::str::Chars,
|
|
|
|
initial_len: usize,
|
|
|
|
emit: FormatSpecifier,
|
|
|
|
callback: &mut F,
|
|
|
|
) where
|
|
|
|
F: FnMut(TextRange, FormatSpecifier),
|
|
|
|
{
|
|
|
|
let start = initial_len - chars.as_str().len();
|
|
|
|
chars.next();
|
|
|
|
let end = initial_len - chars.as_str().len();
|
|
|
|
callback(
|
|
|
|
TextRange::from_to(TextUnit::from_usize(start), TextUnit::from_usize(end)),
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn read_integer<F>(chars: &mut std::str::Chars, initial_len: usize, callback: &mut F)
|
|
|
|
where
|
|
|
|
F: FnMut(TextRange, FormatSpecifier),
|
|
|
|
{
|
|
|
|
let start = initial_len - chars.as_str().len();
|
|
|
|
chars.next();
|
|
|
|
while let Some(next_char) = chars.clone().next() {
|
|
|
|
match next_char {
|
|
|
|
'0'..='9' => {
|
|
|
|
chars.next();
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let end = initial_len - chars.as_str().len();
|
|
|
|
callback(
|
|
|
|
TextRange::from_to(TextUnit::from_usize(start), TextUnit::from_usize(end)),
|
|
|
|
FormatSpecifier::Integer,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
fn read_identifier<F>(chars: &mut std::str::Chars, initial_len: usize, callback: &mut F)
|
|
|
|
where
|
|
|
|
F: FnMut(TextRange, FormatSpecifier),
|
|
|
|
{
|
|
|
|
let start = initial_len - chars.as_str().len();
|
|
|
|
chars.next();
|
|
|
|
while let Some(next_char) = chars.clone().next() {
|
|
|
|
match next_char {
|
|
|
|
'a'..='z' | 'A'..='Z' | '0'..='9' | '_' => {
|
|
|
|
chars.next();
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let end = initial_len - chars.as_str().len();
|
|
|
|
callback(
|
|
|
|
TextRange::from_to(TextUnit::from_usize(start), TextUnit::from_usize(end)),
|
|
|
|
FormatSpecifier::Identifier,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasFormatSpecifier for String {}
|
|
|
|
impl HasFormatSpecifier for RawString {}
|