How to use the parsimmon.makeFailure 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 osnr / livegb / lib / assembler / index.ts View on Github external
return Parsimmon(function(input: string, i: number) {
    for (let len = 4; len >= 1; len--) {
      const instr = input.slice(i, i + len);
      if (instr in opTable) {
        return Parsimmon.makeSuccess(i + len, opTable[instr]);
      }
    }
    return Parsimmon.makeFailure(i, 'wut');
    // Chain here is an interesting trick to choose parser at parse time.
  }).chain((afterParsers: Parser[]) => alt.apply(alt, afterParsers) as any as Parser);
})();
github mysql / mysql-connector-nodejs / lib / ExprParser / lib / grammar / keywords.js View on Github external
const ignoreCase = str => Pa((input, i) => {
    const j = i + str.length;
    const head = input.slice(i, j);

    if (head.toLowerCase() === str.toLowerCase()) {
        return Pa.makeSuccess(j, head);
    }

    // wrap the expected value in single-quotes to fit the underlying Parsimmon exception format
    return Pa.makeFailure(i, `'${str.toLowerCase()}'`);
});
github microsoft / dtslint / bin / rules / definitelytyped-header-parser.js View on Github external
function fail(msg) {
            let expected = "foo MAJOR.MINOR";
            if (msg) {
                expected += ` (${msg})`;
            }
            return pm.makeFailure(index, expected);
        }
    });
github ant-move / Antmove / packages / @antmove / wx-alipay-plugin / parse / parseWxml.js View on Github external
return P(function(input, i) {
        let str = input.substring(i);
        if (matchText(str));
      if (input.charAt(i) !== char) {
        return P.makeSuccess(i + 1, input.charAt(i));
      }
      return P.makeFailure(i, 'anything different than "' + char + '"');
    });
github keean / zenscript / src / parse-indentation.js View on Github external
return P((stream, i) => {
      let j = 0
      while (stream.charAt(i + j) === ' ') {
         j = j + 1
      }
      if (j === target) {
         return P.makeSuccess(i + j, j)
      } else {
         return P.makeFailure(i, 'indentation error: ' + j + ' does not equal ' + target)
      }
   })
}