Skip to content

Commit 81550a0

Browse files
authored
Rollup merge of rust-lang#66015 - popzxc:refactor-librustc_parser, r=matklad
librustc_lexer: Refactor the module This PR introduces a refactoring of the `librustc_lexer` in order to improve readability. All the changes performed are only cosmetic and do not introduce any changes the lexer logic or performance. Newly introduced modules `literal`, `token` and `utils` are just copy-pasted from the `lib.rs` and do not contain even cosmetic changes (I decided to do so so it'll be easier to review changes looking only on diff). r? @petrochenkov cc @Centril @matklad
2 parents 24af0c9 + 31735b0 commit 81550a0

File tree

2 files changed

+159
-122
lines changed

2 files changed

+159
-122
lines changed

src/librustc_lexer/src/cursor.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,20 @@ impl<'a> Cursor<'a> {
4141
/// If requested position doesn't exist, `EOF_CHAR` is returned.
4242
/// However, getting `EOF_CHAR` doesn't always mean actual end of file,
4343
/// it should be checked with `is_eof` method.
44-
pub(crate) fn nth_char(&self, n: usize) -> char {
44+
fn nth_char(&self, n: usize) -> char {
4545
self.chars().nth(n).unwrap_or(EOF_CHAR)
4646
}
4747

48+
/// Peeks the next symbol from the input stream without consuming it.
49+
pub(crate) fn first(&self) -> char {
50+
self.nth_char(0)
51+
}
52+
53+
/// Peeks the second symbol from the input stream without consuming it.
54+
pub(crate) fn second(&self) -> char {
55+
self.nth_char(1)
56+
}
57+
4858
/// Checks if there is nothing more to consume.
4959
pub(crate) fn is_eof(&self) -> bool {
5060
self.chars.as_str().is_empty()

0 commit comments

Comments
 (0)