Cleanup TunitModifications
This commit is contained in:
@ -2,8 +2,6 @@ defmodule Outlook.InternalTree.TunitModifications do
|
||||
|
||||
alias Outlook.InternalTree.{InternalNode,TranslationUnit}
|
||||
|
||||
require Logger
|
||||
|
||||
def modifiers do
|
||||
[
|
||||
%{
|
||||
@ -25,20 +23,21 @@ defmodule Outlook.InternalTree.TunitModifications do
|
||||
|
||||
defp unite_with_next(nodelist, tu_ids) when is_list(tu_ids) do
|
||||
ids_to_process = Enum.reverse(tu_ids)
|
||||
Logger.info "nu: #{inspect tu_ids}"
|
||||
Enum.reduce(ids_to_process, nodelist, fn id, nodes -> unite_with_next(nodes, id) end)
|
||||
end
|
||||
defp unite_with_next(nodelist, tu_id) do
|
||||
ind = Enum.find_index(nodelist, fn n -> n.nid == tu_id end)
|
||||
case Enum.slice(nodelist, ind, 2) do
|
||||
[unit, next] ->
|
||||
nunit = %TranslationUnit{unit | content: unit.content <> next.content}
|
||||
nodelist
|
||||
|> List.replace_at(ind, nunit)
|
||||
|> List.delete_at(ind + 1)
|
||||
[_] ->
|
||||
nodelist
|
||||
end
|
||||
nodes = Enum.slice(nodelist, ind, 2)
|
||||
unite_with_next(nodelist, ind, nodes)
|
||||
end
|
||||
defp unite_with_next(nodelist, ind, [unit,next]) do
|
||||
nunit = %TranslationUnit{unit | content: unit.content <> next.content}
|
||||
nodelist
|
||||
|> List.replace_at(ind, nunit)
|
||||
|> List.delete_at(ind + 1)
|
||||
end
|
||||
defp unite_with_next(nodelist, _, [_]) do
|
||||
nodelist
|
||||
end
|
||||
|
||||
defp split_tunit(_nodelist, _tu_ids) do
|
||||
|
||||
Reference in New Issue
Block a user