UNPKG

@whisklabs/grpc

Version:

gRPC generator and http library for typescript

73 lines 2.59 kB
import { next, setComment, writeComment } from '../comment'; import { Thrower } from '../thrower'; import { ParseMap } from './map'; import { InnerOptions } from './options'; export function ParseField(tokens, empty) { if (empty === void 0) { empty = false; } var field = { name: '', type: '', tag: -1, required: false, repeated: false, optional: false, options: {}, }; setComment(field); while (tokens.length > 0) { switch (next(tokens)) { case '=': tokens.shift(); field.tag = Number(tokens.shift()); break; case 'map': { var _a = 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(); writeComment(field); break; } case '[': field.options = InnerOptions(tokens); break; case ';': if (field.name === '') { throw new Thrower('field', [['Missing field name', 0]]); } if (field.type === '') { throw new Thrower('field', [["Missing type in message field: ".concat(field.name), 0]]); } if (field.tag === -1) { throw new 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; writeComment(field); } else { throw new Thrower('field', [["Unexpected token in message field: ".concat(tokens[0]), 0]]); } } } throw new Thrower('field', [['No ; found for message field', 0]]); } //# sourceMappingURL=field.js.map