Example #1
0
    def parse_t(self, lojban):

        fihe_out = run_jbofihe("-t", lojban)

        # it's easier to determine the indentation
        # level if we parse the output backwards
        fihe_tree = fihe_out.split("\n")[::-1]
        fihe_tree.pop(0)

        def dive(tree):

            level = tree[0].find("+")

            if level == -1:
                chunks = tree.pop(0)
                return [(chunks, dive(tree))]

            result = []
            while tree and tree[0][level] in ("+", "|"):
                line = tree[0]
                if line[level] == "+":
                    line =line[level+2:]
                    if ":" in line:
                        t, d = line.split(":")
                        result.append((t.strip(), d.strip()))
                    typ = line
                    tree.pop(0)
                    continue
                elif line[level] == "|":
                    result.append((typ, dive(tree)))
            return result[::-1] # back from backwards parsing

        return dive(fihe_tree)
Example #2
0
    def parse_xb(self, lojban):

        fihe_out = run_jbofihe("-x -b", lojban)
        lines = fihe_out.split("\n")
        lines.pop()
        out = map(lambda _: [], range(5))
        for i in range(len(lines) / 5):
            section = lines[5*i:5*(i+1)]
            for j, line in enumerate(section):
                out[j].append(line)
        return map("".join, out)