From e674fd7e909c273c36952f01829544a2efc11c92 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 4 May 2022 22:14:57 +0200 Subject: New raw theme & nicer debug representation --- src/parse/mod.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src/parse') diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 9f4860e7..7811482b 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -26,6 +26,13 @@ pub fn parse(src: &str) -> Arc { } } +/// Parse code directly, only used for syntax highlighting. +pub fn parse_code(src: &str) -> Vec { + let mut p = Parser::new(src, TokenMode::Code); + code(&mut p); + p.finish() +} + /// Reparse a code block. /// /// Returns `Some` if all of the input was consumed. @@ -696,18 +703,23 @@ fn params(p: &mut Parser, marker: Marker) { fn code_block(p: &mut Parser) { p.perform(NodeKind::CodeBlock, |p| { p.start_group(Group::Brace); - while !p.eof() { - p.start_group(Group::Expr); - if expr(p).is_ok() && !p.eof() { - p.expected("semicolon or line break"); - } - p.end_group(); + code(p); + p.end_group(); + }); +} - // Forcefully skip over newlines since the group's contents can't. - p.eat_while(|t| matches!(t, NodeKind::Space(_))); +/// Parse expressions. +fn code(p: &mut Parser) { + while !p.eof() { + p.start_group(Group::Expr); + if expr(p).is_ok() && !p.eof() { + p.expected("semicolon or line break"); } p.end_group(); - }); + + // Forcefully skip over newlines since the group's contents can't. + p.eat_while(|t| matches!(t, NodeKind::Space(_))); + } } // Parse a content block: `[...]`. -- cgit v1.2.3