From da0ed3f2b315c023440b1cd4178c903b95f232b1 Mon Sep 17 00:00:00 2001 From: jutty Date: Fri, 26 Dec 2025 01:18:38 -0300 Subject: [PATCH] Add closing function on content syntax parser This provides saner, more testable, properly closed output even without a trailing newline. --- src/syntax/content/parser.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/syntax/content/parser.rs b/src/syntax/content/parser.rs index aee8e54..ea9744b 100644 --- a/src/syntax/content/parser.rs +++ b/src/syntax/content/parser.rs @@ -1,6 +1,6 @@ use std::collections::{HashMap}; -use crate::{syntax::serial::populate_graph, types::Config}; +use crate::{prelude::*, syntax::serial::populate_graph, types::Config}; use super::{Parseable as _, Token, LexMap}; use token::{ anchor::Anchor, linebreak::LineBreak, paragraph::Paragraph, header::Header, @@ -168,6 +168,7 @@ fn lex(text: &str, map: LexMap) -> Vec { } } + close(&state, &mut tokens); tokens } @@ -233,6 +234,18 @@ impl State { } } +fn close(state: &State, tokens: &mut Vec) { + match state.context.block { + BlockContext::Paragraph => { + tokens.push(Token::Paragraph(Paragraph::new(false))); + }, + BlockContext::Header(_) => panic!("End of file with open header"), + BlockContext::PreFormat => panic!("End of file with open preformat"), + BlockContext::None => log!("End of file on None block context"), + } +} + + fn parse(tokens: &[Token]) -> String { tokens.iter().map(Token::render).collect::() }