mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Remove markup_while
This commit is contained in:
parent
490819a3d0
commit
b1a82ae22d
@ -28,30 +28,6 @@ pub fn parse(src: &str) -> Rc<GreenNode> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse an atomic primary. Returns `Some` if all of the input was consumed.
|
|
||||||
pub fn parse_atomic(
|
|
||||||
prefix: &str,
|
|
||||||
src: &str,
|
|
||||||
_: bool,
|
|
||||||
_: usize,
|
|
||||||
) -> Option<(Vec<Green>, bool)> {
|
|
||||||
let mut p = Parser::with_prefix(prefix, src, TokenMode::Code);
|
|
||||||
primary(&mut p, true).ok()?;
|
|
||||||
p.consume_unterminated()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse an atomic primary. Returns `Some` if all of the input was consumed.
|
|
||||||
pub fn parse_atomic_markup(
|
|
||||||
prefix: &str,
|
|
||||||
src: &str,
|
|
||||||
_: bool,
|
|
||||||
_: usize,
|
|
||||||
) -> Option<(Vec<Green>, bool)> {
|
|
||||||
let mut p = Parser::with_prefix(prefix, src, TokenMode::Markup);
|
|
||||||
markup_expr(&mut p);
|
|
||||||
p.consume_unterminated()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse some markup. Returns `Some` if all of the input was consumed.
|
/// Parse some markup. Returns `Some` if all of the input was consumed.
|
||||||
pub fn parse_markup(
|
pub fn parse_markup(
|
||||||
prefix: &str,
|
prefix: &str,
|
||||||
@ -83,6 +59,30 @@ pub fn parse_markup_elements(
|
|||||||
p.consume()
|
p.consume()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parse an atomic primary. Returns `Some` if all of the input was consumed.
|
||||||
|
pub fn parse_atomic(
|
||||||
|
prefix: &str,
|
||||||
|
src: &str,
|
||||||
|
_: bool,
|
||||||
|
_: usize,
|
||||||
|
) -> Option<(Vec<Green>, bool)> {
|
||||||
|
let mut p = Parser::with_prefix(prefix, src, TokenMode::Code);
|
||||||
|
primary(&mut p, true).ok()?;
|
||||||
|
p.consume_unterminated()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse an atomic primary. Returns `Some` if all of the input was consumed.
|
||||||
|
pub fn parse_atomic_markup(
|
||||||
|
prefix: &str,
|
||||||
|
src: &str,
|
||||||
|
_: bool,
|
||||||
|
_: usize,
|
||||||
|
) -> Option<(Vec<Green>, bool)> {
|
||||||
|
let mut p = Parser::with_prefix(prefix, src, TokenMode::Markup);
|
||||||
|
markup_expr(&mut p);
|
||||||
|
p.consume_unterminated()
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse a template literal. Returns `Some` if all of the input was consumed.
|
/// Parse a template literal. Returns `Some` if all of the input was consumed.
|
||||||
pub fn parse_template(
|
pub fn parse_template(
|
||||||
prefix: &str,
|
prefix: &str,
|
||||||
@ -128,11 +128,18 @@ pub fn parse_comment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parse markup.
|
/// Parse markup.
|
||||||
fn markup(p: &mut Parser, at_start: bool) {
|
///
|
||||||
markup_while(p, at_start, 0, &mut |_| true)
|
/// If `at_start` is true, things like headings that may only appear at the
|
||||||
|
/// beginning of a line or template are initially allowed.
|
||||||
|
fn markup(p: &mut Parser, mut at_start: bool) {
|
||||||
|
p.perform(NodeKind::Markup(0), |p| {
|
||||||
|
while !p.eof() {
|
||||||
|
markup_node(p, &mut at_start);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse markup that stays right of the given column.
|
/// Parse markup that stays right of the given `column`.
|
||||||
fn markup_indented(p: &mut Parser, column: usize) {
|
fn markup_indented(p: &mut Parser, column: usize) {
|
||||||
p.eat_while(|t| match t {
|
p.eat_while(|t| match t {
|
||||||
NodeKind::Space(n) => *n == 0,
|
NodeKind::Space(n) => *n == 0,
|
||||||
@ -140,22 +147,15 @@ fn markup_indented(p: &mut Parser, column: usize) {
|
|||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
|
|
||||||
markup_while(p, false, column, &mut |p| match p.peek() {
|
let mut at_start = false;
|
||||||
Some(NodeKind::Space(n)) if *n >= 1 => p.column(p.current_end()) >= column,
|
|
||||||
_ => true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a syntax tree while the peeked NodeKind satisifies a condition.
|
|
||||||
///
|
|
||||||
/// If `at_start` is true, things like headings that may only appear at the
|
|
||||||
/// beginning of a line or template are allowed.
|
|
||||||
fn markup_while<F>(p: &mut Parser, mut at_start: bool, column: usize, f: &mut F)
|
|
||||||
where
|
|
||||||
F: FnMut(&mut Parser) -> bool,
|
|
||||||
{
|
|
||||||
p.perform(NodeKind::Markup(column), |p| {
|
p.perform(NodeKind::Markup(column), |p| {
|
||||||
while !p.eof() && f(p) {
|
while !p.eof() {
|
||||||
|
if let Some(NodeKind::Space(1 ..)) = p.peek() {
|
||||||
|
if p.column(p.current_end()) < column {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
markup_node(p, &mut at_start);
|
markup_node(p, &mut at_start);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user