How to use the parsimmon.optWhitespace function in parsimmon

To help you get started, we’ve selected a few parsimmon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brotchie / protobuf-textformat / src / parser.js View on Github external
"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);
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / groupedExpr.js View on Github external
const parser = options => r => Pa
    .seq(
        Pa.string('('),
        Pa.optWhitespace,
        r.expr.map(data => data.output),
        Pa.optWhitespace,
        Pa.string(')')
    )
    .map(data => data[2]);
github sider / TyScan / dist / pattern / type / parser.js View on Github external
    RBRACE: _ => P.string('}').trim(P.optWhitespace),
    DOTS: _ => P.string('...').trim(P.optWhitespace).map(_ => undefined),
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / lengthSpec.js View on Github external
const parser = options => r => Pa
    .seq(Pa.string('('), Pa.optWhitespace, r.INT, Pa.optWhitespace, Pa.string(')'))
    .tie();
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / bitExpr.js View on Github external
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);
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / jsonKeyValue.js View on Github external
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;
    });
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / groupedExpr.js View on Github external
const parser = options => r => Pa
    .seq(
        Pa.string('('),
        Pa.optWhitespace,
        r.expr.map(data => data.output),
        Pa.optWhitespace,
        Pa.string(')')
    )
    .map(data => data[2]);
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / shiftExpr.js View on Github external
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);
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / jsonArray.js View on Github external
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);
        });
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / mulDivExpr.js View on Github external
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);