summaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-04 22:14:57 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-04 22:14:57 +0200
commite674fd7e909c273c36952f01829544a2efc11c92 (patch)
treec74218ce4a546de06b28aad2f73ba460338252b7 /src/parse
parent75472fee1a2377f56551fc856cf7511bd55091f0 (diff)
New raw theme & nicer debug representation
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/mod.rs30
1 files changed, 21 insertions, 9 deletions
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<GreenNode> {
}
}
+/// Parse code directly, only used for syntax highlighting.
+pub fn parse_code(src: &str) -> Vec<Green> {
+ 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: `[...]`.