@@ -22,26 +22,28 @@ import (
22
22
"github.com/arduino/go-paths-helper"
23
23
)
24
24
25
- const KIND_PROTOTYPE = "prototype"
26
- const KIND_FUNCTION = "function"
25
+ const kindPrototype = "prototype"
26
+ const kindFunction = "function"
27
27
28
28
//const KIND_PROTOTYPE_MODIFIERS = "prototype_modifiers"
29
29
30
- const TEMPLATE = "template"
31
- const STATIC = "static"
32
- const EXTERN = "extern \" C\" "
30
+ const keywordTemplate = "template"
31
+ const keywordStatic = "static"
32
+ const keywordExternC = "extern \" C\" "
33
33
34
- var KNOWN_TAG_KINDS = map [string ]bool {
34
+ var knownTagKinds = map [string ]bool {
35
35
"prototype" : true ,
36
36
"function" : true ,
37
37
}
38
38
39
- type CTagsParser struct {
40
- tags []* CTag
39
+ // Parser is a parser for ctags output
40
+ type Parser struct {
41
+ tags []* Tag
41
42
mainFile * paths.Path
42
43
}
43
44
44
- type CTag struct {
45
+ // Tag is a tag generated by ctags
46
+ type Tag struct {
45
47
FunctionName string
46
48
Kind string
47
49
Line int
@@ -58,7 +60,8 @@ type CTag struct {
58
60
PrototypeModifiers string
59
61
}
60
62
61
- func (p * CTagsParser ) Parse (ctagsOutput []byte , mainFile * paths.Path ) ([]* Prototype , int ) {
63
+ // Parse a ctags output and generates Prototypes
64
+ func (p * Parser ) Parse (ctagsOutput []byte , mainFile * paths.Path ) ([]* Prototype , int ) {
62
65
rows := strings .Split (string (ctagsOutput ), "\n " )
63
66
rows = removeEmpty (rows )
64
67
@@ -79,17 +82,17 @@ func (p *CTagsParser) Parse(ctagsOutput []byte, mainFile *paths.Path) ([]*Protot
79
82
return p .toPrototypes (), p .findLineWhereToInsertPrototypes ()
80
83
}
81
84
82
- func (p * CTagsParser ) addPrototypes () {
85
+ func (p * Parser ) addPrototypes () {
83
86
for _ , tag := range p .tags {
84
87
if ! tag .SkipMe {
85
88
addPrototype (tag )
86
89
}
87
90
}
88
91
}
89
92
90
- func addPrototype (tag * CTag ) {
91
- if strings .Index (tag .Prototype , TEMPLATE ) == 0 {
92
- if strings .Index (tag .Code , TEMPLATE ) == 0 {
93
+ func addPrototype (tag * Tag ) {
94
+ if strings .Index (tag .Prototype , keywordTemplate ) == 0 {
95
+ if strings .Index (tag .Code , keywordTemplate ) == 0 {
93
96
code := tag .Code
94
97
if strings .Contains (code , "{" ) {
95
98
code = code [:strings .Index (code , "{" )]
@@ -106,19 +109,19 @@ func addPrototype(tag *CTag) {
106
109
}
107
110
108
111
tag .PrototypeModifiers = ""
109
- if strings .Contains (tag .Code , STATIC + " " ) {
110
- tag .PrototypeModifiers = tag .PrototypeModifiers + " " + STATIC
112
+ if strings .Contains (tag .Code , keywordStatic + " " ) {
113
+ tag .PrototypeModifiers = tag .PrototypeModifiers + " " + keywordStatic
111
114
}
112
115
113
116
// Extern "C" modifier is now added in FixCLinkageTagsDeclarations
114
117
115
118
tag .PrototypeModifiers = strings .TrimSpace (tag .PrototypeModifiers )
116
119
}
117
120
118
- func (p * CTagsParser ) removeDefinedProtypes () {
121
+ func (p * Parser ) removeDefinedProtypes () {
119
122
definedPrototypes := make (map [string ]bool )
120
123
for _ , tag := range p .tags {
121
- if tag .Kind == KIND_PROTOTYPE {
124
+ if tag .Kind == kindPrototype {
122
125
definedPrototypes [tag .Prototype ] = true
123
126
}
124
127
}
@@ -133,7 +136,7 @@ func (p *CTagsParser) removeDefinedProtypes() {
133
136
}
134
137
}
135
138
136
- func (p * CTagsParser ) skipDuplicates () {
139
+ func (p * Parser ) skipDuplicates () {
137
140
definedPrototypes := make (map [string ]bool )
138
141
139
142
for _ , tag := range p .tags {
@@ -145,9 +148,9 @@ func (p *CTagsParser) skipDuplicates() {
145
148
}
146
149
}
147
150
148
- type skipFuncType func (tag * CTag ) bool
151
+ type skipFuncType func (tag * Tag ) bool
149
152
150
- func (p * CTagsParser ) skipTagsWhere (skipFunc skipFuncType ) {
153
+ func (p * Parser ) skipTagsWhere (skipFunc skipFuncType ) {
151
154
for _ , tag := range p .tags {
152
155
if ! tag .SkipMe {
153
156
skip := skipFunc (tag )
@@ -169,11 +172,11 @@ func removeSpacesAndTabs(s string) string {
169
172
return s
170
173
}
171
174
172
- func tagIsUnhandled (tag * CTag ) bool {
175
+ func tagIsUnhandled (tag * Tag ) bool {
173
176
return ! isHandled (tag )
174
177
}
175
178
176
- func isHandled (tag * CTag ) bool {
179
+ func isHandled (tag * Tag ) bool {
177
180
if tag .Class != "" {
178
181
return false
179
182
}
@@ -186,12 +189,12 @@ func isHandled(tag *CTag) bool {
186
189
return true
187
190
}
188
191
189
- func tagIsUnknown (tag * CTag ) bool {
190
- return ! KNOWN_TAG_KINDS [tag .Kind ]
192
+ func tagIsUnknown (tag * Tag ) bool {
193
+ return ! knownTagKinds [tag .Kind ]
191
194
}
192
195
193
- func parseTag (row string ) * CTag {
194
- tag := & CTag {}
196
+ func parseTag (row string ) * Tag {
197
+ tag := & Tag {}
195
198
parts := strings .Split (row , "\t " )
196
199
197
200
tag .FunctionName = parts [0 ]
0 commit comments