How to use the parsimmon.fail 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 kantord / emuto / src / parsers / identifier.js View on Github external
.chain((identifier: string): IdentifierNodeType => {
    const exceptions = ['null', 'false', 'true', 'if', 'each']
    if (exceptions.indexOf(identifier) < 0) {
      return P.of(identifier)
    } else {
      return P.fail(`identifier but got keyword ${identifier}`)
    }
  })
  .map((value: string): IdentifierNodeType => ({
github squiggle-lang / squiggle-lang / src / parse / block.js View on Github external
function checkBlock(statements) {
  var n = statements.length;
  var i = n - 1;
  var last = statements[i];
  if (last.type !== "ExprStmt") {
    return P.fail("blocks must end with an expression");
  } else {
    return P.of([statements.slice(0, i), last]);
  }
}
github squiggle-lang / squiggle-lang / src / parse-helpers.js View on Github external
return NameParser.chain(function(x) {
    if (x === kw) {
      return P.of(kw);
    } else {
      return P.fail(kw);
    }
  });
}
github keean / zenscript / src / parse-precedence.js View on Github external
return this.operator.chain((op) => {
            const info = this.leftMap.get(op)
            if (info) {
               if (info.precedence < precedence) {
                  return P.fail('Precedence below minimum expected')
               }
               return info.leftDenotation.call(this, info, lhs).chain((lhs2) => {
                  return this.parseLeftDenotation(precedence, lhs2)
               })
            }
            return P.fail('Unkown operator ' + op)
         }).or(P.succeed(lhs))
      }
github squiggle-lang / squiggle-lang / src / parse / identifier.js View on Github external
function helper(id) {
  if (keywords.indexOf(id) < 0) {
    return P.of(id);
  } else {
    return P.fail("identifier but got keyword '" + id + "'");
  }
}
github keean / zenscript / src / parse-precedence.js View on Github external
return this.operator.chain((op) => {
            const info = this.leftMap.get(op)
            if (info) {
               if (info.precedence < precedence) {
                  return P.fail('Precedence below minimum expected')
               }
               return info.leftDenotation.call(this, info, lhs).chain((lhs2) => {
                  return this.parseLeftDenotation(precedence, lhs2)
               })
            }
            return P.fail('Unkown operator ' + op)
         }).or(P.succeed(lhs))
      }