about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/lexer/mod.rs
AgeCommit message (Collapse)AuthorLines
2023-02-28refactor parse_token_trees to not return unmatched_delimsyukang-3/+26
2023-02-28rename unmatched_braces to unmatched_delimsyukang-2/+2
2023-02-14Don't recover lifetimes/labels containing emojis as character literals许杰友 Jieyou Xu (Joe)-2/+7
Note that at the time of this commit, `unic-emoji-char` seems to have data tables only up to Unicode 5.0, but Unicode is already newer than this. A newer emoji such as `🥺` will not be recognized as an emoji but older emojis such as `🐱` will.
2023-02-06Migrate `rustc_parse` to derive diagnosticsclubby789-112/+47
2023-01-27Improve unexpected close and mismatch delimiter hint in TokenTreesReaderyukang-0/+1
2023-01-14Emit only one nbsp error per fileDavid Tolnay-5/+26
2023-01-12Emit a single error for contiguous sequences of Unicode homoglyphsclubby789-4/+24
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-1/+12
Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. This commit changes the language very slightly. Some programs that used to not compile now will compile. This is because some invalid literals that are removed by `cfg` or attribute macros will no longer trigger errors. See this comment for more details: https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
2022-11-09Rollup merge of #103919 - nnethercote:unescaping-cleanups, r=matkladDylan DPC-59/+48
Unescaping cleanups Some code improvements, and some error message improvements. Best reviewed one commit at a time. r? ````@matklad````
2022-11-07Make underscore_literal_suffix a hard error.Nicholas Nethercote-11/+1
It's been a warning for 5.5 years. Time to make it a hard error. Closes #42326.
2022-11-04Inline and remove `validate_int_literal`.Nicholas Nethercote-18/+13
It has a single callsite, and is fairly small. The `Float` match arm already has base-specific checking inline, so this makes things more consistent.
2022-11-04Refactor `cook_lexer_literal`.Nicholas Nethercote-42/+36
It deals with eight cases: ints, floats, and the six quoted types (char/byte/strings). For ints and floats we have an early return, and the other six types fall through to the code at the end, which makes the function hard to read. This commit rearranges things to avoid the early returns.
2022-10-22Recover unclosed char literal being parsed as lifetimeMichael Goulet-2/+7
2022-10-03Merge `parse_token_trees_until_close_delim` and `parse_all_token_trees`.Nicholas Nethercote-1/+1
Because they're very similar, and this will allow some follow-up changes.
2022-09-28Address review comments.Nicholas Nethercote-1/+1
2022-09-26Inline and remove `cook_lexer_token`.Nicholas Nethercote-171/+174
This is a small performance win, alas.
2022-09-26Add `rustc_lexer::TokenKind::Eof`.Nicholas Nethercote-8/+2
For alignment with `rust_ast::TokenKind::Eof`. Plus it's a bit faster, due to less `Option` manipulation in `StringReader::next_token`.
2022-09-26Use less DRY in `cook_lexer_token`.Nicholas Nethercote-19/+19
This is a case where a small amount of repetition results in code that is faster and easier to read.
2022-09-26Make `rustc_lexer::cursor::Cursor` public.Nicholas Nethercote-10/+13
`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-09-26[ui] Rearrange `StringReader`/`TokenTreesReader` creation.Nicholas Nethercote-1/+2
`TokenTreesReader` wraps a `StringReader`, but the `into_token_trees` function obscures this. This commit moves to a more straightforward control flow.
2022-09-26Clarify spacing computation.Nicholas Nethercote-7/+8
The spacing computation is done in two parts. In the first part `next_token` and `bump` use `Spacing::Alone` to mean "preceded by whitespace" and `Spacing::Joint` to mean the opposite. In the second part `parse_token_tree_other` then adjusts the `spacing` value to mean the usual thing (i.e. "is the following token joinable punctuation?"). This shift in meaning is very confusing and it took me some time to understand what was going on. This commit changes the first part to use a bool, and adds some comments, which makes things much clearer.
2022-09-26Move `#!` checking.Nicholas Nethercote-9/+8
Currently does the "is this a `#!` at the start of the file?" check for every single token(!) This commit moves it so it only happens once.
2022-09-26Remove unnecessary `spacing` assignment.Nicholas Nethercote-1/+0
It has no useful effect.
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-2/+0
by module
2022-08-01Shrink `Token`.Nicholas Nethercote-23/+29
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.
2022-08-01Add a size assertion for `Token`.Nicholas Nethercote-0/+7
2022-08-01Remove `StringReader::end_src_index`.Nicholas Nethercote-5/+2
It not needed, always being set to the end of the text.
2022-08-01Improve shebang handling.Nicholas Nethercote-8/+5
Avoid doing stuff until it's necessary.
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-1/+1
2022-04-29errors: `span_suggestion` takes `impl ToString`David Wood-2/+2
Change `span_suggestion` (and variants) to take `impl ToString` rather than `String` for the suggested code, as this simplifies the requirements on the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-9/+9
2022-04-16Rollup merge of #95859 - rainy-me:unterminated-nested-block-comment, ↵Dylan DPC-10/+50
r=petrochenkov Improve diagnostics for unterminated nested block comment close #95283 (This is my first time try to messing around with rust compiler and might get a lot of things wrong... :bow: )
2022-04-14refactor: change to use peekablerainy-me-20/+17
2022-04-13couple of clippy::complexity fixesMatthias Krüger-3/+3
2022-04-14improve diagnostics for unterminated nested block commentrainy-me-10/+53
2022-03-31Rollup merge of #95251 - GrishaVar:hashes-u16-to-u8, r=dtolnayDylan DPC-3/+1
Reduce max hash in raw strings from u16 to u8 [Relevant discussion](https://rust-lang.zulipchat.com/#narrow/stream/237824-t-lang.2Fdoc/topic/Max.20raw.20string.20delimiters)
2022-03-30Update error message & remove outdated test commentGrisha Vartanyan-3/+1
2022-03-27Make fatal DiagnosticBuilder yield neverMichael Goulet-12/+19
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-2/+2
2022-02-23rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".Eduard-Mihai Burtescu-2/+4
2022-02-16Adopt let_else in even more placesest31-6/+2
2021-11-23review comment: plural of emoji is emojiEsteban Kuber-1/+1
2021-11-23Account for confusable codepoints when recovering emoji identifiersEsteban Kuber-2/+13
2021-11-23Tokenize emoji as if they were valid indentifiersEsteban Kuber-0/+6
In the lexer, consider emojis to be valid identifiers and reject them later to avoid knock down parse errors.
2021-11-04Optimize literal, doc comment lint as well, extract function.Hans Kratz-39/+2
2021-11-04Create subslice as that leads to a smaller code size.Hans Kratz-3/+4
2021-11-04Optimize bidi character detection.Hans Kratz-6/+39
2021-11-01fix formattingPietro Albini-1/+1
2021-10-31Lint against RTL unicode codepoints in literals and commentsEsteban Küber-3/+37
Address CVE-2021-42574.
2021-07-31Suggest `br` if the unknown string prefix `rb` is foundFabian Wolff-3/+11