about summary refs log tree commit diff
path: root/compiler/rustc_lexer/src/cursor.rs
AgeCommit message (Collapse)AuthorLines
2025-06-06rustc_lexer: typo fix + small cleanupsMarijn Schouten-1/+1
2025-05-05Implement RFC 3503: frontmattersDeadbeef-1/+13
Supercedes #137193
2025-02-05implement `eat_until` leveraging memchr in lexergvozdvmozgu-0/+7
2024-03-17Silence redundant error on char literal that was meant to be a string in ↵Esteban Küber-0/+9
2021 edition
2024-03-17Handle str literals written with `'` lexed as lifetimeEsteban Küber-1/+1
Given `'hello world'` and `'1 str', provide a structured suggestion for a valid string literal: ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-3.rs:2:26 | LL | println!('hello world'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("hello world"); | ~ ~ ``` ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-1.rs:2:20 | LL | println!('1 + 1'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("1 + 1"); | ~ ~ ``` Fix #119685.
2023-07-23reimplement C string literalsDeadbeef-0/+4
2022-09-26Rename some things.Nicholas Nethercote-6/+6
`Cursor` keeps track of the position within the current token. But it uses confusing names that don't make it clear that the "length consumed" is just within the current token. This commit renames things to make this clearer.
2022-09-26Make `rustc_lexer::cursor::Cursor` public.Nicholas Nethercote-2/+2
`Cursor` is currently hidden, and the main tokenization path uses `rustc_lexer::first_token` which involves constructing a new `Cursor` for every single token, which is weird. Also, `first_token` also can't handle empty input, so callers have to check for that first. This commit makes `Cursor` public, so `StringReader` can contain a `Cursor`, which results in a simpler structure. The commit also changes `StringReader::advance_token` so it returns an `Option<Token>`, simplifying the the empty input case.
2022-08-01Shrink `Token`.Nicholas Nethercote-2/+2
From 72 bytes to 12 bytes (on x86-64). There are two parts to this: - Changing various source code offsets from 64-bit to 32-bit. This is not a problem because the rest of rustc also uses 32-bit source code offsets. This means `Token` is no longer `Copy` but this causes no problems. - Removing the `RawStrError` from `LiteralKind`. Raw string literal invalidity is now indicated by a `None` value within `RawStr`/`RawByteStr`, and the new `validate_raw_str` function can be used to re-lex an invalid raw string literal to get the `RawStrError`. There is one very small change in behaviour. Previously, if a raw string literal matched both the `InvalidStarter` and `TooManyHashes` cases, the latter would override the former. This has now changed, because `raw_double_quoted_string` now uses `?` and so returns immediately upon detecting the `InvalidStarter` case. I think this is a slight improvement to report the earlier-detected error, and it explains the change in the `test_too_many_hashes` test. The commit also removes a couple of comments that refer to #77629 and say that the size of these types don't affect performance. These comments are wrong, though the performance effect is small.
2021-12-01Replace `nth_char(0)` with `next()` in `cursor.first()`Julian Wollersberger-12/+21
and optimize the iterator returned by `tokenize(). This improves lexer performance by 35%
2021-01-07Return EOF_CHAR constant instead of magic char.Hanzhen Liang-1/+1
2020-08-30mv compiler to compiler/mark-0/+84