-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
post_parser.go
67 lines (57 loc) · 1.23 KB
/
post_parser.go
1
2
3
4
5
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
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
package hype
type PostParser interface {
PostParse(p *Parser, d *Document, err error) error
}
type PostParseFn func(p *Parser, d *Document, err error) error
func (fn PostParseFn) PostParse(p *Parser, d *Document, err error) error {
return fn(p, d, err)
}
func (list Nodes) PostParse(p *Parser, d *Document, err error) error {
var err2 error
for _, n := range list {
if nodes, ok := n.(Nodes); ok {
err2 = nodes.PostParse(p, d, err)
if err2 != nil {
if _, ok := err2.(PostParseError); ok {
return err2
}
return PostParseError{
Document: d,
Err: err2,
Filename: p.Filename,
OrigErr: err,
Root: p.Root,
}
}
continue
}
pp, ok := n.(PostParser)
if ok {
err2 = pp.PostParse(p, d, err)
if err2 != nil {
return PostParseError{
Document: d,
Err: err2,
Filename: p.Filename,
OrigErr: err,
PostParser: pp,
Root: p.Root,
}
}
}
err2 = n.Children().PostParse(p, d, err)
if err2 != nil {
if _, ok := err2.(PostParseError); ok {
return err2
}
return PostParseError{
Document: d,
Err: err2,
Filename: p.Filename,
OrigErr: err,
Root: p.Root,
}
}
}
return err
}