mirror of
https://github.com/typst/typst
synced 2025-05-17 02:25:27 +08:00
current_kind -> current
This commit is contained in:
parent
f8730b09f3
commit
a74bbd8e8b
@ -44,7 +44,7 @@ fn markup(
|
|||||||
let m = p.marker();
|
let m = p.marker();
|
||||||
let mut nesting: usize = 0;
|
let mut nesting: usize = 0;
|
||||||
while !p.end() {
|
while !p.end() {
|
||||||
match p.current_kind() {
|
match p.current() {
|
||||||
SyntaxKind::LeftBracket => nesting += 1,
|
SyntaxKind::LeftBracket => nesting += 1,
|
||||||
SyntaxKind::RightBracket if nesting > 0 => nesting -= 1,
|
SyntaxKind::RightBracket if nesting > 0 => nesting -= 1,
|
||||||
_ if stop(p) => break,
|
_ if stop(p) => break,
|
||||||
@ -79,10 +79,10 @@ pub(super) fn reparse_markup(
|
|||||||
) -> Option<Vec<SyntaxNode>> {
|
) -> Option<Vec<SyntaxNode>> {
|
||||||
let mut p = Parser::new(text, range.start, LexMode::Markup);
|
let mut p = Parser::new(text, range.start, LexMode::Markup);
|
||||||
while !p.end() && p.current_start() < range.end {
|
while !p.end() && p.current_start() < range.end {
|
||||||
match p.current_kind() {
|
match p.current() {
|
||||||
SyntaxKind::LeftBracket => *nesting += 1,
|
SyntaxKind::LeftBracket => *nesting += 1,
|
||||||
SyntaxKind::RightBracket if *nesting > 0 => *nesting -= 1,
|
SyntaxKind::RightBracket if *nesting > 0 => *nesting -= 1,
|
||||||
_ if stop(p.current_kind()) => break,
|
_ if stop(p.current()) => break,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ pub(super) fn reparse_markup(
|
|||||||
/// Parses a single markup expression: This includes markup elements like
|
/// Parses a single markup expression: This includes markup elements like
|
||||||
/// spaces, text, and headings, and embedded code expressions.
|
/// spaces, text, and headings, and embedded code expressions.
|
||||||
fn markup_expr(p: &mut Parser, at_start: &mut bool) {
|
fn markup_expr(p: &mut Parser, at_start: &mut bool) {
|
||||||
match p.current_kind() {
|
match p.current() {
|
||||||
SyntaxKind::Space
|
SyntaxKind::Space
|
||||||
| SyntaxKind::Parbreak
|
| SyntaxKind::Parbreak
|
||||||
| SyntaxKind::LineComment
|
| SyntaxKind::LineComment
|
||||||
@ -257,7 +257,7 @@ fn reference(p: &mut Parser) {
|
|||||||
|
|
||||||
/// Consumes whitespace that does not contain a newline.
|
/// Consumes whitespace that does not contain a newline.
|
||||||
fn whitespace_line(p: &mut Parser) {
|
fn whitespace_line(p: &mut Parser) {
|
||||||
while !p.newline() && p.current_kind().is_trivia() {
|
while !p.newline() && p.current().is_trivia() {
|
||||||
p.eat();
|
p.eat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,7 +296,7 @@ fn math_expr(p: &mut Parser) {
|
|||||||
fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
|
fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
|
||||||
let m = p.marker();
|
let m = p.marker();
|
||||||
let mut continuable = false;
|
let mut continuable = false;
|
||||||
match p.current_kind() {
|
match p.current() {
|
||||||
SyntaxKind::Hash => embedded_code_expr(p),
|
SyntaxKind::Hash => embedded_code_expr(p),
|
||||||
SyntaxKind::MathIdent => {
|
SyntaxKind::MathIdent => {
|
||||||
continuable = true;
|
continuable = true;
|
||||||
@ -396,11 +396,11 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Separate primes and superscripts to different attachments.
|
// Separate primes and superscripts to different attachments.
|
||||||
if primed && p.current_kind() == SyntaxKind::Hat {
|
if primed && p.current() == SyntaxKind::Hat {
|
||||||
p.wrap(m, SyntaxKind::MathAttach);
|
p.wrap(m, SyntaxKind::MathAttach);
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some((kind, stop, assoc, mut prec)) = math_op(p.current_kind()) else {
|
let Some((kind, stop, assoc, mut prec)) = math_op(p.current()) else {
|
||||||
// No attachments, so we need to wrap primes as attachment.
|
// No attachments, so we need to wrap primes as attachment.
|
||||||
if primed {
|
if primed {
|
||||||
p.wrap(m, SyntaxKind::MathAttach);
|
p.wrap(m, SyntaxKind::MathAttach);
|
||||||
@ -668,7 +668,7 @@ fn embedded_code_expr(p: &mut Parser) {
|
|||||||
code_expr_prec(p, true, 0);
|
code_expr_prec(p, true, 0);
|
||||||
|
|
||||||
// Consume error for things like `#12p` or `#"abc\"`.#
|
// Consume error for things like `#12p` or `#"abc\"`.#
|
||||||
if !at && !p.current_kind().is_trivia() && !p.end() {
|
if !at && !p.current().is_trivia() && !p.end() {
|
||||||
p.unexpected();
|
p.unexpected();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,7 +687,7 @@ fn embedded_code_expr(p: &mut Parser) {
|
|||||||
fn code_expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) {
|
fn code_expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) {
|
||||||
let m = p.marker();
|
let m = p.marker();
|
||||||
if !atomic && p.at_set(set::UNARY_OP) {
|
if !atomic && p.at_set(set::UNARY_OP) {
|
||||||
let op = ast::UnOp::from_kind(p.current_kind()).unwrap();
|
let op = ast::UnOp::from_kind(p.current()).unwrap();
|
||||||
p.eat();
|
p.eat();
|
||||||
code_expr_prec(p, atomic, op.precedence());
|
code_expr_prec(p, atomic, op.precedence());
|
||||||
p.wrap(m, SyntaxKind::Unary);
|
p.wrap(m, SyntaxKind::Unary);
|
||||||
@ -717,7 +717,7 @@ fn code_expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let binop = if p.at_set(set::BINARY_OP) {
|
let binop = if p.at_set(set::BINARY_OP) {
|
||||||
ast::BinOp::from_kind(p.current_kind())
|
ast::BinOp::from_kind(p.current())
|
||||||
} else if min_prec <= ast::BinOp::NotIn.precedence() && p.eat_if(SyntaxKind::Not)
|
} else if min_prec <= ast::BinOp::NotIn.precedence() && p.eat_if(SyntaxKind::Not)
|
||||||
{
|
{
|
||||||
if p.at(SyntaxKind::In) {
|
if p.at(SyntaxKind::In) {
|
||||||
@ -756,7 +756,7 @@ fn code_expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) {
|
|||||||
/// composed of.
|
/// composed of.
|
||||||
fn code_primary(p: &mut Parser, atomic: bool) {
|
fn code_primary(p: &mut Parser, atomic: bool) {
|
||||||
let m = p.marker();
|
let m = p.marker();
|
||||||
match p.current_kind() {
|
match p.current() {
|
||||||
SyntaxKind::Ident => {
|
SyntaxKind::Ident => {
|
||||||
p.eat();
|
p.eat();
|
||||||
if !atomic && p.at(SyntaxKind::Arrow) {
|
if !atomic && p.at(SyntaxKind::Arrow) {
|
||||||
@ -814,7 +814,7 @@ fn code_primary(p: &mut Parser, atomic: bool) {
|
|||||||
|
|
||||||
/// Parses a content or code block.
|
/// Parses a content or code block.
|
||||||
fn block(p: &mut Parser) {
|
fn block(p: &mut Parser) {
|
||||||
match p.current_kind() {
|
match p.current() {
|
||||||
SyntaxKind::LeftBracket => content_block(p),
|
SyntaxKind::LeftBracket => content_block(p),
|
||||||
SyntaxKind::LeftBrace => code_block(p),
|
SyntaxKind::LeftBrace => code_block(p),
|
||||||
_ => p.expected("block"),
|
_ => p.expected("block"),
|
||||||
@ -1005,7 +1005,7 @@ fn module_import(p: &mut Parser) {
|
|||||||
/// Parses items to import from a module: `a, b, c`.
|
/// Parses items to import from a module: `a, b, c`.
|
||||||
fn import_items(p: &mut Parser) {
|
fn import_items(p: &mut Parser) {
|
||||||
let m = p.marker();
|
let m = p.marker();
|
||||||
while !p.current_kind().is_terminator() {
|
while !p.current().is_terminator() {
|
||||||
let item_marker = p.marker();
|
let item_marker = p.marker();
|
||||||
if !p.eat_if(SyntaxKind::Ident) {
|
if !p.eat_if(SyntaxKind::Ident) {
|
||||||
p.unexpected();
|
p.unexpected();
|
||||||
@ -1024,7 +1024,7 @@ fn import_items(p: &mut Parser) {
|
|||||||
p.wrap(item_marker, SyntaxKind::RenamedImportItem);
|
p.wrap(item_marker, SyntaxKind::RenamedImportItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !p.current_kind().is_terminator() {
|
if !p.current().is_terminator() {
|
||||||
p.expect(SyntaxKind::Comma);
|
p.expect(SyntaxKind::Comma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1149,7 +1149,7 @@ fn parenthesized_or_array_or_dict(p: &mut Parser) -> SyntaxKind {
|
|||||||
state.maybe_just_parens = false;
|
state.maybe_just_parens = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while !p.current_kind().is_terminator() {
|
while !p.current().is_terminator() {
|
||||||
if !p.at_set(set::ARRAY_OR_DICT_ITEM) {
|
if !p.at_set(set::ARRAY_OR_DICT_ITEM) {
|
||||||
p.unexpected();
|
p.unexpected();
|
||||||
continue;
|
continue;
|
||||||
@ -1158,7 +1158,7 @@ fn parenthesized_or_array_or_dict(p: &mut Parser) -> SyntaxKind {
|
|||||||
array_or_dict_item(p, &mut state);
|
array_or_dict_item(p, &mut state);
|
||||||
state.count += 1;
|
state.count += 1;
|
||||||
|
|
||||||
if !p.current_kind().is_terminator() && p.expect(SyntaxKind::Comma) {
|
if !p.current().is_terminator() && p.expect(SyntaxKind::Comma) {
|
||||||
state.maybe_just_parens = false;
|
state.maybe_just_parens = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1249,7 +1249,7 @@ fn args(p: &mut Parser) {
|
|||||||
p.assert(SyntaxKind::LeftParen);
|
p.assert(SyntaxKind::LeftParen);
|
||||||
|
|
||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
while !p.current_kind().is_terminator() {
|
while !p.current().is_terminator() {
|
||||||
if !p.at_set(set::ARG) {
|
if !p.at_set(set::ARG) {
|
||||||
p.unexpected();
|
p.unexpected();
|
||||||
continue;
|
continue;
|
||||||
@ -1257,7 +1257,7 @@ fn args(p: &mut Parser) {
|
|||||||
|
|
||||||
arg(p, &mut seen);
|
arg(p, &mut seen);
|
||||||
|
|
||||||
if !p.current_kind().is_terminator() {
|
if !p.current().is_terminator() {
|
||||||
p.expect(SyntaxKind::Comma);
|
p.expect(SyntaxKind::Comma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1314,7 +1314,7 @@ fn params(p: &mut Parser) {
|
|||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
let mut sink = false;
|
let mut sink = false;
|
||||||
|
|
||||||
while !p.current_kind().is_terminator() {
|
while !p.current().is_terminator() {
|
||||||
if !p.at_set(set::PARAM) {
|
if !p.at_set(set::PARAM) {
|
||||||
p.unexpected();
|
p.unexpected();
|
||||||
continue;
|
continue;
|
||||||
@ -1322,7 +1322,7 @@ fn params(p: &mut Parser) {
|
|||||||
|
|
||||||
param(p, &mut seen, &mut sink);
|
param(p, &mut seen, &mut sink);
|
||||||
|
|
||||||
if !p.current_kind().is_terminator() {
|
if !p.current().is_terminator() {
|
||||||
p.expect(SyntaxKind::Comma);
|
p.expect(SyntaxKind::Comma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1371,7 +1371,7 @@ fn pattern<'s>(
|
|||||||
seen: &mut HashSet<&'s str>,
|
seen: &mut HashSet<&'s str>,
|
||||||
dupe: Option<&'s str>,
|
dupe: Option<&'s str>,
|
||||||
) {
|
) {
|
||||||
match p.current_kind() {
|
match p.current() {
|
||||||
SyntaxKind::Underscore => p.eat(),
|
SyntaxKind::Underscore => p.eat(),
|
||||||
SyntaxKind::LeftParen => destructuring_or_parenthesized(p, reassignment, seen),
|
SyntaxKind::LeftParen => destructuring_or_parenthesized(p, reassignment, seen),
|
||||||
_ => pattern_leaf(p, reassignment, seen, dupe),
|
_ => pattern_leaf(p, reassignment, seen, dupe),
|
||||||
@ -1392,7 +1392,7 @@ fn destructuring_or_parenthesized<'s>(
|
|||||||
p.enter_newline_mode(NewlineMode::Continue);
|
p.enter_newline_mode(NewlineMode::Continue);
|
||||||
p.assert(SyntaxKind::LeftParen);
|
p.assert(SyntaxKind::LeftParen);
|
||||||
|
|
||||||
while !p.current_kind().is_terminator() {
|
while !p.current().is_terminator() {
|
||||||
if !p.at_set(set::DESTRUCTURING_ITEM) {
|
if !p.at_set(set::DESTRUCTURING_ITEM) {
|
||||||
p.unexpected();
|
p.unexpected();
|
||||||
continue;
|
continue;
|
||||||
@ -1401,7 +1401,7 @@ fn destructuring_or_parenthesized<'s>(
|
|||||||
destructuring_item(p, reassignment, seen, &mut maybe_just_parens, &mut sink);
|
destructuring_item(p, reassignment, seen, &mut maybe_just_parens, &mut sink);
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
||||||
if !p.current_kind().is_terminator() && p.expect(SyntaxKind::Comma) {
|
if !p.current().is_terminator() && p.expect(SyntaxKind::Comma) {
|
||||||
maybe_just_parens = false;
|
maybe_just_parens = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1467,7 +1467,7 @@ fn pattern_leaf<'s>(
|
|||||||
seen: &mut HashSet<&'s str>,
|
seen: &mut HashSet<&'s str>,
|
||||||
dupe: Option<&'s str>,
|
dupe: Option<&'s str>,
|
||||||
) {
|
) {
|
||||||
if p.current_kind().is_keyword() {
|
if p.current().is_keyword() {
|
||||||
p.eat_and_get().expected("pattern");
|
p.eat_and_get().expected("pattern");
|
||||||
return;
|
return;
|
||||||
} else if !p.at_set(set::PATTERN_LEAF) {
|
} else if !p.at_set(set::PATTERN_LEAF) {
|
||||||
@ -1564,7 +1564,7 @@ impl<'s> Parser<'s> {
|
|||||||
self.prev_end
|
self.prev_end
|
||||||
}
|
}
|
||||||
|
|
||||||
fn current_kind(&self) -> SyntaxKind {
|
fn current(&self) -> SyntaxKind {
|
||||||
self.current.kind()
|
self.current.kind()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1632,7 +1632,7 @@ impl<'s> Parser<'s> {
|
|||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn assert(&mut self, kind: SyntaxKind) {
|
fn assert(&mut self, kind: SyntaxKind) {
|
||||||
assert_eq!(self.current_kind(), kind);
|
assert_eq!(self.current(), kind);
|
||||||
self.eat();
|
self.eat();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1741,7 +1741,7 @@ impl<'s> Parser<'s> {
|
|||||||
|
|
||||||
fn skip(&mut self) {
|
fn skip(&mut self) {
|
||||||
if self.lexer.mode() != LexMode::Markup {
|
if self.lexer.mode() != LexMode::Markup {
|
||||||
while self.current_kind().is_trivia() {
|
while self.current().is_trivia() {
|
||||||
self.save_and_lex();
|
self.save_and_lex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1809,7 +1809,7 @@ impl<'s> Parser<'s> {
|
|||||||
let at = self.at(kind);
|
let at = self.at(kind);
|
||||||
if at {
|
if at {
|
||||||
self.eat();
|
self.eat();
|
||||||
} else if kind == SyntaxKind::Ident && self.current_kind().is_keyword() {
|
} else if kind == SyntaxKind::Ident && self.current().is_keyword() {
|
||||||
self.trim_errors();
|
self.trim_errors();
|
||||||
self.eat_and_get().expected(kind.name());
|
self.eat_and_get().expected(kind.name());
|
||||||
} else {
|
} else {
|
||||||
@ -1855,7 +1855,7 @@ impl<'s> Parser<'s> {
|
|||||||
/// unexpected.
|
/// unexpected.
|
||||||
fn unexpected(&mut self) {
|
fn unexpected(&mut self) {
|
||||||
self.trim_errors();
|
self.trim_errors();
|
||||||
self.balanced &= !self.current_kind().is_grouping();
|
self.balanced &= !self.current().is_grouping();
|
||||||
self.eat_and_get().unexpected();
|
self.eat_and_get().unexpected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user