@whisklabs/grpc
Version:
gRPC generator and http library for typescript
77 lines • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParseField = void 0;
var comment_1 = require("../comment");
var thrower_1 = require("../thrower");
var map_1 = require("./map");
var options_1 = require("./options");
function ParseField(tokens, empty) {
if (empty === void 0) { empty = false; }
var field = {
name: '',
type: '',
tag: -1,
required: false,
repeated: false,
optional: false,
options: {},
};
(0, comment_1.setComment)(field);
while (tokens.length > 0) {
switch ((0, comment_1.next)(tokens)) {
case '=':
tokens.shift();
field.tag = Number(tokens.shift());
break;
case 'map': {
var _a = (0, map_1.ParseMap)(tokens), type = _a.type, map = _a.map, name_1 = _a.name;
field.type = type;
field.map = map;
field.name = name_1;
break;
}
case 'repeated':
case 'required':
case 'optional': {
var t = tokens.shift();
field.required = t === 'required';
field.repeated = t === 'repeated';
field.optional = t === 'optional';
field.type = tokens.shift();
field.name = tokens.shift();
(0, comment_1.writeComment)(field);
break;
}
case '[':
field.options = (0, options_1.InnerOptions)(tokens);
break;
case ';':
if (field.name === '') {
throw new thrower_1.Thrower('field', [['Missing field name', 0]]);
}
if (field.type === '') {
throw new thrower_1.Thrower('field', [["Missing type in message field: ".concat(field.name), 0]]);
}
if (field.tag === -1) {
throw new thrower_1.Thrower('field', [["Missing tag number in message field: ".concat(field.name), 0]]);
}
tokens.shift();
return field;
case undefined:
continue;
default:
if (empty) {
field.type = tokens.shift();
field.name = tokens.shift();
empty = false;
(0, comment_1.writeComment)(field);
}
else {
throw new thrower_1.Thrower('field', [["Unexpected token in message field: ".concat(tokens[0]), 0]]);
}
}
}
throw new thrower_1.Thrower('field', [['No ; found for message field', 0]]);
}
exports.ParseField = ParseField;
//# sourceMappingURL=field.js.map