How to use the parsimmon.seqMap 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 microsoft / dtslint / bin / rules / definitelytyped-header-parser.js View on Github external
function contributorsParser(strict) {
    // Need to remove '^' and '$' from the regex, parsimmon does not expect those.
    const contributor = strict
        ? pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/\/, 1), (name, username) => ({ name, url: "https://github.com/" + username }))
        : pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/<([^>]+)>/, 1), (name, url) => ({ name, url }));
    const contributors = pm.sepBy1(contributor, separator);
    if (!strict) {
        // Allow trailing whitespace.
        return pm.seqMap(contributors, pm.regexp(/ */), a => a);
    }
    return contributors;
}
// TODO: Should we do something with the URL?
github microsoft / dtslint / bin / rules / definitelytyped-header-parser.js View on Github external
function contributorsParser(strict) {
    // Need to remove '^' and '$' from the regex, parsimmon does not expect those.
    const contributor = strict
        ? pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/\/, 1), (name, username) => ({ name, url: "https://github.com/" + username }))
        : pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/<([^>]+)>/, 1), (name, url) => ({ name, url }));
    const contributors = pm.sepBy1(contributor, separator);
    if (!strict) {
        // Allow trailing whitespace.
        return pm.seqMap(contributors, pm.regexp(/ */), a => a);
    }
    return contributors;
}
// TODO: Should we do something with the URL?
github microsoft / dtslint / bin / rules / definitelytyped-header-parser.js View on Github external
function headerParser(strict) {
    return pm.seqMap(pm.string("// Type definitions for "), parseLabel(strict), pm.string("// Project: "), projectParser, pm.regexp(/\r?\n\/\/ Definitions by: /), contributorsParser(strict), definitionsParser, typeScriptVersionParser, pm.all, // Don't care about the rest of the file
    // tslint:disable-next-line:variable-name
    (_str, label, _project, projects, _defsBy, contributors, _definitions, typeScriptVersion) => ({
        libraryName: label.name,
        libraryMajorVersion: label.major,
        libraryMinorVersion: label.minor,
        projects, contributors, typeScriptVersion,
    }));
}
/*
github keean / zenscript / src / parse.js View on Github external
const assignment = P.seqMap(
   assignKeyword.then(typedVariable).skip(assign),
   expression,
   (v, e) => {
      return new AST.Declaration(v, e)
   }
)

// return
const returnKeyword = P.string('return')
const rtn = returnKeyword.then(space).then(expression).map((exp) => {
   return new AST.Return(exp)
})

// defineFunction = identifier, '(', arg_list, ')', optTypeAnnotation, '=>', (expression | NL, block)
const defineFunction = P.seqMap(
   identifier,
   inParenthesis(typedArgList),
   optTypeAnnotation.skip(fat_arrow),
   block.or(expression.map((e) => {return new AST.Return(e)})),
   (name, args, optReturnType, body) => {
      const v = new AST.Variable(name)
      if (optReturnType !== undefined) {
         v.userType = optReturnType
      }
      return new AST.Declaration(v, new AST.Fn(name, args, body))
   }
)

// statement = return | defineFunction | assignment | expression
const statement = rtn.or(defineFunction).or(assignment).or(expression) // .skip(exp_space)
github ant-move / Antmove / packages / @antmove / wx-alipay-plugin / parse / parseWxml.js View on Github external
OpeningElement: function (r) {
        return P.seqMap(
            lTagArrow,
            r.Symbol,
            whitespaces,
            Wxml.Attribute.many(),
            whitespaces,
            rTagArrow,
            Wxml.Element.atLeast(1)
                .or(Wxml.StringExpression.or(whitespaces)),
            lTagArrow,
            whitespaces,
            endLine,
            r.Symbol,
            whitespaces,
            rTagArrow,
            function (r1, r2, r3, r4, r5, r6, r7) {
                let _prop = {};
github youknowriad / averroes / scripts / editor / api / parser.js View on Github external
blockheader() {
    return P.seqMap(
      P.string("{%")
        .then(P.whitespace)
        .then(P.string("name="))
        .then(P.regex(/[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*/))
        .skip(P.whitespace),
      JSONParser.value.trim(P.optWhitespace).skip(P.string("%}")),
      (name, attributes) => ({
        name,
        attributes
      })
    );
  },
  blockfooter() {
github ant-move / Antmove / packages / @antmove / wx-alipay-plugin / parse / parseWxml.js View on Github external
newComment: function (r) {
        let anyString = P.any.notFollowedBy(P.seqMap(
            P.any,
            P.string('-->')
        ), function (...r) {
            return r.join('');
        });

        return P.seqMap(
            P.string(''),
            function (...r) {
                r[2] = r[2].join('');
                return {
                    typeof: 'wxml.Element',
github ant-move / Antmove / packages / @antmove / wx-alipay-plugin / parse / parseWxml.js View on Github external
ClosingElement: function (r) {
        return P.seqMap(
            lTagArrow,
            r.Symbol,
            whitespaces,
            Wxml.Attribute.many(),
            whitespaces,
            endLine,
            rTagArrow,
            function (r1, r2, r3, r4, r5, r6, r7) {
                let _prop = {};
                r4.forEach(function (el) {
                    _prop[el[0]] = el[1];
                });

                return {
                    typeof: 'wxml.element',
                    key: null,
github youknowriad / averroes / scripts / editor / api / parser.js View on Github external
image() {
    return P.seqMap(
      P.regex(/[^\]\r\n]*/).wrap(P.string("!["), P.string("]")),
      P.regex(/[^)\r\n]+/).wrap(P.string("("), P.string(")")),
      (text, link) => ({
        type: "img",
        props: {
          src: link,
          alt: text
        }
      })
    );
  },
  code(r) {