This repository has been archived by the owner on Mar 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
comment.go
61 lines (56 loc) · 1.91 KB
/
comment.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
package parser
import (
doc "github.com/demizer/go-rst/pkg/document"
mes "github.com/demizer/go-rst/pkg/messages"
tok "github.com/demizer/go-rst/pkg/token"
)
func (p *Parser) comment(i *tok.Item) doc.Node {
var n doc.Node
if p.peek(1).Type == tok.BlankLine {
p.Msg("Found empty comment block")
n := doc.NewComment(&tok.Item{StartPosition: i.StartPosition, Line: i.Line})
p.nodeTarget.Append(n)
return n
}
if nSpace := p.peek(1); nSpace != nil && nSpace.Type != tok.Space {
// The comment element itself is valid, but we need to add it to the NodeList before the systemMessage.
p.Msg("Missing space after comment mark! (mes.InlineMarkupWarningExplicitMarkupWithUnIndent)")
p.systemMessage(mes.InlineMarkupWarningExplicitMarkupWithUnIndent)
return n
// return doc.NewComment(&tok.Item{Line: i.Line})
}
nPara := p.peek(2)
p.Msgr("two peek ahead", "type", nPara.Type)
if nPara != nil && nPara.Type == tok.Text {
// Skip the tok.Space
p.next(2)
p.Msgr("have token", "token", p.token)
// See if next line is indented, if so, it is part of the comment
if p.peek(1).Type == tok.Space && p.peek(2).Type == tok.Text {
p.Msg("Found NodeComment block")
p.next(2)
for {
nPara.Text += "\n" + p.token.Text
if p.peek(1).Type == tok.Space && p.peek(2).Type == tok.Text {
p.next(2)
} else {
break
}
}
nPara.Length = len(nPara.Text)
} else if z := p.peek(1); z != nil && z.Type != tok.BlankLine && z.Type != tok.CommentMark && z.Type != tok.EOF {
// A valid comment contains a blank line after the comment block
p.Msg("Found mes.InlineMarkupWarningExplicitMarkupWithUnIndent")
n = doc.NewComment(nPara)
p.nodeTarget.Append(n)
p.systemMessage(mes.InlineMarkupWarningExplicitMarkupWithUnIndent)
return n
} else {
// Just a regular single lined comment
p.Msg("Found one-line NodeComment")
}
n = doc.NewComment(nPara)
}
p.nodeTarget.Append(n)
return n
}