How to use the parsimmon.whitespace 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 zubairq / pilot / public / simpleSqlParser.js View on Github external
},{}],6:[function(require,module,exports){
'use strict';
var Parsimmon = require('parsimmon');

/********************************************************************************************
	ALIASES
********************************************************************************************/

var seq = Parsimmon.seq;
var alt = Parsimmon.alt;
var regex = Parsimmon.regex;
var string = Parsimmon.string;
var optWhitespace = Parsimmon.optWhitespace;
var whitespace = Parsimmon.whitespace;
var lazy = Parsimmon.lazy;



/********************************************************************************************
	COMMON PATTERNS
********************************************************************************************/

// Make a parser optionnal
// "empty" parameter will be returned as result if the optionnal parser can't match
function opt(parser, empty) {
	if (typeof empty == 'undefined') return parser.or(Parsimmon.succeed([]));
	return parser.or(Parsimmon.succeed(empty));
}

// Join results of a parser
github dsferruzza / simpleSqlParser / src / sql2ast.js View on Github external
'use strict';
var Parsimmon = require('parsimmon');

/********************************************************************************************
	ALIASES
********************************************************************************************/

var seq = Parsimmon.seq;
var alt = Parsimmon.alt;
var regex = Parsimmon.regex;
var string = Parsimmon.string;
var optWhitespace = Parsimmon.optWhitespace;
var whitespace = Parsimmon.whitespace;
var lazy = Parsimmon.lazy;



/********************************************************************************************
	COMMON PATTERNS
********************************************************************************************/

// Make a parser optionnal
// "empty" parameter will be returned as result if the optionnal parser can't match
function opt(parser, empty) {
	if (typeof empty == 'undefined') return parser.or(Parsimmon.succeed([]));
	return parser.or(Parsimmon.succeed(empty));
}

// Join results of a parser
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / castOp.js View on Github external
const parser = options => r => Pa
    .seq(
        r.CAST,
        Pa.string('('),
        Pa.optWhitespace,
        r.expr.map(data => data.output),
        Pa.whitespace,
        r.AS,
        Pa.whitespace,
        r.castType,
        Pa.optWhitespace,
        Pa.string(')')
    )
    .map(data => {
        const operator = new Operator();
        operator.setName(data[0]);
        operator.addParam(data[3]);
        operator.addParam(data[7]);

        const expr = new Expr();
        expr.setType(Expr.Type.OPERATOR);
        expr.setOperator(operator);

        return expr;
    });
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / castType.js View on Github external
Pa
                    .seq(
                        Pa.whitespace,
                        r.INTEGER
                    )
                    .tie()
                    .atMost(1)
                    .map(data => !data.length ? '' : data[0])
            )
            .tie(),
        Pa
            .seq(
                r.UNSIGNED,
                Pa
                    .seq(
                        Pa.whitespace,
                        r.INTEGER
                    )
                    .tie()
                    .atMost(1)
                    .map(data => !data.length ? '' : data[0])
            )
            .tie(),
        Pa
            .seq(
                r.CHAR,
                r.lengthSpec.atMost(1).map(data => !data.length ? '' : data[0])
            )
            .tie(),
        Pa
            .seq(
                r.BINARY,
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / projectedSearchExpr.js View on Github external
const parser = options => r => Pa
    .seq(
        r.expr
            .map(data => data),
        Pa
            .seq(Pa.whitespace, r.AS, Pa.whitespace, r.ident)
            .map(data => data[3])
            .atMost(1)
            .map(data => data[0])
    )
    .map(data => {
        const projection = new Crud.Projection();
        projection.setSource(data[0].output);

        if (data[1]) {
            projection.setAlias(data[1]);
        } else {
            projection.setAlias(data[0].input);
        }

        return { input: options.input, output: projection };
    });
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / orExpr.js View on Github external
const parser = options => r => Pa
    .seq(
        r.andExpr,
        Pa
            .seq(Pa.whitespace, r.OR, Pa.whitespace, r.andExpr)
            .map(data => ({ operand: data[3], operator: data[1] }))
            .many()
    )
    .map(binaryOpMapper);
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / sortExpr.js View on Github external
const parser = options => r => Pa
    .seq(
        r.expr
            .map(data => data.output),
        Pa
            .seq(Pa.whitespace, Pa.alt(r.ASC, r.DESC))
            .map(data => data[1])
            .atMost(1)
            .map(data => data[0])
    )
    .map(data => {
        const order = new Crud.Order();
        order.setExpr(data[0]);

        if (data[1]) {
            order.setDirection(data[1]);
        }

        return { input: options.input, output: order };
    });
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / castType.js View on Github external
const parser = options => r => Pa
    .alt(
        Pa
            .seq(
                r.SIGNED,
                Pa
                    .seq(
                        Pa.whitespace,
                        r.INTEGER
                    )
                    .tie()
                    .atMost(1)
                    .map(data => !data.length ? '' : data[0])
            )
            .tie(),
        Pa
            .seq(
                r.UNSIGNED,
                Pa
                    .seq(
                        Pa.whitespace,
                        r.INTEGER
                    )
                    .tie()