rustla/parser/state_machine/
aplus.rs1use super::*;
8
9pub fn aplus_col_break(
11 src_lines: &Vec<String>,
12 base_indent: usize,
13 section_level: &mut usize,
14 line_cursor: &mut LineCursor,
15 mut doctree: DocTree,
16 captures: ®ex::Captures,
17 pattern_name: &Pattern,
18) -> TransitionResult {
19
20 let detected_marker_indent = captures.get(1).unwrap().as_str().chars().count();
21
22 match Parser::parent_indent_matches(doctree.shared_node_data(), detected_marker_indent) {
23 IndentationMatch::JustRight => {
24 doctree = match doctree.push_data(TreeNodeType::AplusColBreak) {
25 Ok(tree) => tree,
26 Err(tree) => {
27 return TransitionResult::Failure {
28 message: format!(
29 "Node insertion error on line {}. Computer says no...",
30 line_cursor.sum_total()
31 ),
32 doctree: tree,
33 }
34 }
35 };
36 TransitionResult::Success {
37 doctree: doctree,
38 push_or_pop: PushOrPop::Neither,
39 line_advance: LineAdvance::Some(1),
40 }
41 }
42 IndentationMatch::TooLittle => {
43 eprintln!(
44 "Detected a column break on line {} with too little indentation. Interpreting as paragraph...",
45 line_cursor.sum_total()
46 );
47 doctree = doctree.focus_on_parent();
48 TransitionResult::Success {
49 doctree: doctree,
50 push_or_pop: PushOrPop::Pop,
51 line_advance: LineAdvance::None,
52 }
53 }
54 IndentationMatch::TooMuch => {
55 doctree = match doctree.push_data_and_focus(
56 TreeNodeType::BlockQuote {
57 body_indent: detected_marker_indent,
58 }
59 ) {
60 Ok(tree) => tree,
61 Err(tree) => {
62 return TransitionResult::Failure {
63 message: format!(
64 "Node insertion error on line {}. Computer says no...",
65 line_cursor.sum_total()
66 ),
67 doctree: tree,
68 }
69 }
70 };
71 return TransitionResult::Success {
72 doctree: doctree,
73 push_or_pop: PushOrPop::Push(vec![State::BlockQuote]),
74 line_advance: LineAdvance::None,
75 };
76 }
77 }
78}