mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Improve TokenKind
comments.
- Improve wording. - Use backticks consistently for examples.
This commit is contained in:
parent
df29f9b0c3
commit
2c7c3697db
@ -57,11 +57,10 @@ impl Token {
|
|||||||
/// Enum representing common lexeme types.
|
/// Enum representing common lexeme types.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum TokenKind {
|
pub enum TokenKind {
|
||||||
// Multi-char tokens:
|
/// A line comment, e.g. `// comment`.
|
||||||
/// "// comment"
|
|
||||||
LineComment { doc_style: Option<DocStyle> },
|
LineComment { doc_style: Option<DocStyle> },
|
||||||
|
|
||||||
/// `/* block comment */`
|
/// A block comment, e.g. `/* block comment */`.
|
||||||
///
|
///
|
||||||
/// Block comments can be recursive, so a sequence like `/* /* */`
|
/// Block comments can be recursive, so a sequence like `/* /* */`
|
||||||
/// will not be considered terminated and will result in a parsing error.
|
/// will not be considered terminated and will result in a parsing error.
|
||||||
@ -70,18 +69,17 @@ pub enum TokenKind {
|
|||||||
/// Any whitespace character sequence.
|
/// Any whitespace character sequence.
|
||||||
Whitespace,
|
Whitespace,
|
||||||
|
|
||||||
/// "ident" or "continue"
|
/// An identifier or keyword, e.g. `ident` or `continue`.
|
||||||
///
|
|
||||||
/// At this step, keywords are also considered identifiers.
|
|
||||||
Ident,
|
Ident,
|
||||||
|
|
||||||
/// Like the above, but containing invalid unicode codepoints.
|
/// An identifier that is invalid because it contains emoji.
|
||||||
InvalidIdent,
|
InvalidIdent,
|
||||||
|
|
||||||
/// "r#ident"
|
/// A raw identifier, e.g. "r#ident".
|
||||||
RawIdent,
|
RawIdent,
|
||||||
|
|
||||||
/// An unknown prefix, like `foo#`, `foo'`, `foo"`.
|
/// An unknown literal prefix, like `foo#`, `foo'`, `foo"`. Excludes
|
||||||
|
/// literal prefixes that contain emoji, which are considered "invalid".
|
||||||
///
|
///
|
||||||
/// Note that only the
|
/// Note that only the
|
||||||
/// prefix (`foo`) is included in the token, not the separator (which is
|
/// prefix (`foo`) is included in the token, not the separator (which is
|
||||||
@ -93,11 +91,12 @@ pub enum TokenKind {
|
|||||||
|
|
||||||
/// An unknown prefix in a lifetime, like `'foo#`.
|
/// An unknown prefix in a lifetime, like `'foo#`.
|
||||||
///
|
///
|
||||||
/// Note that like above, only the `'` and prefix are included in the token
|
/// Like `UnknownPrefix`, only the `'` and prefix are included in the token
|
||||||
/// and not the separator.
|
/// and not the separator.
|
||||||
UnknownPrefixLifetime,
|
UnknownPrefixLifetime,
|
||||||
|
|
||||||
/// `'r#lt`, which in edition < 2021 is split into several tokens: `'r # lt`.
|
/// A raw lifetime, e.g. `'r#foo`. In edition < 2021 it will be split into
|
||||||
|
/// several tokens: `'r` and `#` and `foo`.
|
||||||
RawLifetime,
|
RawLifetime,
|
||||||
|
|
||||||
/// Similar to the above, but *always* an error on every edition. This is used
|
/// Similar to the above, but *always* an error on every edition. This is used
|
||||||
@ -110,70 +109,69 @@ pub enum TokenKind {
|
|||||||
/// Split into the component tokens on older editions.
|
/// Split into the component tokens on older editions.
|
||||||
GuardedStrPrefix,
|
GuardedStrPrefix,
|
||||||
|
|
||||||
/// Examples: `12u8`, `1.0e-40`, `b"123"`. Note that `_` is an invalid
|
/// Literals, e.g. `12u8`, `1.0e-40`, `b"123"`. Note that `_` is an invalid
|
||||||
/// suffix, but may be present here on string and float literals. Users of
|
/// suffix, but may be present here on string and float literals. Users of
|
||||||
/// this type will need to check for and reject that case.
|
/// this type will need to check for and reject that case.
|
||||||
///
|
///
|
||||||
/// See [LiteralKind] for more details.
|
/// See [LiteralKind] for more details.
|
||||||
Literal { kind: LiteralKind, suffix_start: u32 },
|
Literal { kind: LiteralKind, suffix_start: u32 },
|
||||||
|
|
||||||
/// "'a"
|
/// A lifetime, e.g. `'a`.
|
||||||
Lifetime { starts_with_number: bool },
|
Lifetime { starts_with_number: bool },
|
||||||
|
|
||||||
// One-char tokens:
|
/// `;`
|
||||||
/// ";"
|
|
||||||
Semi,
|
Semi,
|
||||||
/// ","
|
/// `,`
|
||||||
Comma,
|
Comma,
|
||||||
/// "."
|
/// `.`
|
||||||
Dot,
|
Dot,
|
||||||
/// "("
|
/// `(`
|
||||||
OpenParen,
|
OpenParen,
|
||||||
/// ")"
|
/// `)`
|
||||||
CloseParen,
|
CloseParen,
|
||||||
/// "{"
|
/// `{`
|
||||||
OpenBrace,
|
OpenBrace,
|
||||||
/// "}"
|
/// `}`
|
||||||
CloseBrace,
|
CloseBrace,
|
||||||
/// "["
|
/// `[`
|
||||||
OpenBracket,
|
OpenBracket,
|
||||||
/// "]"
|
/// `]`
|
||||||
CloseBracket,
|
CloseBracket,
|
||||||
/// "@"
|
/// `@`
|
||||||
At,
|
At,
|
||||||
/// "#"
|
/// `#`
|
||||||
Pound,
|
Pound,
|
||||||
/// "~"
|
/// `~`
|
||||||
Tilde,
|
Tilde,
|
||||||
/// "?"
|
/// `?`
|
||||||
Question,
|
Question,
|
||||||
/// ":"
|
/// `:`
|
||||||
Colon,
|
Colon,
|
||||||
/// "$"
|
/// `$`
|
||||||
Dollar,
|
Dollar,
|
||||||
/// "="
|
/// `=`
|
||||||
Eq,
|
Eq,
|
||||||
/// "!"
|
/// `!`
|
||||||
Bang,
|
Bang,
|
||||||
/// "<"
|
/// `<`
|
||||||
Lt,
|
Lt,
|
||||||
/// ">"
|
/// `>`
|
||||||
Gt,
|
Gt,
|
||||||
/// "-"
|
/// `-`
|
||||||
Minus,
|
Minus,
|
||||||
/// "&"
|
/// `&`
|
||||||
And,
|
And,
|
||||||
/// "|"
|
/// `|`
|
||||||
Or,
|
Or,
|
||||||
/// "+"
|
/// `+`
|
||||||
Plus,
|
Plus,
|
||||||
/// "*"
|
/// `*`
|
||||||
Star,
|
Star,
|
||||||
/// "/"
|
/// `/`
|
||||||
Slash,
|
Slash,
|
||||||
/// "^"
|
/// `^`
|
||||||
Caret,
|
Caret,
|
||||||
/// "%"
|
/// `%`
|
||||||
Percent,
|
Percent,
|
||||||
|
|
||||||
/// Unknown token, not expected by the lexer, e.g. "№"
|
/// Unknown token, not expected by the lexer, e.g. "№"
|
||||||
|
Loading…
Reference in New Issue
Block a user