From 7d9f9be43469748148da5cdf516cd8b32238e1f5 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 23 Apr 2026 18:58:41 +0800 Subject: 重构AST抽象 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ast/parser/emphasis.rs | 137 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 src/ast/parser/emphasis.rs (limited to 'src/ast/parser/emphasis.rs') diff --git a/src/ast/parser/emphasis.rs b/src/ast/parser/emphasis.rs new file mode 100644 index 0000000..c8e6b9b --- /dev/null +++ b/src/ast/parser/emphasis.rs @@ -0,0 +1,137 @@ +use crate::ast::parser::{ParserInternalStatus, ParserMatchResult}; + +#[derive(Default)] +struct EmphasisTmp { + /// 强调开始的列 + emphasis_begin_col: u16, + + /// 前缀,用于后缀匹配 + prefix_count: String, + + /// 是否正在输入强调前缀 + typing_emphasis_prefix: bool, + + /// 是否正在输入强调内容 + typing_emphasis_content: bool, +} + +#[derive(Default, PartialEq, Eq)] +#[repr(u8)] +enum Style { + /// 无样式 + #[default] + None, + + /// 星号 + Star, + + /// 下划线 + Underline, +} + +impl Style { + /// 反转样式 + pub fn invert(&self) -> Style { + match self { + Style::Underline => Style::Star, + Style::Star => Style::Underline, + Style::None => Style::None, + } + } +} + +impl std::fmt::Display for Style { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Style::None => write!(f, ""), + Style::Star => write!(f, "*"), + Style::Underline => write!(f, "_"), + } + } +} + +impl From