Skip to content

Commit e01f1f6

Browse files
committed
Allow END after rpc definitions when parsing, fixes #135
1 parent 44d3352 commit e01f1f6

File tree

7 files changed

+51
-10
lines changed

7 files changed

+51
-10
lines changed

ProtoBuf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@
538538
* @expose
539539
*/
540540
Tokenizer.prototype.peek = function() {
541-
if (this.stack.length == 0) {
541+
if (this.stack.length === 0) {
542542
var token = this.next();
543543
if (token === null) return null;
544544
this.stack.push(token);
@@ -948,6 +948,7 @@
948948
throw(new Error("Illegal start of option in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('option' expected)"));
949949
}
950950
} while (token !== Lang.CLOSE);
951+
if (this.tn.peek() === Lang.END) this.tn.next();
951952
} else if (token !== Lang.END) {
952953
throw(new Error("Illegal method delimiter in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' or '"+Lang.OPEN+"' expected)"));
953954
}

ProtoBuf.min.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ProtoBuf.min.map

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/ProtoBuf/DotProto/Parser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ ProtoBuf.DotProto.Parser = (function(ProtoBuf, Lang, Tokenizer) {
404404
throw(new Error("Illegal start of option in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('option' expected)"));
405405
}
406406
} while (token !== Lang.CLOSE);
407+
if (this.tn.peek() === Lang.END) this.tn.next();
407408
} else if (token !== Lang.END) {
408409
throw(new Error("Illegal method delimiter in RPC service "+svc["name"]+"#"+name+" at line "+this.tn.line+": "+token+" ('"+Lang.END+"' or '"+Lang.OPEN+"' expected)"));
409410
}

src/ProtoBuf/DotProto/Tokenizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ ProtoBuf.DotProto.Tokenizer = (function(Lang) {
173173
* @expose
174174
*/
175175
Tokenizer.prototype.peek = function() {
176-
if (this.stack.length == 0) {
176+
if (this.stack.length === 0) {
177177
var token = this.next();
178178
if (token === null) return null;
179179
this.stack.push(token);

tests/example5.proto

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package Datastore;
2+
3+
message LookupRequest {
4+
repeated string key = 1;
5+
}
6+
7+
message LookupResponse {
8+
repeated string results = 1;
9+
}
10+
11+
message RunQueryRequest {
12+
required string query = 1;
13+
}
14+
15+
message RunQueryResponse {
16+
repeated string results = 1;
17+
}
18+
19+
service LookupService {
20+
// Look up some entities by key.
21+
rpc Lookup(LookupRequest) returns (LookupResponse) {
22+
}
23+
}
24+
25+
service RunQueryService {
26+
// Query for entities.
27+
rpc RunQuery(RunQueryRequest) returns (RunQueryResponse) {
28+
};
29+
}

tests/suite.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@
219219
}
220220
test.done();
221221
},
222+
223+
"example5": function(test) {
224+
try {
225+
var builder = ProtoBuf.loadProtoFile(__dirname+"/example5.proto");
226+
builder.build();
227+
} catch(e) {
228+
fail(e);
229+
}
230+
test.done();
231+
},
222232

223233
"numberFormats": function(test) {
224234
try {

0 commit comments

Comments
 (0)