Skip to content

Commit

Permalink
revert rust changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev committed Jan 22, 2025
1 parent 7afe496 commit 7bb4147
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ futures = "0.3.28"
itertools = "0.11"
js-sys = "0.3"
libloading = "0.8.4"
log = { version = "0.4", features = ["kv"] }
log = "0.4"
nickel-lang-core = { version = "0.8.0", default-features = false }
predicates = "3.0"
pretty_assertions = "1.3"
Expand Down
86 changes: 27 additions & 59 deletions topiary-core/src/atom_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,6 @@ impl AtomCollection {
node,
predicates,
),
"append_multiline_delimiter" => {
if self.in_multiline_context(node) {
self.append(
Atom::Literal(requires_delimiter()?.to_string()),
node,
predicates,
)
}
}
"append_empty_softline" => {
self.append(Atom::Softline { spaced: false }, node, predicates);
}
Expand All @@ -260,15 +251,6 @@ impl AtomCollection {
node,
predicates,
),
"prepend_multiline_delimiter" => {
if self.in_multiline_context(node) {
self.prepend(
Atom::Literal(requires_delimiter()?.to_string()),
node,
predicates,
)
}
}
"prepend_empty_softline" => {
self.prepend(Atom::Softline { spaced: false }, node, predicates);
}
Expand Down Expand Up @@ -609,22 +591,6 @@ impl AtomCollection {
self.append.entry(target_node.id()).or_default().push(atom);
}

/// Indicates whether we are in a multiline context or not.
/// # Arguments
///
/// * `node` - The node to which the atom applies.
/// # Returns
///
/// A boolean indicating whether a given node has a a parent labelled as multi-line.
/// If the provided node has no parent, the function returns `false`.
fn in_multiline_context(&self, node: &Node) -> bool {
let parent_id = node.parent().map(|p| p.id());

parent_id
.map(|pid| self.multi_line_nodes.contains(&pid))
.unwrap_or(false)
}

/// Expands a softline atom to a hardline, space or empty atom depending on
/// if we are in a multiline context or not.
///
Expand All @@ -646,32 +612,34 @@ impl AtomCollection {
///
/// A new atom after expanding the softline if applicable.
fn expand_multiline(&self, atom: Atom, node: &Node) -> Atom {
let Atom::Softline { spaced } = atom else {
return atom;
};
let Some(parent) = node.parent() else {
return Atom::Empty;
};
let parent_id = parent.id();

if self.multi_line_nodes.contains(&parent_id) {
log::debug!(
parent_id;
"Expanding softline to hardline in node {}: {}",
node.display_one_based(),
parent.display_one_based()
);
Atom::Hardline
} else if spaced {
log::debug!(
parent_id;
"Expanding softline to space in node {}: {}",
node.display_one_based(),
parent.display_one_based()
);
Atom::Space
if let Atom::Softline { spaced } = atom {
if let Some(parent) = node.parent() {
let parent_id = parent.id();

if self.multi_line_nodes.contains(&parent_id) {
log::debug!(
"Expanding softline to hardline in node {} with parent {}: {}",
node.display_one_based(),
parent_id,
parent.display_one_based()
);
Atom::Hardline
} else if spaced {
log::debug!(
"Expanding softline to space in node {} with parent {}: {}",
node.display_one_based(),
parent_id,
parent.display_one_based()
);
Atom::Space
} else {
Atom::Empty
}
} else {
Atom::Empty
}
} else {
Atom::Empty
atom
}
}

Expand Down

0 comments on commit 7bb4147

Please sign in to comment.