|
|
@ -95,7 +95,7 @@ impl From<BigInt> for Numeric { |
|
|
|
#[derive(Clone, PartialEq, Debug)] |
|
|
|
#[derive(Clone, PartialEq, Debug)] |
|
|
|
pub enum TokenKind { |
|
|
|
pub enum TokenKind { |
|
|
|
/// A boolean literal, which is either `true` or `false`.
|
|
|
|
/// A boolean literal, which is either `true` or `false`.
|
|
|
|
BooleanLiteral(bool), |
|
|
|
BooleanLiteral((bool, ContainsEscapeSequence)), |
|
|
|
|
|
|
|
|
|
|
|
/// The end of the file.
|
|
|
|
/// The end of the file.
|
|
|
|
EOF, |
|
|
|
EOF, |
|
|
@ -118,7 +118,7 @@ pub enum TokenKind { |
|
|
|
/// The [`null` literal][spec].
|
|
|
|
/// The [`null` literal][spec].
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#prod-NullLiteral
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#prod-NullLiteral
|
|
|
|
NullLiteral, |
|
|
|
NullLiteral(ContainsEscapeSequence), |
|
|
|
|
|
|
|
|
|
|
|
/// A numeric literal.
|
|
|
|
/// A numeric literal.
|
|
|
|
NumericLiteral(Numeric), |
|
|
|
NumericLiteral(Numeric), |
|
|
@ -152,7 +152,7 @@ pub enum TokenKind { |
|
|
|
impl From<bool> for TokenKind { |
|
|
|
impl From<bool> for TokenKind { |
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
fn from(oth: bool) -> Self { |
|
|
|
fn from(oth: bool) -> Self { |
|
|
|
Self::BooleanLiteral(oth) |
|
|
|
Self::BooleanLiteral((oth, ContainsEscapeSequence(false))) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -182,7 +182,7 @@ impl TokenKind { |
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
#[must_use] |
|
|
|
#[must_use] |
|
|
|
pub const fn boolean_literal(lit: bool) -> Self { |
|
|
|
pub const fn boolean_literal(lit: bool) -> Self { |
|
|
|
Self::BooleanLiteral(lit) |
|
|
|
Self::BooleanLiteral((lit, ContainsEscapeSequence(false))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Creates an `EOF` token kind.
|
|
|
|
/// Creates an `EOF` token kind.
|
|
|
@ -261,12 +261,12 @@ impl TokenKind { |
|
|
|
#[must_use] |
|
|
|
#[must_use] |
|
|
|
pub fn to_string(&self, interner: &Interner) -> String { |
|
|
|
pub fn to_string(&self, interner: &Interner) -> String { |
|
|
|
match *self { |
|
|
|
match *self { |
|
|
|
Self::BooleanLiteral(val) => val.to_string(), |
|
|
|
Self::BooleanLiteral((val, _)) => val.to_string(), |
|
|
|
Self::EOF => "end of file".to_owned(), |
|
|
|
Self::EOF => "end of file".to_owned(), |
|
|
|
Self::IdentifierName((ident, _)) => interner.resolve_expect(ident).to_string(), |
|
|
|
Self::IdentifierName((ident, _)) => interner.resolve_expect(ident).to_string(), |
|
|
|
Self::PrivateIdentifier(ident) => format!("#{}", interner.resolve_expect(ident)), |
|
|
|
Self::PrivateIdentifier(ident) => format!("#{}", interner.resolve_expect(ident)), |
|
|
|
Self::Keyword((word, _)) => word.to_string(), |
|
|
|
Self::Keyword((word, _)) => word.to_string(), |
|
|
|
Self::NullLiteral => "null".to_owned(), |
|
|
|
Self::NullLiteral(_) => "null".to_owned(), |
|
|
|
Self::NumericLiteral(Numeric::Rational(num)) => num.to_string(), |
|
|
|
Self::NumericLiteral(Numeric::Rational(num)) => num.to_string(), |
|
|
|
Self::NumericLiteral(Numeric::Integer(num)) => num.to_string(), |
|
|
|
Self::NumericLiteral(Numeric::Integer(num)) => num.to_string(), |
|
|
|
Self::NumericLiteral(Numeric::BigInt(ref num)) => format!("{num}n"), |
|
|
|
Self::NumericLiteral(Numeric::BigInt(ref num)) => format!("{num}n"), |
|
|
|