Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// All pieces are optional.
var BareSlurp =
ione(ast.Parameter,
ione(ast.Identifier, P.of("_")));
var ParamSlurpy = word("...").then(Parameter.or(BareSlurp));
var ParamContext = P.string("@").then(Parameter);
var ParamsPositional = list0(ps.Separator, Parameter);
var Params2 =
P.alt(
P.seq(ParamsPositional, ps.Separator.then(ParamSlurpy)),
P.seq(P.of([]), ParamSlurpy),
P.seq(ParamsPositional, P.of(null)),
P.of(null)
);
var Params1 =
P.alt(
ParamContext.chain(function(x) {
return ps.Separator.then(Params2.map(cons(x)));
}),
ParamContext.map(function(x) { return [x, [], null]; }),
Params2.map(cons(null))
);
return iseq(ast.Parameters, Params1);
};
// The third piece (...xs) is the slurpy.
// All pieces are optional.
var BareSlurp =
ione(ast.Parameter,
ione(ast.Identifier, P.of("_")));
var ParamSlurpy = word("...").then(Parameter.or(BareSlurp));
var ParamContext = P.string("@").then(Parameter);
var ParamsPositional = list0(ps.Separator, Parameter);
var Params2 =
P.alt(
P.seq(ParamsPositional, ps.Separator.then(ParamSlurpy)),
P.seq(P.of([]), ParamSlurpy),
P.seq(ParamsPositional, P.of(null)),
P.of(null)
);
var Params1 =
P.alt(
ParamContext.chain(function(x) {
return ps.Separator.then(Params2.map(cons(x)));
}),
ParamContext.map(function(x) { return [x, [], null]; }),
Params2.map(cons(null))
);
return iseq(ast.Parameters, Params1);
};
module.exports = function(ps) {
var Parameter =
ione(ast.Parameter, ps.Identifier);
// Parameters look like this:
// (@this, a, b, c, ...xs)
// The first piece (@this) is the context.
// The second piece (a, b, c) is the positional.
// The third piece (...xs) is the slurpy.
// All pieces are optional.
var BareSlurp =
ione(ast.Parameter,
ione(ast.Identifier, P.of("_")));
var ParamSlurpy = word("...").then(Parameter.or(BareSlurp));
var ParamContext = P.string("@").then(Parameter);
var ParamsPositional = list0(ps.Separator, Parameter);
var Params2 =
P.alt(
P.seq(ParamsPositional, ps.Separator.then(ParamSlurpy)),
P.seq(P.of([]), ParamSlurpy),
P.seq(ParamsPositional, P.of(null)),
P.of(null)
);
var Params1 =
P.alt(
ParamContext.chain(function(x) {
function list0(sep, par) {
return list1(sep, par).or(P.of([]));
}
return NameParser.chain(function(x) {
if (x === kw) {
return P.of(kw);
} else {
return P.fail(kw);
}
});
}
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]);
}
}
function helper(id) {
if (keywords.indexOf(id) < 0) {
return P.of(id);
} else {
return P.fail("identifier but got keyword '" + id + "'");
}
}
let parser = P.lazy(() => nextParser.chain((next) => P.seq(operatorsParser, P.of(next), parser).or(P.of(next))));
return parser;
.desc("fractional digits")
.map(join(""));
var Exponential =
P.seq(
P.regex(/[eE]/),
P.regex(/[+-]?/),
Integer
)
.desc("exponential")
.map(join(""));
var Float =
P.seq(
Integer,
FractionalDigits.or(P.of("")),
Exponential.or(P.of(""))
)
.map(join(""));
var NaN_ = P.string("NaN").desc("NaN");
var Infinity_ = P.string("Infinity").desc("Infinity");
var Number_ =
ione(
ast.Number,
P.alt(Float, NaN_, Infinity_)
.desc("number")
.map(stripUnderscores)
.map(global.Number)
);
module.exports = function(ps) {
var OptionalName = ps.Identifier.or(P.of(null));
return iseq(ast.Function,
P.seq(
keyword("fn").then(_).then(OptionalName).skip(_),
wrap("(", ps.Parameters, ")").skip(_),
ps.Expr
));
};