1#![deny(unstable_features)]
26#[cfg(test)]
29mod tests;
30
31use std::str::Chars;
32
33use LiteralKind::*;
34use TokenKind::*;
35use rustc_unicode::{unicode_ident, unicode_properties};
36use unicode_properties::UnicodeEmoji;
37
38#[derive(#[automatically_derived]impl ::core::fmt::Debug for Token {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Token kind len", &self.kind, &&self.len)
}
}Debug)]
42pub struct Token {
43 pub kind: TokenKind,
44 pub len: u32,
45}
46
47impl Token {
48 fn new(kind: TokenKind, len: u32) -> Token {
49 Token { kind, len }
50 }
51}
52
53#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for TokenKind {
}
#[automatically_derived]impl ::core::clone::Clone for TokenKind {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Option<DocStyle>>;
let _: ::core::clone::AssertParamIsClone<Option<DocStyle>>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<LiteralKind>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for TokenKind { }Copy, #[automatically_derived]impl ::core::fmt::Debug for TokenKind {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::LineComment { doc_style: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"LineComment doc_style", &__self_0),
Self::BlockComment { doc_style: __self_0, terminated: __self_1 }
=>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"BlockComment doc_style terminated", __self_0, &__self_1),
Self::Whitespace =>
::core::fmt::Formatter::write_str(f, "Whitespace"),
Self::Frontmatter {
has_invalid_preceding_whitespace: __self_0,
invalid_infostring: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Frontmatter has_invalid_preceding_whitespace invalid_infostring",
__self_0, &__self_1),
Self::Ident => ::core::fmt::Formatter::write_str(f, "Ident"),
Self::InvalidIdent =>
::core::fmt::Formatter::write_str(f, "InvalidIdent"),
Self::RawIdent =>
::core::fmt::Formatter::write_str(f, "RawIdent"),
Self::ForcedKeywordIdent =>
::core::fmt::Formatter::write_str(f, "ForcedKeywordIdent"),
Self::UnknownPrefix =>
::core::fmt::Formatter::write_str(f, "UnknownPrefix"),
Self::UnknownPrefixLifetime =>
::core::fmt::Formatter::write_str(f, "UnknownPrefixLifetime"),
Self::RawLifetime =>
::core::fmt::Formatter::write_str(f, "RawLifetime"),
Self::GuardedStrPrefix =>
::core::fmt::Formatter::write_str(f, "GuardedStrPrefix"),
Self::Literal { kind: __self_0, suffix_start: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Literal kind suffix_start", __self_0, &__self_1),
Self::Lifetime { starts_with_number: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Lifetime starts_with_number", &__self_0),
Self::Semi => ::core::fmt::Formatter::write_str(f, "Semi"),
Self::Comma => ::core::fmt::Formatter::write_str(f, "Comma"),
Self::Dot => ::core::fmt::Formatter::write_str(f, "Dot"),
Self::OpenParen =>
::core::fmt::Formatter::write_str(f, "OpenParen"),
Self::CloseParen =>
::core::fmt::Formatter::write_str(f, "CloseParen"),
Self::OpenBrace =>
::core::fmt::Formatter::write_str(f, "OpenBrace"),
Self::CloseBrace =>
::core::fmt::Formatter::write_str(f, "CloseBrace"),
Self::OpenBracket =>
::core::fmt::Formatter::write_str(f, "OpenBracket"),
Self::CloseBracket =>
::core::fmt::Formatter::write_str(f, "CloseBracket"),
Self::At => ::core::fmt::Formatter::write_str(f, "At"),
Self::Pound => ::core::fmt::Formatter::write_str(f, "Pound"),
Self::Tilde => ::core::fmt::Formatter::write_str(f, "Tilde"),
Self::Question =>
::core::fmt::Formatter::write_str(f, "Question"),
Self::Colon => ::core::fmt::Formatter::write_str(f, "Colon"),
Self::Dollar => ::core::fmt::Formatter::write_str(f, "Dollar"),
Self::Eq => ::core::fmt::Formatter::write_str(f, "Eq"),
Self::Bang => ::core::fmt::Formatter::write_str(f, "Bang"),
Self::Lt => ::core::fmt::Formatter::write_str(f, "Lt"),
Self::Gt => ::core::fmt::Formatter::write_str(f, "Gt"),
Self::Minus => ::core::fmt::Formatter::write_str(f, "Minus"),
Self::And => ::core::fmt::Formatter::write_str(f, "And"),
Self::Or => ::core::fmt::Formatter::write_str(f, "Or"),
Self::Plus => ::core::fmt::Formatter::write_str(f, "Plus"),
Self::Star => ::core::fmt::Formatter::write_str(f, "Star"),
Self::Slash => ::core::fmt::Formatter::write_str(f, "Slash"),
Self::Caret => ::core::fmt::Formatter::write_str(f, "Caret"),
Self::Percent => ::core::fmt::Formatter::write_str(f, "Percent"),
Self::Unknown => ::core::fmt::Formatter::write_str(f, "Unknown"),
Self::Eof => ::core::fmt::Formatter::write_str(f, "Eof"),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for TokenKind
{
}
#[automatically_derived]impl ::core::cmp::PartialEq for TokenKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::LineComment { doc_style: __self_0 },
Self::LineComment { doc_style: __arg1_0 }) =>
__self_0 == __arg1_0,
(Self::BlockComment {
doc_style: __self_0, terminated: __self_1 },
Self::BlockComment {
doc_style: __arg1_0, terminated: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::Frontmatter {
has_invalid_preceding_whitespace: __self_0,
invalid_infostring: __self_1 }, Self::Frontmatter {
has_invalid_preceding_whitespace: __arg1_0,
invalid_infostring: __arg1_1 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(Self::Literal { kind: __self_0, suffix_start: __self_1 },
Self::Literal { kind: __arg1_0, suffix_start: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::Lifetime { starts_with_number: __self_0 },
Self::Lifetime { starts_with_number: __arg1_0 }) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for TokenKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Option<DocStyle>>;
let _: ::core::cmp::AssertParamIsEq<Option<DocStyle>>;
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<LiteralKind>;
let _: ::core::cmp::AssertParamIsEq<u32>;
}
}Eq)]
55pub enum TokenKind {
56 LineComment {
58 doc_style: Option<DocStyle>,
59 },
60
61 BlockComment {
66 doc_style: Option<DocStyle>,
67 terminated: bool,
68 },
69
70 Whitespace,
72
73 Frontmatter {
74 has_invalid_preceding_whitespace: bool,
75 invalid_infostring: bool,
76 },
77
78 Ident,
80
81 InvalidIdent,
83
84 RawIdent,
86
87 ForcedKeywordIdent,
89
90 UnknownPrefix,
100
101 UnknownPrefixLifetime,
106
107 RawLifetime,
110
111 GuardedStrPrefix,
116
117 Literal {
123 kind: LiteralKind,
124 suffix_start: u32,
125 },
126
127 Lifetime {
129 starts_with_number: bool,
133 },
134
135 Semi,
137 Comma,
139 Dot,
141 OpenParen,
143 CloseParen,
145 OpenBrace,
147 CloseBrace,
149 OpenBracket,
151 CloseBracket,
153 At,
155 Pound,
157 Tilde,
159 Question,
161 Colon,
163 Dollar,
165 Eq,
167 Bang,
169 Lt,
171 Gt,
173 Minus,
175 And,
177 Or,
179 Plus,
181 Star,
183 Slash,
185 Caret,
187 Percent,
189
190 Unknown,
192
193 Eof,
195}
196
197#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for DocStyle {
}
#[automatically_derived]impl ::core::clone::Clone for DocStyle {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for DocStyle { }Copy, #[automatically_derived]impl ::core::fmt::Debug for DocStyle {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
DocStyle::Outer => "Outer",
DocStyle::Inner => "Inner",
})
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for DocStyle
{
}
#[automatically_derived]impl ::core::cmp::PartialEq for DocStyle {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for DocStyle { }Eq)]
198pub enum DocStyle {
199 Outer,
200 Inner,
201}
202
203#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for LiteralKind {
}
#[automatically_derived]impl ::core::clone::Clone for LiteralKind {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Base>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Option<u8>>;
let _: ::core::clone::AssertParamIsClone<Option<u8>>;
let _: ::core::clone::AssertParamIsClone<Option<u8>>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for LiteralKind { }Copy, #[automatically_derived]impl ::core::fmt::Debug for LiteralKind {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Int { base: __self_0, empty_int: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Int base empty_int", __self_0, &__self_1),
Self::Float { base: __self_0, empty_exponent: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Float base empty_exponent", __self_0, &__self_1),
Self::Char { terminated: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Char terminated", &__self_0),
Self::Byte { terminated: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Byte terminated", &__self_0),
Self::Str { terminated: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Str terminated", &__self_0),
Self::ByteStr { terminated: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ByteStr terminated", &__self_0),
Self::CStr { terminated: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"CStr terminated", &__self_0),
Self::RawStr { n_hashes: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"RawStr n_hashes", &__self_0),
Self::RawByteStr { n_hashes: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"RawByteStr n_hashes", &__self_0),
Self::RawCStr { n_hashes: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"RawCStr n_hashes", &__self_0),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
LiteralKind {
}
#[automatically_derived]impl ::core::cmp::PartialEq for LiteralKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Int { base: __self_0, empty_int: __self_1 },
Self::Int { base: __arg1_0, empty_int: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::Float { base: __self_0, empty_exponent: __self_1 },
Self::Float { base: __arg1_0, empty_exponent: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::Char { terminated: __self_0 }, Self::Char {
terminated: __arg1_0 }) => __self_0 == __arg1_0,
(Self::Byte { terminated: __self_0 }, Self::Byte {
terminated: __arg1_0 }) => __self_0 == __arg1_0,
(Self::Str { terminated: __self_0 }, Self::Str {
terminated: __arg1_0 }) => __self_0 == __arg1_0,
(Self::ByteStr { terminated: __self_0 }, Self::ByteStr {
terminated: __arg1_0 }) => __self_0 == __arg1_0,
(Self::CStr { terminated: __self_0 }, Self::CStr {
terminated: __arg1_0 }) => __self_0 == __arg1_0,
(Self::RawStr { n_hashes: __self_0 }, Self::RawStr {
n_hashes: __arg1_0 }) => __self_0 == __arg1_0,
(Self::RawByteStr { n_hashes: __self_0 }, Self::RawByteStr {
n_hashes: __arg1_0 }) => __self_0 == __arg1_0,
(Self::RawCStr { n_hashes: __self_0 }, Self::RawCStr {
n_hashes: __arg1_0 }) => __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for LiteralKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Base>;
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<Option<u8>>;
let _: ::core::cmp::AssertParamIsEq<Option<u8>>;
let _: ::core::cmp::AssertParamIsEq<Option<u8>>;
}
}Eq, #[automatically_derived]impl ::core::cmp::PartialOrd for LiteralKind {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl ::core::cmp::Ord for LiteralKind {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
match (self, other) {
(Self::Int { base: __self_0, empty_int: __self_1 }, Self::Int {
base: __arg1_0, empty_int: __arg1_1 }) =>
match ::core::cmp::Ord::cmp(__self_0, __arg1_0) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(__self_1, __arg1_1),
cmp => cmp,
},
(Self::Float { base: __self_0, empty_exponent: __self_1 },
Self::Float { base: __arg1_0, empty_exponent: __arg1_1 }) =>
match ::core::cmp::Ord::cmp(__self_0, __arg1_0) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(__self_1, __arg1_1),
cmp => cmp,
},
(Self::Char { terminated: __self_0 }, Self::Char {
terminated: __arg1_0 }) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::Byte { terminated: __self_0 }, Self::Byte {
terminated: __arg1_0 }) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::Str { terminated: __self_0 }, Self::Str {
terminated: __arg1_0 }) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::ByteStr { terminated: __self_0 }, Self::ByteStr {
terminated: __arg1_0 }) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::CStr { terminated: __self_0 }, Self::CStr {
terminated: __arg1_0 }) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::RawStr { n_hashes: __self_0 }, Self::RawStr {
n_hashes: __arg1_0 }) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::RawByteStr { n_hashes: __self_0 }, Self::RawByteStr {
n_hashes: __arg1_0 }) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::RawCStr { n_hashes: __self_0 }, Self::RawCStr {
n_hashes: __arg1_0 }) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
_ =>
::core::cmp::Ord::cmp(&::core::intrinsics::discriminant_value(self),
&::core::intrinsics::discriminant_value(other)),
}
}
}Ord)]
210pub enum LiteralKind {
211 Int { base: Base, empty_int: bool },
213 Float { base: Base, empty_exponent: bool },
215 Char { terminated: bool },
217 Byte { terminated: bool },
219 Str { terminated: bool },
221 ByteStr { terminated: bool },
223 CStr { terminated: bool },
225 RawStr { n_hashes: Option<u8> },
228 RawByteStr { n_hashes: Option<u8> },
231 RawCStr { n_hashes: Option<u8> },
233}
234
235#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for GuardedStr {
}
#[automatically_derived]impl ::core::clone::Clone for GuardedStr {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for GuardedStr { }Copy, #[automatically_derived]impl ::core::fmt::Debug for GuardedStr {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"GuardedStr n_hashes terminated token_len", &self.n_hashes,
&self.terminated, &&self.token_len)
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
GuardedStr {
}
#[automatically_derived]impl ::core::cmp::PartialEq for GuardedStr {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.n_hashes == other.n_hashes && self.terminated == other.terminated
&& self.token_len == other.token_len
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for GuardedStr {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u32>;
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq, #[automatically_derived]impl ::core::cmp::PartialOrd for GuardedStr {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl ::core::cmp::Ord for GuardedStr {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
match ::core::cmp::Ord::cmp(&self.n_hashes, &other.n_hashes) {
::core::cmp::Ordering::Equal =>
match ::core::cmp::Ord::cmp(&self.terminated,
&other.terminated) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(&self.token_len, &other.token_len),
cmp => cmp,
},
cmp => cmp,
}
}
}Ord)]
240pub struct GuardedStr {
241 pub n_hashes: u32,
242 pub terminated: bool,
243 pub token_len: u32,
244}
245
246#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for RawStrError {
}
#[automatically_derived]impl ::core::clone::Clone for RawStrError {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<char>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<Option<u32>>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for RawStrError { }Copy, #[automatically_derived]impl ::core::fmt::Debug for RawStrError {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::InvalidStarter { bad_char: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"InvalidStarter bad_char", &__self_0),
Self::NoTerminator {
expected: __self_0,
found: __self_1,
possible_terminator_offset: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"NoTerminator expected found possible_terminator_offset",
__self_0, __self_1, &__self_2),
Self::TooManyDelimiters { found: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"TooManyDelimiters found", &__self_0),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
RawStrError {
}
#[automatically_derived]impl ::core::cmp::PartialEq for RawStrError {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::InvalidStarter { bad_char: __self_0 },
Self::InvalidStarter { bad_char: __arg1_0 }) =>
__self_0 == __arg1_0,
(Self::NoTerminator {
expected: __self_0,
found: __self_1,
possible_terminator_offset: __self_2 }, Self::NoTerminator {
expected: __arg1_0,
found: __arg1_1,
possible_terminator_offset: __arg1_2 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1 &&
__self_2 == __arg1_2,
(Self::TooManyDelimiters { found: __self_0 },
Self::TooManyDelimiters { found: __arg1_0 }) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for RawStrError {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<char>;
let _: ::core::cmp::AssertParamIsEq<u32>;
let _: ::core::cmp::AssertParamIsEq<Option<u32>>;
}
}Eq, #[automatically_derived]impl ::core::cmp::PartialOrd for RawStrError {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl ::core::cmp::Ord for RawStrError {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
match (self, other) {
(Self::InvalidStarter { bad_char: __self_0 },
Self::InvalidStarter { bad_char: __arg1_0 }) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::NoTerminator {
expected: __self_0,
found: __self_1,
possible_terminator_offset: __self_2 }, Self::NoTerminator {
expected: __arg1_0,
found: __arg1_1,
possible_terminator_offset: __arg1_2 }) =>
match ::core::cmp::Ord::cmp(__self_0, __arg1_0) {
::core::cmp::Ordering::Equal =>
match ::core::cmp::Ord::cmp(__self_1, __arg1_1) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(__self_2, __arg1_2),
cmp => cmp,
},
cmp => cmp,
},
(Self::TooManyDelimiters { found: __self_0 },
Self::TooManyDelimiters { found: __arg1_0 }) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
_ =>
::core::cmp::Ord::cmp(&::core::intrinsics::discriminant_value(self),
&::core::intrinsics::discriminant_value(other)),
}
}
}Ord)]
247pub enum RawStrError {
248 InvalidStarter { bad_char: char },
250 NoTerminator { expected: u32, found: u32, possible_terminator_offset: Option<u32> },
254 TooManyDelimiters { found: u32 },
256}
257
258#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Base {
}
#[automatically_derived]impl ::core::clone::Clone for Base {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for Base { }Copy, #[automatically_derived]impl ::core::fmt::Debug for Base {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Base::Binary => "Binary",
Base::Octal => "Octal",
Base::Decimal => "Decimal",
Base::Hexadecimal => "Hexadecimal",
})
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Base { }
#[automatically_derived]impl ::core::cmp::PartialEq for Base {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Base { }Eq, #[automatically_derived]impl ::core::cmp::PartialOrd for Base {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl ::core::cmp::Ord for Base {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&::core::intrinsics::discriminant_value(self),
&::core::intrinsics::discriminant_value(other))
}
}Ord)]
260pub enum Base {
261 Binary = 2,
263 Octal = 8,
265 Decimal = 10,
267 Hexadecimal = 16,
269}
270
271pub fn strip_shebang(input: &str) -> Option<usize> {
274 if let Some(input_tail) = input.strip_prefix("#!") {
278 let next_non_whitespace_token =
281 tokenize(input_tail, FrontmatterAllowed::No).map(|tok| tok.kind).find(|tok| {
282 !#[allow(non_exhaustive_omitted_patterns)] match tok {
TokenKind::Whitespace | TokenKind::LineComment { doc_style: None } |
TokenKind::BlockComment { doc_style: None, .. } => true,
_ => false,
}matches!(
283 tok,
284 TokenKind::Whitespace
285 | TokenKind::LineComment { doc_style: None }
286 | TokenKind::BlockComment { doc_style: None, .. }
287 )
288 });
289 if next_non_whitespace_token != Some(TokenKind::OpenBracket) {
290 return Some(2 + input_tail.lines().next().unwrap_or_default().len());
292 }
293 }
294 None
295}
296
297#[inline]
300pub fn validate_raw_str(input: &str, prefix_len: u32) -> Result<(), RawStrError> {
301 if true {
if !!input.is_empty() {
::core::panicking::panic("assertion failed: !input.is_empty()")
};
};debug_assert!(!input.is_empty());
302 let mut cursor = Cursor::new(input, FrontmatterAllowed::No);
303 for _ in 0..prefix_len {
305 cursor.bump().unwrap();
306 }
307 cursor.raw_double_quoted_string(prefix_len).map(|_| ())
308}
309
310pub fn tokenize(
317 input: &str,
318 frontmatter_allowed: FrontmatterAllowed,
319) -> impl Iterator<Item = Token> {
320 let mut cursor = Cursor::new(input, frontmatter_allowed);
321 std::iter::from_fn(move || {
322 let token = cursor.advance_token();
323 if token.kind != TokenKind::Eof { Some(token) } else { None }
324 })
325}
326
327pub fn is_whitespace(c: char) -> bool {
331 #[allow(non_exhaustive_omitted_patterns)] match c {
'\u{000A}' | '\u{000B}' | '\u{000C}' | '\u{000D}' | '\u{0085}' |
'\u{2028}' | '\u{2029}' | '\u{200E}' | '\u{200F}' | '\u{0009}' |
'\u{0020}' => true,
_ => false,
}matches!(
337 c,
338 | '\u{000A}' | '\u{000B}' | '\u{000C}' | '\u{000D}' | '\u{0085}' | '\u{2028}' | '\u{2029}' | '\u{200E}' | '\u{200F}' | '\u{0009}' | '\u{0020}' )
355}
356
357pub fn is_horizontal_whitespace(c: char) -> bool {
359 #[allow(non_exhaustive_omitted_patterns)] match c {
'\u{0009}' | '\u{0020}' => true,
_ => false,
}matches!(
366 c,
367 '\u{0009}' | '\u{0020}' )
371}
372
373pub fn is_id_start(c: char) -> bool {
377 c == '_' || unicode_ident::is_xid_start(c)
379}
380
381pub fn is_id_continue(c: char) -> bool {
385 unicode_ident::is_xid_continue(c)
386}
387
388pub fn is_ident(string: &str) -> bool {
390 let mut chars = string.chars();
391 if let Some(start) = chars.next() {
392 is_id_start(start) && chars.all(is_id_continue)
393 } else {
394 false
395 }
396}
397
398pub enum FrontmatterAllowed {
399 Yes,
400 No,
401}
402
403pub struct Cursor<'a> {
408 len_remaining: usize,
409 chars: Chars<'a>,
411 pub(crate) frontmatter_allowed: FrontmatterAllowed,
412 #[cfg(debug_assertions)]
413 prev: char,
414}
415
416const EOF_CHAR: char = '\0';
417
418impl<'a> Cursor<'a> {
419 pub fn new(input: &'a str, frontmatter_allowed: FrontmatterAllowed) -> Cursor<'a> {
420 Cursor {
421 len_remaining: input.len(),
422 chars: input.chars(),
423 frontmatter_allowed,
424 #[cfg(debug_assertions)]
425 prev: EOF_CHAR,
426 }
427 }
428
429 pub fn as_str(&self) -> &'a str {
430 self.chars.as_str()
431 }
432
433 pub(crate) fn prev(&self) -> char {
436 #[cfg(debug_assertions)]
437 {
438 self.prev
439 }
440
441 #[cfg(not(debug_assertions))]
442 {
443 EOF_CHAR
444 }
445 }
446
447 pub fn first(&self) -> char {
452 self.chars.clone().next().unwrap_or(EOF_CHAR)
454 }
455
456 pub(crate) fn second(&self) -> char {
458 let mut iter = self.chars.clone();
460 iter.next();
461 iter.next().unwrap_or(EOF_CHAR)
462 }
463
464 pub fn third(&self) -> char {
466 let mut iter = self.chars.clone();
468 iter.next();
469 iter.next();
470 iter.next().unwrap_or(EOF_CHAR)
471 }
472
473 pub(crate) fn is_eof(&self) -> bool {
475 self.chars.as_str().is_empty()
476 }
477
478 pub(crate) fn pos_within_token(&self) -> u32 {
480 (self.len_remaining - self.chars.as_str().len()) as u32
481 }
482
483 pub(crate) fn reset_pos_within_token(&mut self) {
485 self.len_remaining = self.chars.as_str().len();
486 }
487
488 pub(crate) fn bump(&mut self) -> Option<char> {
490 let c = self.chars.next()?;
491
492 #[cfg(debug_assertions)]
493 {
494 self.prev = c;
495 }
496
497 Some(c)
498 }
499
500 pub(crate) fn bump_bytes(&mut self, n: usize) {
502 self.chars = self.as_str()[n..].chars();
503 }
504
505 pub(crate) fn eat_while(&mut self, mut predicate: impl FnMut(char) -> bool) {
507 while predicate(self.first()) && !self.is_eof() {
510 self.bump();
511 }
512 }
513
514 pub(crate) fn eat_until(&mut self, byte: u8) {
515 self.chars = match memchr::memchr(byte, self.as_str().as_bytes()) {
516 Some(index) => self.as_str()[index..].chars(),
517 None => "".chars(),
518 }
519 }
520
521 pub fn advance_token(&mut self) -> Token {
523 let Some(first_char) = self.bump() else {
524 return Token::new(TokenKind::Eof, 0);
525 };
526
527 let token_kind = match first_char {
528 c if #[allow(non_exhaustive_omitted_patterns)] match self.frontmatter_allowed {
FrontmatterAllowed::Yes => true,
_ => false,
}matches!(self.frontmatter_allowed, FrontmatterAllowed::Yes)
529 && is_whitespace(c) =>
530 {
531 let mut last = first_char;
532 while is_whitespace(self.first()) {
533 let Some(c) = self.bump() else {
534 break;
535 };
536 last = c;
537 }
538 if last != '\n' && self.as_str().starts_with("---") {
542 self.bump();
543 self.frontmatter(true)
544 } else {
545 Whitespace
546 }
547 }
548 '-' if #[allow(non_exhaustive_omitted_patterns)] match self.frontmatter_allowed {
FrontmatterAllowed::Yes => true,
_ => false,
}matches!(self.frontmatter_allowed, FrontmatterAllowed::Yes)
549 && self.as_str().starts_with("--") =>
550 {
551 self.frontmatter(false)
553 }
554 '/' => match self.first() {
556 '/' => self.line_comment(),
557 '*' => self.block_comment(),
558 _ => Slash,
559 },
560
561 c if is_whitespace(c) => self.whitespace(),
563
564 'r' => match (self.first(), self.second()) {
566 ('#', c1) if is_id_start(c1) => {
567 self.bump(); self.eat_identifier();
569 RawIdent
570 }
571 ('#', _) | ('"', _) => {
572 let res = self.raw_double_quoted_string(1);
573 let suffix_start = self.pos_within_token();
574 if res.is_ok() {
575 self.eat_literal_suffix();
576 }
577 let kind = RawStr { n_hashes: res.ok() };
578 Literal { kind, suffix_start }
579 }
580 _ => self.ident_or_unknown_prefix(false),
581 },
582
583 'k' => match (self.first(), self.second()) {
585 ('#', c1) if is_id_start(c1) => {
586 self.bump(); self.eat_identifier();
588 ForcedKeywordIdent
589 }
590 _ => self.ident_or_unknown_prefix(false),
591 },
592
593 'b' => self.c_or_byte_string(
595 |terminated| ByteStr { terminated },
596 |n_hashes| RawByteStr { n_hashes },
597 Some(|terminated| Byte { terminated }),
598 ),
599
600 'c' => self.c_or_byte_string(
602 |terminated| CStr { terminated },
603 |n_hashes| RawCStr { n_hashes },
604 None,
605 ),
606
607 c if is_id_start(c) => self.ident_or_unknown_prefix(false),
610
611 c @ '0'..='9' => {
613 let literal_kind = self.number(c);
614 let suffix_start = self.pos_within_token();
615 self.eat_literal_suffix();
616 TokenKind::Literal { kind: literal_kind, suffix_start }
617 }
618
619 '#' if #[allow(non_exhaustive_omitted_patterns)] match self.first() {
'"' | '#' => true,
_ => false,
}matches!(self.first(), '"' | '#') => {
621 self.bump();
622 TokenKind::GuardedStrPrefix
623 }
624
625 ';' => Semi,
627 ',' => Comma,
628 '.' => Dot,
629 '(' => OpenParen,
630 ')' => CloseParen,
631 '{' => OpenBrace,
632 '}' => CloseBrace,
633 '[' => OpenBracket,
634 ']' => CloseBracket,
635 '@' => At,
636 '#' => Pound,
637 '~' => Tilde,
638 '?' => Question,
639 ':' => Colon,
640 '$' => Dollar,
641 '=' => Eq,
642 '!' => Bang,
643 '<' => Lt,
644 '>' => Gt,
645 '-' => Minus,
646 '&' => And,
647 '|' => Or,
648 '+' => Plus,
649 '*' => Star,
650 '^' => Caret,
651 '%' => Percent,
652
653 '\'' => self.lifetime_or_char(),
655
656 '"' => {
658 let terminated = self.double_quoted_string();
659 let suffix_start = self.pos_within_token();
660 if terminated {
661 self.eat_literal_suffix();
662 }
663 let kind = Str { terminated };
664 Literal { kind, suffix_start }
665 }
666 c if is_emoji(c) => self.invalid_ident(),
668 _ => Unknown,
669 };
670 if #[allow(non_exhaustive_omitted_patterns)] match self.frontmatter_allowed {
FrontmatterAllowed::Yes => true,
_ => false,
}matches!(self.frontmatter_allowed, FrontmatterAllowed::Yes)
671 && !#[allow(non_exhaustive_omitted_patterns)] match token_kind {
Whitespace => true,
_ => false,
}matches!(token_kind, Whitespace)
672 {
673 self.frontmatter_allowed = FrontmatterAllowed::No;
675 }
676 let res = Token::new(token_kind, self.pos_within_token());
677 self.reset_pos_within_token();
678 res
679 }
680
681 fn frontmatter(&mut self, has_invalid_preceding_whitespace: bool) -> TokenKind {
683 if true {
{
match (&'-', &self.prev()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_eq!('-', self.prev());
684
685 let pos = self.pos_within_token();
686 self.eat_while(|c| c == '-');
687
688 let length_opening = self.pos_within_token() - pos + 1;
690
691 if true {
if !(length_opening >= 3) {
::core::panicking::panic("assertion failed: length_opening >= 3")
};
};debug_assert!(length_opening >= 3);
693
694 self.eat_while(|ch| ch != '\n' && is_horizontal_whitespace(ch));
696
697 if is_id_start(self.first()) {
700 self.bump();
701 self.eat_while(|c| is_id_continue(c) || c == '-' || c == '.');
702 }
703
704 self.eat_while(|ch| ch != '\n' && is_horizontal_whitespace(ch));
705 let invalid_infostring = self.first() != '\n';
706
707 let mut found = false;
708 let nl_fence_pattern = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\n{0:-<1$}", "",
length_opening as usize))
})format!("\n{:-<1$}", "", length_opening as usize);
709 if let Some(closing) = self.as_str().find(&nl_fence_pattern) {
710 self.bump_bytes(closing + nl_fence_pattern.len());
712 self.eat_until(b'\n');
720 found = true;
721 }
722
723 if !found {
724 let mut rest = self.as_str();
728 let mut potential_closing = rest
731 .find("\n---")
732 .map(|x| x + 1)
736 .or_else(|| rest.find("\nuse "))
737 .or_else(|| rest.find("\n//!"))
738 .or_else(|| rest.find("\n#!["));
739
740 if potential_closing.is_none() {
741 let mut base_index = 0;
744 while let Some(closing) = rest.find("---") {
745 let preceding_chars_start = rest[..closing].rfind("\n").map_or(0, |i| i + 1);
746 if rest[preceding_chars_start..closing].chars().all(is_horizontal_whitespace) {
747 potential_closing = Some(closing + base_index);
749 break;
750 } else {
751 rest = &rest[closing + 3..];
752 base_index += closing + 3;
753 }
754 }
755 }
756
757 if let Some(potential_closing) = potential_closing {
758 self.bump_bytes(potential_closing);
760 self.eat_until(b'\n');
761 } else {
762 self.eat_while(|_| true);
764 }
765 }
766
767 Frontmatter { has_invalid_preceding_whitespace, invalid_infostring }
768 }
769
770 fn line_comment(&mut self) -> TokenKind {
771 if true {
if !(self.prev() == '/' && self.first() == '/') {
::core::panicking::panic("assertion failed: self.prev() == \'/\' && self.first() == \'/\'")
};
};debug_assert!(self.prev() == '/' && self.first() == '/');
772 self.bump();
773
774 let doc_style = match self.first() {
775 '!' => Some(DocStyle::Inner),
777 '/' if self.second() != '/' => Some(DocStyle::Outer),
779 _ => None,
780 };
781
782 self.eat_until(b'\n');
783 LineComment { doc_style }
784 }
785
786 fn block_comment(&mut self) -> TokenKind {
787 if true {
if !(self.prev() == '/' && self.first() == '*') {
::core::panicking::panic("assertion failed: self.prev() == \'/\' && self.first() == \'*\'")
};
};debug_assert!(self.prev() == '/' && self.first() == '*');
788 self.bump();
789
790 let doc_style = match self.first() {
791 '!' => Some(DocStyle::Inner),
793 '*' if !#[allow(non_exhaustive_omitted_patterns)] match self.second() {
'*' | '/' => true,
_ => false,
}matches!(self.second(), '*' | '/') => Some(DocStyle::Outer),
796 _ => None,
797 };
798
799 let mut depth = 1usize;
800 while let Some(c) = self.bump() {
801 match c {
802 '/' if self.first() == '*' => {
803 self.bump();
804 depth += 1;
805 }
806 '*' if self.first() == '/' => {
807 self.bump();
808 depth -= 1;
809 if depth == 0 {
810 break;
814 }
815 }
816 _ => (),
817 }
818 }
819
820 BlockComment { doc_style, terminated: depth == 0 }
821 }
822
823 fn whitespace(&mut self) -> TokenKind {
824 if true {
if !is_whitespace(self.prev()) {
::core::panicking::panic("assertion failed: is_whitespace(self.prev())")
};
};debug_assert!(is_whitespace(self.prev()));
825 self.eat_while(is_whitespace);
826 Whitespace
827 }
828
829 fn ident_or_unknown_prefix(&mut self, already_invalid: bool) -> TokenKind {
830 if true {
if !(is_id_start(self.prev()) || already_invalid) {
::core::panicking::panic("assertion failed: is_id_start(self.prev()) || already_invalid")
};
};debug_assert!(is_id_start(self.prev()) || already_invalid);
831 self.eat_while(is_id_continue);
833 match self.first() {
836 '#' | '"' | '\'' => UnknownPrefix,
837 c if is_emoji(c) => self.invalid_ident(),
838 _ => Ident,
839 }
840 }
841
842 fn invalid_ident(&mut self) -> TokenKind {
843 self.eat_while(|c| is_id_continue(c) || is_emoji(c));
845 InvalidIdent
850 }
851
852 fn c_or_byte_string(
853 &mut self,
854 mk_kind: fn(bool) -> LiteralKind,
855 mk_kind_raw: fn(Option<u8>) -> LiteralKind,
856 single_quoted: Option<fn(bool) -> LiteralKind>,
857 ) -> TokenKind {
858 match (self.first(), self.second(), single_quoted) {
859 ('\'', _, Some(single_quoted)) => {
860 self.bump();
861 let terminated = self.single_quoted_string();
862 let suffix_start = self.pos_within_token();
863 if terminated {
864 self.eat_literal_suffix();
865 }
866 let kind = single_quoted(terminated);
867 Literal { kind, suffix_start }
868 }
869 ('"', _, _) => {
870 self.bump();
871 let terminated = self.double_quoted_string();
872 let suffix_start = self.pos_within_token();
873 if terminated {
874 self.eat_literal_suffix();
875 }
876 let kind = mk_kind(terminated);
877 Literal { kind, suffix_start }
878 }
879 ('r', '"', _) | ('r', '#', _) => {
880 self.bump();
881 let res = self.raw_double_quoted_string(2);
882 let suffix_start = self.pos_within_token();
883 if res.is_ok() {
884 self.eat_literal_suffix();
885 }
886 let kind = mk_kind_raw(res.ok());
887 Literal { kind, suffix_start }
888 }
889 _ => self.ident_or_unknown_prefix(false),
890 }
891 }
892
893 fn number(&mut self, first_digit: char) -> LiteralKind {
894 if true {
if !('0' <= self.prev() && self.prev() <= '9') {
::core::panicking::panic("assertion failed: \'0\' <= self.prev() && self.prev() <= \'9\'")
};
};debug_assert!('0' <= self.prev() && self.prev() <= '9');
895 let mut base = Base::Decimal;
896 if first_digit == '0' {
897 match self.first() {
899 'b' => {
900 base = Base::Binary;
901 self.bump();
902 if !self.eat_decimal_digits() {
903 return Int { base, empty_int: true };
904 }
905 }
906 'o' => {
907 base = Base::Octal;
908 self.bump();
909 if !self.eat_decimal_digits() {
910 return Int { base, empty_int: true };
911 }
912 }
913 'x' => {
914 base = Base::Hexadecimal;
915 self.bump();
916 if !self.eat_hexadecimal_digits() {
917 return Int { base, empty_int: true };
918 }
919 }
920 '0'..='9' | '_' => {
922 self.eat_decimal_digits();
923 }
924
925 '.' | 'e' | 'E' => {}
927
928 _ => return Int { base, empty_int: false },
930 }
931 } else {
932 self.eat_decimal_digits();
934 }
935
936 match self.first() {
937 '.' if self.second() != '.' && !is_id_start(self.second()) => {
941 self.bump();
944 let mut empty_exponent = false;
945 if self.first().is_ascii_digit() {
946 self.eat_decimal_digits();
947 match self.first() {
948 'e' | 'E' => {
949 self.bump();
950 empty_exponent = !self.eat_float_exponent();
951 }
952 _ => (),
953 }
954 }
955 Float { base, empty_exponent }
956 }
957 'e' | 'E' => {
958 self.bump();
959 let empty_exponent = !self.eat_float_exponent();
960 Float { base, empty_exponent }
961 }
962 _ => Int { base, empty_int: false },
963 }
964 }
965
966 fn lifetime_or_char(&mut self) -> TokenKind {
967 if true {
if !(self.prev() == '\'') {
::core::panicking::panic("assertion failed: self.prev() == \'\\\'\'")
};
};debug_assert!(self.prev() == '\'');
968
969 let mut invalid = false;
970 let can_be_a_lifetime = if self.second() == '\'' {
971 false
973 } else {
974 let c = self.first();
978 invalid |= c.is_ascii_digit();
979 invalid |= is_emoji(c);
980 is_id_start(c) || invalid
981 };
982
983 if !can_be_a_lifetime {
984 let terminated = self.single_quoted_string();
985 let suffix_start = self.pos_within_token();
986 if terminated {
987 self.eat_literal_suffix();
988 }
989 let kind = Char { terminated };
990 return Literal { kind, suffix_start };
991 }
992
993 if self.first() == 'r' && self.second() == '#' && is_id_start(self.third()) {
994 self.bump();
996 self.bump();
997 self.bump();
998 self.eat_while(is_id_continue);
999 return RawLifetime;
1000 }
1001
1002 let starts_with_number = self.first().is_ascii_digit();
1005
1006 self.bump();
1010 invalid |= #[allow(non_exhaustive_omitted_patterns)] match self.ident_or_unknown_prefix(invalid)
{
InvalidIdent => true,
_ => false,
}matches!(self.ident_or_unknown_prefix(invalid), InvalidIdent);
1011
1012 match self.first() {
1013 '\'' => {
1017 self.bump();
1018 let kind = Char { terminated: true };
1019 Literal { kind, suffix_start: self.pos_within_token() }
1020 }
1021 '#' if !starts_with_number => UnknownPrefixLifetime,
1022 _ => Lifetime { starts_with_number: invalid },
1023 }
1024 }
1025
1026 fn single_quoted_string(&mut self) -> bool {
1027 if true {
if !(self.prev() == '\'') {
::core::panicking::panic("assertion failed: self.prev() == \'\\\'\'")
};
};debug_assert!(self.prev() == '\'');
1028 if self.second() == '\'' && self.first() != '\\' {
1030 self.bump();
1031 self.bump();
1032 return true;
1033 }
1034
1035 loop {
1039 match self.first() {
1040 '\'' => {
1042 self.bump();
1043 return true;
1044 }
1045 '/' => break,
1048 '\n' if self.second() != '\'' => break,
1050 EOF_CHAR if self.is_eof() => break,
1052 '\\' => {
1054 self.bump();
1055 self.bump();
1056 }
1057 _ => {
1059 self.bump();
1060 }
1061 }
1062 }
1063 false
1065 }
1066
1067 fn double_quoted_string(&mut self) -> bool {
1070 if true {
if !(self.prev() == '"') {
::core::panicking::panic("assertion failed: self.prev() == \'\"\'")
};
};debug_assert!(self.prev() == '"');
1071 while let Some(c) = self.bump() {
1072 match c {
1073 '"' => {
1074 return true;
1075 }
1076 '\\' if self.first() == '\\' || self.first() == '"' => {
1077 self.bump();
1079 }
1080 _ => (),
1081 }
1082 }
1083 false
1085 }
1086
1087 pub fn guarded_double_quoted_string(&mut self) -> Option<GuardedStr> {
1096 if true {
if !(self.prev() != '#') {
::core::panicking::panic("assertion failed: self.prev() != \'#\'")
};
};debug_assert!(self.prev() != '#');
1097
1098 let mut n_start_hashes: u32 = 0;
1099 while self.first() == '#' {
1100 n_start_hashes += 1;
1101 self.bump();
1102 }
1103
1104 if self.first() != '"' {
1105 return None;
1106 }
1107 self.bump();
1108 if true {
if !(self.prev() == '"') {
::core::panicking::panic("assertion failed: self.prev() == \'\"\'")
};
};debug_assert!(self.prev() == '"');
1109
1110 let terminated = self.double_quoted_string();
1113 if !terminated {
1114 let token_len = self.pos_within_token();
1115 self.reset_pos_within_token();
1116
1117 return Some(GuardedStr { n_hashes: n_start_hashes, terminated: false, token_len });
1118 }
1119
1120 let mut n_end_hashes = 0;
1125 while self.first() == '#' && n_end_hashes < n_start_hashes {
1126 n_end_hashes += 1;
1127 self.bump();
1128 }
1129
1130 self.eat_literal_suffix();
1134
1135 let token_len = self.pos_within_token();
1136 self.reset_pos_within_token();
1137
1138 Some(GuardedStr { n_hashes: n_start_hashes, terminated: true, token_len })
1139 }
1140
1141 fn raw_double_quoted_string(&mut self, prefix_len: u32) -> Result<u8, RawStrError> {
1143 let n_hashes = self.raw_string_unvalidated(prefix_len)?;
1146 match u8::try_from(n_hashes) {
1148 Ok(num) => Ok(num),
1149 Err(_) => Err(RawStrError::TooManyDelimiters { found: n_hashes }),
1150 }
1151 }
1152
1153 fn raw_string_unvalidated(&mut self, prefix_len: u32) -> Result<u32, RawStrError> {
1154 if true {
if !(self.prev() == 'r') {
::core::panicking::panic("assertion failed: self.prev() == \'r\'")
};
};debug_assert!(self.prev() == 'r');
1155 let start_pos = self.pos_within_token();
1156 let mut possible_terminator_offset = None;
1157 let mut max_hashes = 0;
1158
1159 let mut eaten = 0;
1161 while self.first() == '#' {
1162 eaten += 1;
1163 self.bump();
1164 }
1165 let n_start_hashes = eaten;
1166
1167 match self.bump() {
1169 Some('"') => (),
1170 c => {
1171 let c = c.unwrap_or(EOF_CHAR);
1172 return Err(RawStrError::InvalidStarter { bad_char: c });
1173 }
1174 }
1175
1176 loop {
1179 self.eat_until(b'"');
1180
1181 if self.is_eof() {
1182 return Err(RawStrError::NoTerminator {
1183 expected: n_start_hashes,
1184 found: max_hashes,
1185 possible_terminator_offset,
1186 });
1187 }
1188
1189 self.bump();
1191
1192 let mut n_end_hashes = 0;
1198 while self.first() == '#' && n_end_hashes < n_start_hashes {
1199 n_end_hashes += 1;
1200 self.bump();
1201 }
1202
1203 if n_end_hashes == n_start_hashes {
1204 return Ok(n_start_hashes);
1205 } else if n_end_hashes > max_hashes {
1206 possible_terminator_offset =
1209 Some(self.pos_within_token() - start_pos - n_end_hashes + prefix_len);
1210 max_hashes = n_end_hashes;
1211 }
1212 }
1213 }
1214
1215 fn eat_decimal_digits(&mut self) -> bool {
1216 let mut has_digits = false;
1217 loop {
1218 match self.first() {
1219 '_' => {
1220 self.bump();
1221 }
1222 '0'..='9' => {
1223 has_digits = true;
1224 self.bump();
1225 }
1226 _ => break,
1227 }
1228 }
1229 has_digits
1230 }
1231
1232 fn eat_hexadecimal_digits(&mut self) -> bool {
1233 let mut has_digits = false;
1234 loop {
1235 match self.first() {
1236 '_' => {
1237 self.bump();
1238 }
1239 '0'..='9' | 'a'..='f' | 'A'..='F' => {
1240 has_digits = true;
1241 self.bump();
1242 }
1243 _ => break,
1244 }
1245 }
1246 has_digits
1247 }
1248
1249 fn eat_float_exponent(&mut self) -> bool {
1252 if true {
if !(self.prev() == 'e' || self.prev() == 'E') {
::core::panicking::panic("assertion failed: self.prev() == \'e\' || self.prev() == \'E\'")
};
};debug_assert!(self.prev() == 'e' || self.prev() == 'E');
1253 if self.first() == '-' || self.first() == '+' {
1254 self.bump();
1255 }
1256 self.eat_decimal_digits()
1257 }
1258
1259 fn eat_literal_suffix(&mut self) {
1261 self.eat_identifier();
1262 }
1263
1264 fn eat_identifier(&mut self) {
1267 if !is_id_start(self.first()) {
1268 return;
1269 }
1270 self.bump();
1271
1272 self.eat_while(is_id_continue);
1273 }
1274}
1275
1276fn is_emoji(c: char) -> bool {
1277 !c.is_ascii() && c.is_emoji_char()
1278}