use crate::SyntaxKind::{
BACKSLASH, BLOCK_COMMENT, CONTENT_LINE, DIVERT, EOF, ESCAPE, GLUE, GLUE_NODE, HASH, L_BRACE,
LINE_COMMENT, MIXED_CONTENT, NEWLINE, PIPE, R_BRACE, TEXT, THREAD, TUNNEL_ONWARDS,
};
use super::Parser;
pub(crate) fn content_line(p: &mut Parser<'_, '_>) {
p.start_node(CONTENT_LINE);
if super::divert::at_divert(p) {
super::divert::divert(p);
if super::divert::at_divert(p) {
super::divert::divert(p);
}
} else {
mixed_content(p);
if super::divert::at_divert(p) {
super::divert::divert(p);
if super::divert::at_divert(p) {
super::divert::divert(p);
}
}
}
if p.current() == HASH {
super::tag::tags(p);
}
if p.at(NEWLINE) {
p.bump();
} else if !p.at_eof() {
p.error("expected newline at end of content line".into());
}
p.finish_node();
}
pub(crate) fn mixed_content(p: &mut Parser<'_, '_>) {
p.start_node(MIXED_CONTENT);
loop {
match p.current() {
NEWLINE | EOF | HASH | DIVERT | TUNNEL_ONWARDS | THREAD => break,
GLUE => {
p.skip_ws(); p.start_node(GLUE_NODE);
p.bump();
p.finish_node();
}
BACKSLASH if !matches!(p.nth(1), NEWLINE | EOF) => {
p.start_node(ESCAPE);
p.bump(); p.bump(); p.finish_node();
}
L_BRACE => {
if p.nth_raw(0) == L_BRACE {
super::inline::inline_logic(p);
} else {
let before = p.pos();
text_content(p);
if p.pos() == before {
p.skip_ws();
}
}
}
_ => {
let before = p.pos();
text_content(p);
if p.pos() == before {
break;
}
}
}
}
p.finish_node();
}
fn text_content(p: &mut Parser<'_, '_>) {
p.start_node(TEXT);
loop {
if p.at_eof() {
break;
}
match p.nth_raw(0) {
NEWLINE | L_BRACE | R_BRACE | GLUE | DIVERT | TUNNEL_ONWARDS | THREAD
| LINE_COMMENT | BLOCK_COMMENT | HASH | PIPE | BACKSLASH | EOF => break,
_ => p.bump(),
}
}
p.finish_node();
}