30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/review/tocparser.rb', line 30
def parse(f, id, filename)
roots = []
path = []
while line = f.gets
line.sub!(/\A\xEF\xBB\xBF/u, '') case line
when /\A\#@/
;
when /\A\s*\z/
;
when /\A(={2,})[\[\s]/
lev = $1.size
error! filename, f.lineno, "section level too deep: #{lev}" if lev > 5
if path.empty?
path.push Chapter.new(get_label(line), id, filename)
roots.push path.first
end
next if get_label(line) =~ /\A\[\// new = Section.new(lev, get_label(line))
until path.last.level < new.level
path.pop
end
path.last.add_child new
path.push new
when /\A= /
path.clear
path.push Chapter.new(get_label(line), id, filename)
roots.push path.first
when %r<\A//\w+(?:\[.*?\])*\{\s*\z>
if path.empty?
error! filename, f.lineno, 'list found before section label'
end
path.last.add_child(list = List.new)
beg = f.lineno
list.add line
while line = f.gets
break if %r<\A//\}> =~ line
list.add line
end
error! filename, beg, 'unterminated list' unless line
when %r<\A//\w>
;
else
next if path.empty?
path.last.add_child(par = Paragraph.new)
par.add line
while line = f.gets
break if /\A\s*\z/ =~ line
par.add line
end
end
end
roots
end
|