SyntaxKind::Eof => SyntaxKind::End to better express its usage (#3872)

This commit is contained in:
Leedehai 2024-04-08 06:21:06 -04:00 committed by GitHub
parent 33d620ed2e
commit 9289d9334b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 31 deletions

View File

@ -288,7 +288,7 @@ pub fn highlight(node: &LinkedNode) -> Option<Tag> {
SyntaxKind::LineComment => Some(Tag::Comment),
SyntaxKind::BlockComment => Some(Tag::Comment),
SyntaxKind::Error => Some(Tag::Error),
SyntaxKind::Eof => None,
SyntaxKind::End => None,
}
}

View File

@ -273,8 +273,8 @@ pub enum SyntaxKind {
BlockComment,
/// An invalid sequence of characters.
Error,
/// The end of the file.
Eof,
/// The end of token stream.
End,
}
impl SyntaxKind {
@ -295,7 +295,7 @@ impl SyntaxKind {
pub fn is_terminator(self) -> bool {
matches!(
self,
Self::Eof
Self::End
| Self::Semicolon
| Self::RightBrace
| Self::RightParen
@ -493,7 +493,7 @@ impl SyntaxKind {
Self::LineComment => "line comment",
Self::BlockComment => "block comment",
Self::Error => "syntax error",
Self::Eof => "end of file",
Self::End => "end of tokens",
}
}
}

View File

@ -95,7 +95,7 @@ impl Lexer<'_> {
pub fn next(&mut self) -> SyntaxKind {
if self.mode == LexMode::Raw {
let Some((kind, end)) = self.raw.pop() else {
return SyntaxKind::Eof;
return SyntaxKind::End;
};
self.s.jump(end);
return kind;
@ -119,7 +119,7 @@ impl Lexer<'_> {
LexMode::Raw => unreachable!(),
},
None => SyntaxKind::Eof,
None => SyntaxKind::End,
}
}

View File

@ -303,7 +303,7 @@ impl SyntaxNode {
/// In contrast to `default()`, this is a const fn.
pub(super) const fn arbitrary() -> Self {
Self(Repr::Leaf(LeafNode {
kind: SyntaxKind::Eof,
kind: SyntaxKind::End,
text: EcoString::new(),
span: Span::detached(),
}))

View File

@ -41,7 +41,7 @@ fn markup(
) {
let m = p.marker();
let mut nesting: usize = 0;
while !p.eof() {
while !p.end() {
match p.current() {
SyntaxKind::LeftBracket => nesting += 1,
SyntaxKind::RightBracket if nesting > 0 => nesting -= 1,
@ -76,7 +76,7 @@ pub(super) fn reparse_markup(
mut stop: impl FnMut(SyntaxKind) -> bool,
) -> Option<Vec<SyntaxNode>> {
let mut p = Parser::new(text, range.start, LexMode::Markup);
while !p.eof() && p.current_start() < range.end {
while !p.end() && p.current_start() < range.end {
match p.current() {
SyntaxKind::LeftBracket => *nesting += 1,
SyntaxKind::RightBracket if *nesting > 0 => *nesting -= 1,
@ -179,7 +179,7 @@ fn raw(p: &mut Parser) {
p.assert(SyntaxKind::RawDelim);
// Eats until the closing delimiter.
while !p.eof() && !p.at(SyntaxKind::RawDelim) {
while !p.end() && !p.at(SyntaxKind::RawDelim) {
p.eat();
}
@ -272,7 +272,7 @@ fn equation(p: &mut Parser) {
/// Parses the contents of a mathematical equation: `x^2 + 1`.
fn math(p: &mut Parser, mut stop: impl FnMut(&Parser) -> bool) {
let m = p.marker();
while !p.eof() && !stop(p) {
while !p.end() && !stop(p) {
if p.at_set(set::MATH_EXPR) {
math_expr(p);
} else {
@ -285,7 +285,7 @@ fn math(p: &mut Parser, mut stop: impl FnMut(&Parser) -> bool) {
/// Parses a single math expression: This includes math elements like
/// attachment, fractions, and roots, and embedded code expressions.
fn math_expr(p: &mut Parser) {
math_expr_prec(p, 0, SyntaxKind::Eof)
math_expr_prec(p, 0, SyntaxKind::End)
}
/// Parses a math expression with at least the given precedence.
@ -369,7 +369,7 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
// Whether there were _any_ primes in the loop.
let mut primed = false;
while !p.eof() && !p.at(stop) {
while !p.end() && !p.at(stop) {
if p.directly_at(SyntaxKind::Text) && p.current_text() == "!" {
p.eat();
p.wrap(m, SyntaxKind::Math);
@ -429,7 +429,7 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
if p.eat_if(SyntaxKind::Underscore) || (!primed && p.eat_if(SyntaxKind::Hat)) {
let m3 = p.marker();
math_expr_prec(p, prec, SyntaxKind::Eof);
math_expr_prec(p, prec, SyntaxKind::End);
math_unparen(p, m3);
}
@ -449,7 +449,7 @@ fn math_delimited(p: &mut Parser) {
let m = p.marker();
p.eat();
let m2 = p.marker();
while !p.eof() && !p.at(SyntaxKind::Dollar) {
while !p.end() && !p.at(SyntaxKind::Dollar) {
if math_class(p.current_text()) == Some(MathClass::Closing) {
p.wrap(m2, SyntaxKind::Math);
p.eat();
@ -507,7 +507,7 @@ fn math_op(kind: SyntaxKind) -> Option<(SyntaxKind, SyntaxKind, ast::Assoc, usiz
Some((SyntaxKind::MathAttach, SyntaxKind::Underscore, ast::Assoc::Right, 2))
}
SyntaxKind::Slash => {
Some((SyntaxKind::MathFrac, SyntaxKind::Eof, ast::Assoc::Left, 1))
Some((SyntaxKind::MathFrac, SyntaxKind::End, ast::Assoc::Left, 1))
}
_ => None,
}
@ -523,7 +523,7 @@ fn math_args(p: &mut Parser) {
let mut array = p.marker();
let mut arg = p.marker();
while !p.eof() && !p.at(SyntaxKind::Dollar) {
while !p.end() && !p.at(SyntaxKind::Dollar) {
if namable
&& (p.at(SyntaxKind::MathIdent) || p.at(SyntaxKind::Text))
&& p.text[p.current_end()..].starts_with(':')
@ -612,19 +612,19 @@ fn code(p: &mut Parser, stop: impl FnMut(&Parser) -> bool) {
/// Parses a sequence of code expressions.
fn code_exprs(p: &mut Parser, mut stop: impl FnMut(&Parser) -> bool) {
while !p.eof() && !stop(p) {
while !p.end() && !stop(p) {
p.enter_newline_mode(NewlineMode::Contextual);
let at_expr = p.at_set(set::CODE_EXPR);
if at_expr {
code_expr(p);
if !p.eof() && !stop(p) && !p.eat_if(SyntaxKind::Semicolon) {
if !p.end() && !stop(p) && !p.eat_if(SyntaxKind::Semicolon) {
p.expected("semicolon or line break");
}
}
p.exit_newline_mode();
if !at_expr && !p.eof() {
if !at_expr && !p.end() {
p.unexpected();
}
}
@ -647,14 +647,14 @@ fn embedded_code_expr(p: &mut Parser) {
code_expr_prec(p, true, 0);
// Consume error for things like `#12p` or `#"abc\"`.#
if !at && !p.current().is_trivia() && !p.eof() {
if !at && !p.current().is_trivia() && !p.end() {
p.unexpected();
}
let semi =
(stmt || p.directly_at(SyntaxKind::Semicolon)) && p.eat_if(SyntaxKind::Semicolon);
if stmt && !semi && !p.eof() && !p.at(SyntaxKind::RightBracket) {
if stmt && !semi && !p.end() && !p.at(SyntaxKind::RightBracket) {
p.expected("semicolon or line break");
}
@ -1561,8 +1561,8 @@ impl<'s> Parser<'s> {
set.contains(self.current)
}
fn eof(&self) -> bool {
self.at(SyntaxKind::Eof)
fn end(&self) -> bool {
self.at(SyntaxKind::End)
}
fn directly_at(&self, kind: SyntaxKind) -> bool {
@ -1751,7 +1751,7 @@ impl<'s> Parser<'s> {
fn next_non_trivia(lexer: &mut Lexer<'s>) -> SyntaxKind {
loop {
let next = lexer.next();
// Loop is terminatable, because SyntaxKind::Eof is not a trivia.
// Loop is terminatable, because SyntaxKind::End is not a trivia.
if !next.is_trivia() {
break next;
}
@ -1775,7 +1775,7 @@ impl<'s> Parser<'s> {
None => false,
}
{
self.current = SyntaxKind::Eof;
self.current = SyntaxKind::End;
}
}
}

View File

@ -160,7 +160,7 @@ fn try_reparse(
// Stop parsing early if this kind is encountered.
let stop_kind = match parent_kind {
Some(_) => SyntaxKind::RightBracket,
None => SyntaxKind::Eof,
None => SyntaxKind::End,
};
// Reparse!

View File

@ -894,7 +894,7 @@ fn linebreak_optimized<'a>(
let mut lines = Vec::with_capacity(16);
breakpoints(p, |end, breakpoint| {
let k = table.len();
let eof = end == p.bidi.text.len();
let is_end = end == p.bidi.text.len();
let mut best: Option<Entry> = None;
// Find the optimal predecessor.
@ -946,7 +946,7 @@ fn linebreak_optimized<'a>(
active += 1;
}
MAX_COST
} else if breakpoint == Breakpoint::Mandatory || eof {
} else if breakpoint == Breakpoint::Mandatory || is_end {
// This is a mandatory break and the line is not overfull, so
// all breakpoints before this one become inactive since no line
// can span above the mandatory break.
@ -964,7 +964,7 @@ fn linebreak_optimized<'a>(
};
// Penalize runts.
if k == i + 1 && eof {
if k == i + 1 && is_end {
cost += RUNT_COST;
}