6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/treeline/parser.rb', line 6
def parse(lines)
tree = {}
@path = []
lines.each do | line |
line.rstrip!
line = yield(line) if block_given?
if (line =~ /^\S/)
@path = [ [ line, 0 ] ]
else
matched = /^(\s+)/.match(line)
unless (matched.nil?)
indent = matched[1].length
while (indent <= @path[0][1])
@path.shift
end
line.lstrip!
@path.unshift [ line, indent ]
end
end
make_path_to_node(tree, @path.reverse)
end
tree
end
|