const fs = require('fs')
    , path = require('path')
    , nameRe = /^:(.*):/
    , patternLineRe = /^\t([\.\*]+)$/

module.exports.parse = parse

function parse(lines) {
  return lines.reduce((parsed, line, index) => {
    const matches = nameRe.exec(line)
    if (!matches) return parsed
    const name = matches[1]
        , pattern = findPattern(lines.slice(index + 1))
        , width = pattern[0] ? pattern[0].length : undefined
        , height = pattern.length ? pattern.length : undefined
    return parsed.concat({ name, pattern, width, height })
  }, [])
}

function findPattern(lines, pattern = []) {
  if (!lines.length) return pattern

  const [line, ...remainingLines] = lines
  const matches = patternLineRe.exec(line)

  if (!matches && pattern.length) return pattern
  if (!matches && !pattern.length) return findPattern(remainingLines, pattern)

  return findPattern(remainingLines, pattern.concat( toPatternLine(matches) ))
}

function toPatternLine(matches) {
  return [ matches[1].split('').map( toBinary ) ]
}

function toBinary(char) {
  return { '.': 0, '*': 1 }[char]
}

@@ -53,20 +53,58 @@
 )%0A    , 
-name
+mainSectionDividerRe = /%5E(%5C-)+$/%0A    , key
 Re = /%5E:
@@ -153,36 +153,489 @@
 $/%0A%0A
-module.exports.parse = parse
+const findSections = dividerRe =%3E lines =%3E %7B%0A  return lines.reduce((sections, line) =%3E %7B%0A    if (dividerRe.test(line)) return sections.concat(%5B%5B line %5D%5D)%0A    last(sections).push(line)%0A    return sections%0A  %7D, %5B%5B%5D%5D)%0A%7D%0A%0Aconst findMainSections = findSections(mainSectionDividerRe)%0A    , findContentSections = findSections(keyRe)%0A%0A%0Amodule.exports.parse = parse%0A%0A%0Afunction findTerms(lines) %7B%0A  const contentLines = findMainSections(lines)%5B1%5D%0A  return findContentSections(contentLines)%0A%7D
 %0A%0Afu
@@ -725,20 +725,19 @@
 tches = 
-name
+key
 Re.exec(
@@ -1576,12 +1576,71 @@
 1 %7D%5Bchar%5D%0A%7D%0A
+%0Afunction last(array) %7B%0A  return array%5Barray.length - 1%5D%0A%7D%0A

Generalize parsing