How to use the parsimmon.succeed 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 keean / zenscript / src / parse.js View on Github external
(texp, mu) => {
      if (mu !== undefined) {
         if (!unify.types(texp, mu)) {
            throw 'unification error when parsing recursive type'
         }
      }
      return texp
   }
)

const typeOperator = token(P.regex(/[->]+/))

const TypePrecedence = new PrecedenceParser.PrecedenceParser(typeOperator, typeSubExpression)
texp = TypePrecedence.parseExprWithMinimumPrecedence(0)

const typeExpression = P.succeed().chain(() => {
   var_map.clear()
   return texp
})

// Register type operators with precedence parser

function infixTypeOp([name, opInfo]) {
   TypePrecedence.ledop(opInfo.symbol, opInfo.associativity, opInfo.precedence, function(info, lhs) {
      return this.parseExprWithMinimumPrecedence(info.minimumPrecedence()).map((rhs) => {
         return new AST.TypeConstructor(name, [lhs, rhs])
      })
   })
}

for (const opEntry of AST.infixTypeOps.entries()) {
   infixTypeOp(opEntry)
github keean / zenscript / src / parse.js View on Github external
const optTypeAnnotation = optional(typeAnnotationToken.then(typeExpression))

// typedIdentifier = identifier, [optTypeAnnotation, typeExpression]
const typedVariable = P.seqMap(variable, optTypeAnnotation, (v, t) => {
      if (t !== undefined) {
         v.userType = t
      }
      return v;
   }
)

const typedArgList = P.sepBy(typedVariable, comma)

// literal_function = [identifier], '(', arg_list, ')', '=>' (NL, block | expression)
const literal_function = P.seqMap(
   identifier.or(P.succeed('')),
   inParenthesis(typedArgList).skip(fat_arrow),
   block.or(expression.map((e) => {return new AST.Return(e)})),
   (name, args, body) => {
      return new AST.Fn(name, args, body)
   }
)

// expression_list = expression, {',', expression}
expression_list_lazy = P.sepBy(expression, comma)

// tuple = '(', expression_list, ')'
const tuple = inParenthesis(expression_list).map((exp_list) => {
   return new AST.LiteralTuple(exp_list)
})

function application(exp1, exps) {
github keean / zenscript / src / parse.js View on Github external
function optional(p) {
   return p.or(P.succeed())
}
github microsoft / dtslint / bin / rules / definitelytyped-header-parser.js View on Github external
const typeScriptVersionLineParser = pm.regexp(/\/\/ TypeScript Version: (2.(\d))/, 1).chain(v => {
    switch (v) {
        case "2.1":
        case "2.2":
        case "2.3":
        case "2.4":
            return pm.succeed(v);
        default:
            return pm.fail(`TypeScript ${v} is not yet supported.`);
    }
});
const typeScriptVersionParser = pm.regexp(/\r?\n/)
github dsferruzza / simpleSqlParser / src / sql2ast.js View on Github external
function opt(parser, empty) {
	if (typeof empty == 'undefined') return parser.or(Parsimmon.succeed([]));
	return parser.or(Parsimmon.succeed(empty));
}
github dsferruzza / simpleSqlParser / src / sql2ast.js View on Github external
function opt(parser, empty) {
	if (typeof empty == 'undefined') return parser.or(Parsimmon.succeed([]));
	return parser.or(Parsimmon.succeed(empty));
}
github dsferruzza / simpleSqlParser / dist / simpleSqlParser.js View on Github external
function opt(parser, empty) {
	if (typeof empty == 'undefined') return parser.or(Parsimmon.succeed([]));
	return parser.or(Parsimmon.succeed(empty));
}
github zubairq / pilot / public / simpleSqlParser.js View on Github external
function opt(parser, empty) {
	if (typeof empty == 'undefined') return parser.or(Parsimmon.succeed([]));
	return parser.or(Parsimmon.succeed(empty));
}