Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(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)
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) {
function optional(p) {
return p.or(P.succeed())
}
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/)
function opt(parser, empty) {
if (typeof empty == 'undefined') return parser.or(Parsimmon.succeed([]));
return parser.or(Parsimmon.succeed(empty));
}
function opt(parser, empty) {
if (typeof empty == 'undefined') return parser.or(Parsimmon.succeed([]));
return parser.or(Parsimmon.succeed(empty));
}
function opt(parser, empty) {
if (typeof empty == 'undefined') return parser.or(Parsimmon.succeed([]));
return parser.or(Parsimmon.succeed(empty));
}
function opt(parser, empty) {
if (typeof empty == 'undefined') return parser.or(Parsimmon.succeed([]));
return parser.or(Parsimmon.succeed(empty));
}