@whisklabs/grpc
Version:
gRPC generator and http library for typescript
64 lines • 2.15 kB
JavaScript
import { next, writeComment } from '../comment';
import { Thrower } from '../thrower';
import { ch, check, cut, insertOption, semicolon } from '../utils';
import { isNumber, isText } from '../validators';
import { InnerOptions, ParseOptions } from './options';
import { ParseReserved } from './reserved';
export function EnumVal(tokens) {
var results = check({
type: 'enum value',
tokens: tokens.slice(0, 4).concat(tokens[tokens.indexOf(';')]),
rules: [ch(isText, { result: true }), ch('='), ch(isNumber, { result: true }), ch([';', '[']), ch([';'])],
}).results;
cut(tokens, 3);
var options = tokens[0] === '[' ? InnerOptions(tokens) : {};
cut(tokens, 1);
return {
name: results[0],
value: {
value: Number(results[1]),
options: options,
},
};
}
export function ParseEnums(tokens) {
var results = check({
type: 'enum',
tokens: tokens.slice(0, 3).concat(tokens[tokens.indexOf('}')]),
rules: [ch('enum'), ch(isText, { result: true }), ch('{'), ch('}')],
}).results;
var en = {
name: results[0],
values: {},
options: {},
reserved: [],
};
writeComment(en);
cut(tokens, 3);
while (tokens.length > 0) {
switch (next(tokens)) {
case '}':
cut(tokens, 1);
semicolon(tokens);
writeComment(en);
return en;
case 'option': {
var _a = ParseOptions(tokens), field = _a.field, value = _a.value;
insertOption(en.options, field, value);
break;
}
case 'reserved':
en.reserved.push(ParseReserved(tokens));
break;
case undefined:
continue;
default: {
var _b = EnumVal(tokens), name_1 = _b.name, value = _b.value;
en.values[name_1] = value;
writeComment(en.values[name_1]);
}
}
}
throw new Thrower('enum', [['no close tag "}"', 0]]);
}
//# sourceMappingURL=enums.js.map