UNPKG

@whisklabs/grpc

Version:

gRPC generator and http library for typescript

44 lines 1.48 kB
import { next, setComment, writeComment } from '../comment'; import { Thrower } from '../thrower'; import { ch, check, cut, insertOption, semicolon } from '../utils'; import { isText } from '../validators'; import { ParseOptions } from './options'; import { ParseRPC } from './rpc'; export function ParseService(tokens) { var _a = check({ type: 'service', tokens: tokens, rules: [ch('service'), ch(isText, { result: true }), ch('{')], }), results = _a.results, len = _a.len; cut(tokens, len); var service = { name: results[0], methods: [], options: {}, }; setComment(service); while (tokens.length > 0) { if (tokens[0] === '}') { tokens.shift(); semicolon(tokens); writeComment(service); return service; } switch (next(tokens)) { case 'option': { var _b = ParseOptions(tokens), field = _b.field, value = _b.value; insertOption(service.options, field, value); break; } case 'rpc': service.methods.push(ParseRPC(tokens)); break; case undefined: continue; default: throw new Thrower('rpc', [["Unexpected token in service: ".concat(tokens[0]), 0]]); } } throw new Thrower('rpc', [['no close tag "}"', 0]]); } //# sourceMappingURL=service.js.map