How to use the parsimmon.seq 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 squiggle-lang / squiggle-lang / src / parse / pattern-factory.js View on Github external
ione(ast.PatternObject,
      wrap("{", list0(ps.Separator, PatternObjectPair), "}"));

  var PatternArrayStrict =
    ione(ast.PatternArray,
      wrap("[", list0(ps.Separator, Pattern), "]"));

  var BareSlurp =
    ione(ast.PatternSimple,
      ione(ast.Identifier, P.of("_")));

  var PatternArraySlurpy =
    iseq(ast.PatternArraySlurpy,
      wrap(
        "[",
        P.seq(
          Pattern.skip(ps.Separator).many(),
          word("...").then(Pattern.or(BareSlurp))
        ),
        "]"
      ));

  var PatternArray =
    P.alt(
      PatternArrayStrict,
      PatternArraySlurpy
    );

  return Pattern;
}
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / castType.js View on Github external
)
            .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,
                r.lengthSpec.atMost(1).map(data => !data.length ? '' : data[0])
            )
            .tie(),
        Pa
            .seq(
                r.DECIMAL,
                Pa
                    .alt(
github golopot / tex-to-unicode / lib / parser.js View on Github external
Subscript: () =>
    Parsimmon.seq(
      Parsimmon.regexp(/_\s*/),
      Parsimmon.alt(
        Parsimmon.regexp(/{[a-zA-Z0-9+-]+}/),
        Parsimmon.regexp(/[a-zA-Z0-9+-]/)
      )
    ).map(([a, b]) => a + b),
github squiggle-lang / squiggle-lang / src / parse / match.js View on Github external
module.exports = function(ps) {
  var emptyPattern =
    ione(ast.PatternSimple,
      ione(ast.Identifier, P.of("_")));
  var NormalClause =
    P.seq(
      keyword("case").then(_).then(ps.MatchPattern),
      _.then(keyword("then").then(_)).then(ps.Block)
    );
  var ElseClause =
    P.seq(
      emptyPattern,
      _.then(keyword("else").then(_)).then(ps.Block)
    );
  var MatchClause =
    iseq(ast.MatchClause, NormalClause.or(ElseClause));
  return iseq(ast.Match,
    P.seq(
      keyword("match").then(_).then(ps.BinExpr),
      _.then(MatchClause).atLeast(1)
        .skip(_)
        .skip(keyword("end"))
    ));
};
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / booleanExpressions / castType.js View on Github external
.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()
                    .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
github squiggle-lang / squiggle-lang / src / parse / function.js View on Github external
module.exports = function(ps) {
  var OptionalName = ps.Identifier.or(P.of(null));
  return iseq(ast.Function,
    P.seq(
      keyword("fn").then(_).then(OptionalName).skip(_),
      wrap("(", ps.Parameters, ")").skip(_),
      ps.Expr
    ));
};
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 kantord / emuto / src / parsers / abstract / binaryOperator.js View on Github external
P.lazy((): mixed => {
    const OperatorParser_ = OperatorParser.node('primitive')
    return P.seq(
      OperandParser,
      P.seq(crap.then(OperatorParser_), crap.then(OperandParser)).many()
    )
      .map(
        (value: [NodeType, Array]): NodeType =>
          value[1].length > 0
            ? {
              name: 'binaryOperation',
              value: value[1].reduce(
                (a: Array, b: NodeType): Array =>
                  a.concat(b),
                [value[0]]
              )
            }
            : value[0]
      )
      .desc(description)
  })
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / index.js View on Github external
STRING_SQ (r) {
            return Pa
                .seq(
                    Pa.string("'"),
                    Pa.alt(r.SCHAR, Pa.string('"'), r.ESCAPED_SQ, r.ESCAPED_ESCAPE_CHAR).many().tie(),
                    Pa.string("'")
                )
                .tie();
        },
github squiggle-lang / squiggle-lang / src / parse / if.js View on Github external
module.exports = function(ps) {
  var ElseIf = iseq(ast.ElseIf,
    P.seq(
      keyword("elseif").then(_).then(ps.Expr).skip(_),
      keyword("then").then(_).then(ps.Block).skip(_)
    ));
  return iseq(ast.If,
    P.seq(
      keyword("if").then(_).then(ps.Expr).skip(_),
      keyword("then").then(_).then(ps.Block).skip(_),
      ElseIf.many(),
      keyword("else").then(_).then(ps.Block).skip(_)
        .skip(keyword("end"))
    ));
};