minor cleanup

This commit is contained in:
Anton-4 2021-07-07 18:08:34 +02:00
parent e7c5cc5664
commit e156fbef03
5 changed files with 24 additions and 29 deletions

View File

@ -166,9 +166,9 @@ where
p.build()?
};
/*if DEBUG {
if DEBUG {
eprintln!("{}", program.to_source_string());
}*/
}
morphic_lib::solve(program)
}

View File

@ -75,7 +75,7 @@ impl MarkupNode {
}
}
// return (index of child in list of children, index of child in list of children of ast node)
// return (index of child in list of children, closest ast index of child corresponding to ast node)
pub fn get_child_indices(
&self,
child_id: MarkNodeId,

View File

@ -135,7 +135,7 @@ impl<'a> EdModel<'a> {
self.grid_node_map.node_exists_at_pos(self.get_caret())
}
// return (index of child in list of children, index of child in list of children of ast node) of MarkupNode at current caret position
// return (index of child in list of children, closest ast index of child corresponding to ast node) of MarkupNode at current caret position
pub fn get_curr_child_indices(&self) -> EdResult<(usize, usize)> {
if self.node_exists_at_caret() {
let curr_mark_node_id = self.get_curr_mark_node_id()?;

View File

@ -696,16 +696,13 @@ pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult
Expr2::List{ elem_var: _, elems: _} => {
let prev_mark_node = ed_model.markup_node_pool.get(prev_mark_node_id);
if prev_mark_node.get_content()? == nodes::LEFT_SQUARE_BR {
if curr_mark_node.get_content()? == nodes::RIGHT_SQUARE_BR {
// based on if, we are at the start of the list
let new_child_index = 1;
let new_ast_child_index = 0;
add_blank_child(new_child_index, new_ast_child_index, ed_model)?; // insert a Blank first, this results in cleaner code
handle_new_char(received_char, ed_model)?
} else {
InputOutcome::Ignored
}
if prev_mark_node.get_content()? == nodes::LEFT_SQUARE_BR && curr_mark_node.get_content()? == nodes::RIGHT_SQUARE_BR {
// based on if, we are at the start of the list
let new_child_index = 1;
let new_ast_child_index = 0;
// insert a Blank first, this results in cleaner code
add_blank_child(new_child_index, new_ast_child_index, ed_model)?;
handle_new_char(received_char, ed_model)?
} else {
InputOutcome::Ignored
}
@ -773,22 +770,19 @@ pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult
} else if "\"{[".contains(*ch) {
let prev_mark_node = ed_model.markup_node_pool.get(prev_mark_node_id);
if prev_mark_node.get_content()? == nodes::LEFT_SQUARE_BR {
if curr_mark_node.get_content()? == nodes::RIGHT_SQUARE_BR {
let (new_child_index, new_ast_child_index) = ed_model.get_curr_child_indices()?;
// insert a Blank first, this results in cleaner code
add_blank_child(
new_child_index,
new_ast_child_index,
ed_model
)?;
handle_new_char(received_char, ed_model)?
} else {
InputOutcome::Ignored
}
if prev_mark_node.get_content()? == nodes::LEFT_SQUARE_BR && curr_mark_node.get_content()? == nodes::RIGHT_SQUARE_BR {
let (new_child_index, new_ast_child_index) = ed_model.get_curr_child_indices()?;
// insert a Blank first, this results in cleaner code
add_blank_child(
new_child_index,
new_ast_child_index,
ed_model
)?;
handle_new_char(received_char, ed_model)?
} else {
InputOutcome::Ignored
}
} else {
InputOutcome::Ignored
}

View File

@ -164,7 +164,7 @@ pub fn add_blank_child(
.fail(),
}?;
let new_mark_children = make_mark_children(
let new_mark_children = update_mark_children(
new_child_index,
blank_elt_id,
list_ast_node_id,
@ -182,7 +182,8 @@ pub fn add_blank_child(
Ok(InputOutcome::Accepted)
}
pub fn make_mark_children(
// add a Blank child to the Nested mark node and update the caret
pub fn update_mark_children(
new_child_index: usize,
blank_elt_id: ExprId,
list_ast_node_id: ExprId,