Skip to content

Commit

Permalink
CLI: Also accept (trailing) triple-slash comments for compatibility w…
Browse files Browse the repository at this point in the history
…ith protoc-gen-doc, see #640
  • Loading branch information
dcodeIO committed Jan 13, 2017
1 parent 9e360ea commit d4272db
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 100 deletions.
2 changes: 1 addition & 1 deletion dist/noparse/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/noparse/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/noparse/protobuf.min.js.gz
Binary file not shown.
104 changes: 59 additions & 45 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/runtime/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/runtime/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/runtime/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ type RPCCallback = (error: Error, responseData?: Uint8Array) => void;
* @property {function():?string} peek Peeks for the next token (`null` on eof)
* @property {function(string)} push Pushes a token back to the stack
* @property {function(string, boolean=):boolean} skip Skips a token, returns its presence and advances or, if non-optional and not present, throws
* @property {function():?string} cmnt Gets the comment on the previous line, if any
* @property {function(number=):?string} cmnt Gets the comment on the previous line or the line comment on the specified line, if any
*/
type TokenizerHandle = { [k: string]: any };

Expand Down
37 changes: 24 additions & 13 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,12 @@ function parse(source, root, options) {
throw illegal(name, "name");
name = applyCase(name);
skip("=");
var field = new Field(name, parseId(next()), type, rule, extend);
var field = new Field(name, parseId(next()), type, rule, extend),
trailingLine = tn.line();
field.comment = cmnt();
parseInlineOptions(field);
if (!field.comment)
field.comment = cmnt(trailingLine);
// JSON defaults to packed=true if not set so we have to set packed=false explicity when
// parsing proto2 descriptors without the option, where applicable.
if (field.repeated && types.packed[type] !== undefined && !isProto3)
Expand Down Expand Up @@ -378,15 +381,12 @@ function parse(source, root, options) {

name = applyCase(name);
skip("=");
var id = parseId(next());
var field = new MapField(name, id, keyType, valueType);
var line = tn.line();
var field = new MapField(name, parseId(next()), keyType, valueType),
trailingLine = tn.line();
field.comment = cmnt();
parseInlineOptions(field);
if (!field.comment) {
peek();
field.comment = cmnt(/* if on */ line);
}
if (!field.comment)
field.comment = cmnt(trailingLine);
parent.add(field);
}

Expand All @@ -398,7 +398,8 @@ function parse(source, root, options) {
throw illegal(name, "name");

name = applyCase(name);
var oneof = new OneOf(name);
var oneof = new OneOf(name),
trailingLine = tn.line();
oneof.comment = cmnt();
if (skip("{", true)) {
while ((token = next()) !== "}") {
Expand All @@ -411,8 +412,11 @@ function parse(source, root, options) {
}
}
skip(";", true);
} else
} else {
skip(";");
if (!oneof.comment)
oneof.comment = cmnt(trailingLine);
}
parent.add(oneof);
}

Expand Down Expand Up @@ -447,9 +451,12 @@ function parse(source, root, options) {

var name = token;
skip("=");
var value = parseId(next(), true);
var value = parseId(next(), true),
trailingLine = tn.line();
parent.add(name, value, cmnt());
parseInlineOptions({}); // skips enum value options
if (!parent.comments[name])
parent.comments[name] = cmnt(trailingLine);
}

function parseOption(parent, token) {
Expand Down Expand Up @@ -568,7 +575,8 @@ function parse(source, root, options) {

responseType = token;
skip(")");
var method = new Method(name, type, requestType, responseType, requestStream, responseStream);
var method = new Method(name, type, requestType, responseType, requestStream, responseStream),
trailingLine = tn.line();
method.comment = cmnt();
if (skip("{", true)) {
while ((token = next()) !== "}") {
Expand All @@ -585,8 +593,11 @@ function parse(source, root, options) {
}
}
skip(";", true);
} else
} else {
skip(";");
if (!method.comment)
method.comment = cmnt(trailingLine);
}
parent.add(method);
}

Expand Down
Loading

0 comments on commit d4272db

Please sign in to comment.