|
|
|
@ -240,6 +240,8 @@ pub enum TokenKind {
|
|
|
|
|
/// A string literal.
|
|
|
|
|
StringLiteral(Box<str>), |
|
|
|
|
|
|
|
|
|
TemplateLiteral(Box<str>), |
|
|
|
|
|
|
|
|
|
/// A regular expression, consisting of body and flags.
|
|
|
|
|
RegularExpressionLiteral(Box<str>, RegExpFlags), |
|
|
|
|
|
|
|
|
@ -310,6 +312,14 @@ impl TokenKind {
|
|
|
|
|
Self::StringLiteral(lit.into()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Creates a `TemplateLiteral` token type.
|
|
|
|
|
pub fn template_literal<S>(lit: S) -> Self |
|
|
|
|
where |
|
|
|
|
S: Into<Box<str>>, |
|
|
|
|
{ |
|
|
|
|
Self::TemplateLiteral(lit.into()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Creates a `RegularExpressionLiteral` token kind.
|
|
|
|
|
pub fn regular_expression_literal<B>(body: B, flags: RegExpFlags) -> Self |
|
|
|
|
where |
|
|
|
@ -337,6 +347,7 @@ impl Display for TokenKind {
|
|
|
|
|
Self::NumericLiteral(NumericLiteral::BigInt(ref num)) => write!(f, "{}n", num), |
|
|
|
|
Self::Punctuator(ref punc) => write!(f, "{}", punc), |
|
|
|
|
Self::StringLiteral(ref lit) => write!(f, "{}", lit), |
|
|
|
|
Self::TemplateLiteral(ref lit) => write!(f, "{}", lit), |
|
|
|
|
Self::RegularExpressionLiteral(ref body, ref flags) => write!(f, "/{}/{}", body, flags), |
|
|
|
|
Self::LineTerminator => write!(f, "line terminator"), |
|
|
|
|
} |
|
|
|
|