How to use the parsimmon.sepBy1 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
}
/*
Allow any of the following:

// Project: https://foo.com
//          https://bar.com

// Project: https://foo.com,
//          https://bar.com

// Project: https://foo.com, https://bar.com

Use `\s\s+` to ensure at least 2 spaces, to  disambiguate from the next line being `// Definitions by:`.
*/
const separator = pm.regexp(/(, )|(,?\r?\n\/\/\s\s+)/);
const projectParser = pm.sepBy1(pm.regexp(/[^,\r\n]+/), separator);
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?
const definitionsParser = pm.regexp(/\r?\n\/\/ Definitions: [^\r\n]+/);
function parseLabel(strict) {
    return pm.Parser((input, index) => {
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 sider / TyScan / dist / pattern / parser.js View on Github external
    Term: L => P.sepBy1(L.Factor, L.AND).trim(P.optWhitespace)
        .map(r => new node.Term(r)),
    Factor: L => P.seq(L.Call, L.TypeAnnotation.times(0, 1)).trim(P.optWhitespace)
github sider / TyScan / src / typePattern / parser.ts View on Github external
  IntersectionType: L => P.sepBy1(L.ArrayType, L.AND)
    .map(r => new node.IntersectionType(r)),
github sider / TyScan / src / pattern / parser.ts View on Github external
  Expression: L => P.sepBy1(L.Term, L.OR).trim(P.optWhitespace)
    .map(r => new node.Expression(r)),
github sider / TyScan / src / typePattern / parser.ts View on Github external
  TypeArgs: L => P.sepBy1(L.Type, L.COMMA).wrap(L.LT, L.GT),
github sider / TyScan / src / pattern / parser.ts View on Github external
  Term: L => P.sepBy1(L.Factor, L.AND).trim(P.optWhitespace)
    .map(r => new node.Term(r)),
github sider / TyScan / src / typePattern / parser.ts View on Github external
  UnionType: L => P.sepBy1(L.IntersectionType, L.OR)
    .map(r => new node.UnionType(r)),
github sider / TyScan / dist / pattern / parser.js View on Github external
    Expression: L => P.sepBy1(L.Term, L.OR).trim(P.optWhitespace)
        .map(r => new node.Expression(r)),
    Term: L => P.sepBy1(L.Factor, L.AND).trim(P.optWhitespace)