Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"use strict";
/* Parser combinator based parser for the
* protobuf text format.
*/
var Parsimmon = require('parsimmon');
var regex = Parsimmon.regex
, string = Parsimmon.string
, optWhitespace = Parsimmon.optWhitespace
, lazy = Parsimmon.lazy
, alt = Parsimmon.alt
, seq = Parsimmon.seq;
var comment = regex(/#.+/).then(optWhitespace.atMost(1));
var whitespace = optWhitespace.then(comment.atMost(1));
var lexeme = function(p){ return p.skip(whitespace); }
var colon = lexeme(string(':'));
var lbrace = lexeme(string('{'))
, rbrace = lexeme(string('}'));
var stripFirstLast = function(x) {
return x.substr(1, x.length-2);
const parser = options => r => Pa
.seq(
Pa.string('('),
Pa.optWhitespace,
r.expr.map(data => data.output),
Pa.optWhitespace,
Pa.string(')')
)
.map(data => data[2]);
RBRACE: _ => P.string('}').trim(P.optWhitespace),
DOTS: _ => P.string('...').trim(P.optWhitespace).map(_ => undefined),
const parser = options => r => Pa
.seq(Pa.string('('), Pa.optWhitespace, r.INT, Pa.optWhitespace, Pa.string(')'))
.tie();
const parser = options => r => Pa
.seq(
r.shiftExpr,
Pa
.seq(
Pa.optWhitespace,
Pa.alt(Pa.string('&'), Pa.string('|'), Pa.string('^')),
Pa.optWhitespace,
r.shiftExpr
)
.map(data => ({ operand: data[3], operator: data[1] }))
.many()
)
.map(binaryOpMapper);
const parser = options => r => Pa
.seq(
r.STRING_DQ,
Pa.optWhitespace,
Pa.string(':'),
Pa.optWhitespace,
r.expr.map(data => data.output)
)
.map(data => {
const objectField = new Expr.Object.ObjectField();
objectField.setKey(data[0].slice(1, data[0].length - 1));
objectField.setValue(data[4]);
return objectField;
});
const parser = options => r => Pa
.seq(
Pa.string('('),
Pa.optWhitespace,
r.expr.map(data => data.output),
Pa.optWhitespace,
Pa.string(')')
)
.map(data => data[2]);
const parser = options => r => Pa
.seq(
r.addSubExpr,
Pa
.seq(
Pa.optWhitespace,
Pa.alt(Pa.string('<<'), Pa.string('>>')),
Pa.optWhitespace,
r.addSubExpr
)
.map(data => ({ operand: data[3], operator: data[1] }))
.many()
)
.map(binaryOpMapper);
const parser = options => r => Pa
.seq(
Pa.string('['),
Pa.optWhitespace,
Pa
.seq(
r.expr.map(data => data.output),
Pa
.seq(Pa.optWhitespace, Pa.string(','), Pa.optWhitespace, r.expr.map(data => data.output))
.map(data => data[3])
.many()
)
.map(data => [data[0]].concat(data[1]))
.atMost(1)
.map(data => data[0]),
Pa.optWhitespace,
Pa.string(']')
)
.map(data => {
const array = new Expr.Array();
const items = data[2] || [];
items.forEach(any => {
array.addValue(any);
});
const parser = options => r => Pa
.seq(
r.intervalExpr,
Pa
.seq(
Pa.optWhitespace,
Pa.alt(Pa.string('*'), r.DIV, Pa.string('/'), Pa.string('%')),
Pa.optWhitespace,
r.intervalExpr
)
.map(data => ({ operand: data[3], operator: data[1] }))
.many()
)
.map(binaryOpMapper);