
fill_substr_info <- function(skeleton) {
  # 1. Datei lesen falls nötig
  if (length(skeleton) == 1 && file.exists(skeleton))
    skeleton <- readLines(skeleton)

  # 2. x aus skeleton[1] extrahieren
  x <- str_split_1(skeleton[1], ":")[2]
  x <- str_trim(x)

  # 3. df erzeugen (Skeleton-Einträge mit Hierarchie)
  x_marked <- mark_skeleton_entries(x)
  df <- extract_skeleton_entries(x_marked)

  # 4. type und translation aus Skeleton-Zeilen in df übertragen
  entry_lines <- skeleton[startsWith(skeleton, "|")]
  df$type <- ""
  df$translation <- ""
  for (i in seq_len(nrow(df))) {
    line <- entry_lines[i]
    if (df$depth[i] == 0) {
      # Format: |header:type:translation (split at first two ":")
      stripped <- sub("^\\|", "", line)
      first  <- str_split_fixed(stripped, ":", 2)
      second <- str_split_fixed(first[,2], ":", 2)
    } else {
      # Format: |[tabs]eq: type: translation (split at first two ": ")
      stripped <- sub("^\\|\\t*", "", line)
      first  <- str_split_fixed(stripped, ": ", 2)
      second <- str_split_fixed(first[,2], ": ", 2)
    }
    df$type[i]        <- str_trim(second[,1])
    df$translation[i] <- str_trim(second[,2])
  }

  # 5. df_substr erzeugen (alle N*(N+1)/2 Substrings)
  token <- split_sumerian(x)$signs
  N <- length(token)
  df_substr <- init_substr_info(token)

  # 6. Einträge von df nach df_substr übertragen via substr_position
  positions <- substr_position(df$start, df$n_tokens, N)
  df_substr$type[positions]        <- df$type
  df_substr$translation[positions] <- df$translation

  df_substr
}
