UNPKG

@whisklabs/grpc

Version:

gRPC generator and http library for typescript

64 lines 2.01 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'; export function ParseRPC(tokens) { var _a = check({ type: 'rpc', tokens: tokens, rules: [ ch('rpc'), ch(isText, { result: true }), ch('('), ch('stream', { ignore: true, result: true }), ch(isText, { result: true }), ch(')'), ch('returns'), ch('('), ch('stream', { ignore: true, result: true }), ch(isText, { result: true }), ch(')'), ], }), results = _a.results, len = _a.len; cut(tokens, len); var rpc = { name: results[0], inputType: results[2], outputType: results[4], clientStreaming: results[1] === 'stream', serverStreaming: results[3] === 'stream', options: {}, }; setComment(rpc); if (tokens[0] === ';') { tokens.shift(); return rpc; } check({ type: 'rpc', tokens: [tokens[0], tokens[tokens.indexOf('}')]], rules: [ch('{'), ch('}')], }); tokens.shift(); while (tokens.length > 0) { switch (next(tokens)) { case '}': cut(tokens, 1); semicolon(tokens); writeComment(rpc); return rpc; case 'option': { var _b = ParseOptions(tokens), field = _b.field, value = _b.value; insertOption(rpc.options, field, value); break; } case undefined: continue; default: throw new Thrower('rpc', [["Unexpected token \"".concat(tokens[0], "\""), 0]]); } } throw new Thrower('rpc', [['no close tag "}"', 0]]); } //# sourceMappingURL=rpc.js.map