Skip to content

Commit e901a6d

Browse files
author
Anthony Romano
authored
Merge pull request #6 from heyitsanthony/flush-comments
parse: flush comment slice when current line is not a comment
2 parents f4164b1 + 2d5fece commit e901a6d

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

parse/parse.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ func ReadFile(fpath string) (*Proto, error) {
134134
comments = append(comments, strings.TrimSpace(ls))
135135
continue
136136
}
137+
emitComments := comments
138+
comments = []string{}
137139

138140
// skippin enum
139141
if strings.HasPrefix(line, "enum ") {
@@ -187,14 +189,12 @@ func ReadFile(fpath string) (*Proto, error) {
187189
switch mode {
188190
case parsingMessage: // message Name
189191
protoMessage.Name = strings.Replace(elem, "{", "", -1)
190-
protoMessage.Description = strings.Join(comments, " ")
191-
comments = []string{} // reset
192+
protoMessage.Description = strings.Join(emitComments, " ")
192193
protoMessage.Fields = []ProtoField{} // reset
193194

194195
case parsingService: // service Name
195196
protoService.Name = strings.Replace(elem, "{", "", -1)
196-
protoService.Description = strings.Join(comments, " ")
197-
comments = []string{} // reset
197+
protoService.Description = strings.Join(emitComments, " ")
198198
protoService.Methods = []ProtoMethod{} // reset
199199
}
200200
}
@@ -205,7 +205,6 @@ func ReadFile(fpath string) (*Proto, error) {
205205
protoMessage.FilePath = fs
206206
rp.Messages = append(rp.Messages, protoMessage)
207207
protoMessage = ProtoMessage{}
208-
comments = []string{}
209208
mode = reading
210209
continue
211210
}
@@ -227,9 +226,8 @@ func ReadFile(fpath string) (*Proto, error) {
227226
}
228227

229228
protoField.Name = fds[1]
230-
protoField.Description = strings.Join(comments, " ")
229+
protoField.Description = strings.Join(emitComments, " ")
231230
protoMessage.Fields = append(protoMessage.Fields, protoField)
232-
comments = []string{}
233231

234232
case parsingService:
235233
// parse 'rpc Watch(stream WatchRequest) returns (stream WatchResponse) {}'
@@ -253,15 +251,13 @@ func ReadFile(fpath string) (*Proto, error) {
253251
protoMethod.Name = f1
254252
protoMethod.RequestType = f2
255253
protoMethod.ResponseType = f3
256-
protoMethod.Description = strings.Join(comments, " ")
254+
protoMethod.Description = strings.Join(emitComments, " ")
257255
protoService.Methods = append(protoService.Methods, protoMethod)
258-
comments = []string{}
259256
} else if !strings.HasSuffix(line, "{}") && strings.HasSuffix(line, "}") {
260257
// end of service
261258
protoService.FilePath = fs
262259
rp.Services = append(rp.Services, protoService)
263260
protoService = ProtoService{}
264-
comments = []string{}
265261
mode = reading
266262
}
267263
}

parse/testdata/README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
this is test...
2-
3-
41
### etcdserverpb
52

63

@@ -38,8 +35,6 @@ this is test...
3835

3936
##### service `KV` (testdata/rpc.proto)
4037

41-
for grpc-gateway
42-
4338
| Method | Request Type | Response Type | Description |
4439
| ------ | ------------ | ------------- | ----------- |
4540
| Range | RangeRequest | RangeResponse | Range gets the keys in the range from the key-value store. |
@@ -91,8 +86,6 @@ for grpc-gateway
9186

9287
##### message `AlarmRequest` (testdata/rpc.proto)
9388

94-
default, used to query if any alarm is active space quota is exhausted
95-
9689
| Field | Description | Type | Go | Java | Python | C++ |
9790
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
9891
| action | action is the kind of alarm request to issue. The action may GET alarm statuses, ACTIVATE an alarm, or DEACTIVATE a raised alarm. | AlarmAction | | | | |
@@ -635,7 +628,7 @@ Empty field.
635628

636629
| Field | Description | Type | Go | Java | Python | C++ |
637630
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
638-
| key | default, no sorting lowest target value first highest target value first key is the first key for the range. If range_end is not given, the request only looks up key. | bytes | []byte | ByteString | str | string |
631+
| key | key is the first key for the range. If range_end is not given, the request only looks up key. | bytes | []byte | ByteString | str | string |
639632
| range_end | range_end is the upper bound on the requested range [key, range_end). If range_end is '\0', the range is all keys >= key. If the range_end is one bit larger than the given key, then the range requests get the all keys with the prefix (the given key). If both key and range_end are '\0', then range requests returns all keys. | bytes | []byte | ByteString | str | string |
640633
| limit | limit is a limit on the number of keys returned for the request. | int64 | int64 | long | int/long | int64 |
641634
| revision | revision is the point-in-time of the key-value store to use for the range. If revision is less or equal to zero, the range is over the newest key-value store. If the revision has been compacted, ErrCompacted is returned as a response. | int64 | int64 | long | int/long | int64 |

0 commit comments

Comments
 (0)