feat: simplify Danger functions
yarn.lock also changed because of the previous commmit
This commit is contained in:
parent
b7a186f8ac
commit
fad1b51630
|
@ -392,268 +392,6 @@ module DiminishingReturns = {
|
||||||
module Lib = {
|
module Lib = {
|
||||||
// many nigh-identical functions because of this bug: <https://github.com/quantified-uncertainty/squiggle/issues/1090>
|
// many nigh-identical functions because of this bug: <https://github.com/quantified-uncertainty/squiggle/issues/1090>
|
||||||
// discussed further below
|
// discussed further below
|
||||||
let optimalAllocationGivenDiminishingMarginalReturnsFunctions2 = Function.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions2",
|
|
||||||
~nameSpace,
|
|
||||||
~output=EvtArray,
|
|
||||||
~requiresNamespace=false,
|
|
||||||
~examples=[
|
|
||||||
`Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions2({|x| 20-x}, {|y| 10}, 100, 0.01)`,
|
|
||||||
],
|
|
||||||
~definitions=[
|
|
||||||
FnDefinition.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions2",
|
|
||||||
~inputs=[FRTypeLambda, FRTypeLambda, FRTypeNumber, FRTypeNumber],
|
|
||||||
~run=(inputs, _, env, reducer) =>
|
|
||||||
switch inputs {
|
|
||||||
| [
|
|
||||||
IEvLambda(lambda1),
|
|
||||||
IEvLambda(lambda2),
|
|
||||||
IEvNumber(funds),
|
|
||||||
IEvNumber(approximateIncrement),
|
|
||||||
] =>
|
|
||||||
Helpers.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions(
|
|
||||||
[lambda1, lambda2],
|
|
||||||
funds,
|
|
||||||
approximateIncrement,
|
|
||||||
env,
|
|
||||||
reducer,
|
|
||||||
)
|
|
||||||
| _ =>
|
|
||||||
Error("Error in Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions2")
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
let optimalAllocationGivenDiminishingMarginalReturnsFunctions3 = Function.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions3",
|
|
||||||
~nameSpace,
|
|
||||||
~output=EvtArray,
|
|
||||||
~requiresNamespace=false,
|
|
||||||
~examples=[
|
|
||||||
`Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions3({|x| x+1}, {|y| 10}, {|z| 20-2*z}, 100, 0.01)`,
|
|
||||||
],
|
|
||||||
~definitions=[
|
|
||||||
FnDefinition.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions3",
|
|
||||||
~inputs=[FRTypeLambda, FRTypeLambda, FRTypeLambda, FRTypeNumber, FRTypeNumber],
|
|
||||||
~run=(inputs, _, env, reducer) =>
|
|
||||||
switch inputs {
|
|
||||||
| [
|
|
||||||
IEvLambda(lambda1),
|
|
||||||
IEvLambda(lambda2),
|
|
||||||
IEvLambda(lambda3),
|
|
||||||
IEvNumber(funds),
|
|
||||||
IEvNumber(approximateIncrement),
|
|
||||||
] =>
|
|
||||||
Helpers.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions(
|
|
||||||
[lambda1, lambda2, lambda3],
|
|
||||||
funds,
|
|
||||||
approximateIncrement,
|
|
||||||
env,
|
|
||||||
reducer,
|
|
||||||
)
|
|
||||||
| _ =>
|
|
||||||
Error("Error in Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions3")
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
let optimalAllocationGivenDiminishingMarginalReturnsFunctions4 = Function.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions4",
|
|
||||||
~nameSpace,
|
|
||||||
~output=EvtArray,
|
|
||||||
~requiresNamespace=false,
|
|
||||||
~examples=[
|
|
||||||
`Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions4({|x| x+1}, {|y| 10}, {|z| 20-2*z}, {|a| 15-a}, 100, 0.01)`,
|
|
||||||
],
|
|
||||||
~definitions=[
|
|
||||||
FnDefinition.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions4",
|
|
||||||
~inputs=[
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeNumber,
|
|
||||||
FRTypeNumber,
|
|
||||||
],
|
|
||||||
~run=(inputs, _, env, reducer) =>
|
|
||||||
switch inputs {
|
|
||||||
| [
|
|
||||||
IEvLambda(lambda1),
|
|
||||||
IEvLambda(lambda2),
|
|
||||||
IEvLambda(lambda3),
|
|
||||||
IEvLambda(lambda4),
|
|
||||||
IEvNumber(funds),
|
|
||||||
IEvNumber(approximateIncrement),
|
|
||||||
] =>
|
|
||||||
Helpers.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions(
|
|
||||||
[lambda1, lambda2, lambda3, lambda4],
|
|
||||||
funds,
|
|
||||||
approximateIncrement,
|
|
||||||
env,
|
|
||||||
reducer,
|
|
||||||
)
|
|
||||||
| _ =>
|
|
||||||
Error("Error in Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions4")
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
let optimalAllocationGivenDiminishingMarginalReturnsFunctions5 = Function.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions5",
|
|
||||||
~nameSpace,
|
|
||||||
~output=EvtArray,
|
|
||||||
~requiresNamespace=false,
|
|
||||||
~examples=[
|
|
||||||
`Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions5({|x| x+1}, {|y| 10}, {|z| 20-2*z}, {|a| 15-a}, {|b| 17-b}, 100, 0.01)`,
|
|
||||||
],
|
|
||||||
~definitions=[
|
|
||||||
FnDefinition.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions5",
|
|
||||||
~inputs=[
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeNumber,
|
|
||||||
FRTypeNumber,
|
|
||||||
],
|
|
||||||
~run=(inputs, _, env, reducer) =>
|
|
||||||
switch inputs {
|
|
||||||
| [
|
|
||||||
IEvLambda(lambda1),
|
|
||||||
IEvLambda(lambda2),
|
|
||||||
IEvLambda(lambda3),
|
|
||||||
IEvLambda(lambda4),
|
|
||||||
IEvLambda(lambda5),
|
|
||||||
IEvNumber(funds),
|
|
||||||
IEvNumber(approximateIncrement),
|
|
||||||
] =>
|
|
||||||
Helpers.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions(
|
|
||||||
[lambda1, lambda2, lambda3, lambda4, lambda5],
|
|
||||||
funds,
|
|
||||||
approximateIncrement,
|
|
||||||
env,
|
|
||||||
reducer,
|
|
||||||
)
|
|
||||||
| _ =>
|
|
||||||
Error("Error in Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions5")
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
let optimalAllocationGivenDiminishingMarginalReturnsFunctions6 = Function.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions6",
|
|
||||||
~nameSpace,
|
|
||||||
~output=EvtArray,
|
|
||||||
~requiresNamespace=false,
|
|
||||||
~examples=[
|
|
||||||
`Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions6({|x| x+1}, {|y| 10}, {|z| 20-2*z}, {|a| 15-a}, {|b| 17-b}, {|c| 19-c}, 100, 0.01)`,
|
|
||||||
],
|
|
||||||
~definitions=[
|
|
||||||
FnDefinition.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions6",
|
|
||||||
~inputs=[
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeNumber,
|
|
||||||
FRTypeNumber,
|
|
||||||
],
|
|
||||||
~run=(inputs, _, env, reducer) =>
|
|
||||||
switch inputs {
|
|
||||||
| [
|
|
||||||
IEvLambda(lambda1),
|
|
||||||
IEvLambda(lambda2),
|
|
||||||
IEvLambda(lambda3),
|
|
||||||
IEvLambda(lambda4),
|
|
||||||
IEvLambda(lambda5),
|
|
||||||
IEvLambda(lambda6),
|
|
||||||
IEvNumber(funds),
|
|
||||||
IEvNumber(approximateIncrement),
|
|
||||||
] =>
|
|
||||||
Helpers.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions(
|
|
||||||
[lambda1, lambda2, lambda3, lambda4, lambda5, lambda6],
|
|
||||||
funds,
|
|
||||||
approximateIncrement,
|
|
||||||
env,
|
|
||||||
reducer,
|
|
||||||
)
|
|
||||||
| _ =>
|
|
||||||
Error("Error in Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions6")
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
let optimalAllocationGivenDiminishingMarginalReturnsFunctions7 = Function.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions7",
|
|
||||||
~nameSpace,
|
|
||||||
~output=EvtArray,
|
|
||||||
~requiresNamespace=false,
|
|
||||||
~examples=[
|
|
||||||
`Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions7({|x| x+1}, {|y| 10}, {|z| 20-2*z}, {|a| 15-a}, {|b| 17-b}, {|c| 19-c}, {|d| 20-d/2}, 100, 0.01)`,
|
|
||||||
],
|
|
||||||
~definitions=[
|
|
||||||
FnDefinition.make(
|
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsFunctions7",
|
|
||||||
~inputs=[
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeLambda,
|
|
||||||
FRTypeNumber,
|
|
||||||
FRTypeNumber,
|
|
||||||
],
|
|
||||||
~run=(inputs, _, env, reducer) =>
|
|
||||||
switch inputs {
|
|
||||||
| [
|
|
||||||
IEvLambda(lambda1),
|
|
||||||
IEvLambda(lambda2),
|
|
||||||
IEvLambda(lambda3),
|
|
||||||
IEvLambda(lambda4),
|
|
||||||
IEvLambda(lambda5),
|
|
||||||
IEvLambda(lambda6),
|
|
||||||
IEvLambda(lambda7),
|
|
||||||
IEvNumber(funds),
|
|
||||||
IEvNumber(approximateIncrement),
|
|
||||||
] =>
|
|
||||||
Helpers.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions(
|
|
||||||
[lambda1, lambda2, lambda3, lambda4, lambda5, lambda6, lambda7],
|
|
||||||
funds,
|
|
||||||
approximateIncrement,
|
|
||||||
env,
|
|
||||||
reducer,
|
|
||||||
)
|
|
||||||
| _ =>
|
|
||||||
Error("Error in Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions7")
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
|
|
||||||
// The following will compile, but not work, because of this bug: <https://github.com/quantified-uncertainty/squiggle/issues/558> Instead, I am creating different functions for different numbers of inputs above.
|
|
||||||
@dead
|
|
||||||
let optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions = Function.make(
|
let optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions = Function.make(
|
||||||
~name="optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions",
|
~name="optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
@ -722,15 +460,5 @@ let library = [
|
||||||
// will only depend on num points and the complexity of the function
|
// will only depend on num points and the complexity of the function
|
||||||
|
|
||||||
// Diminishing marginal return functions
|
// Diminishing marginal return functions
|
||||||
// There are functions optimalAllocationGivenDiminishingMarginalReturnsFunctions2 through optimalAllocationGivenDiminishingMarginalReturnsFunctions7
|
DiminishingReturns.Lib.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions
|
||||||
// because of this bug: <https://github.com/quantified-uncertainty/squiggle/issues/1090>
|
|
||||||
// As soon as that is fixed, I will delete this bag of functions
|
|
||||||
// and uncomment the function below
|
|
||||||
DiminishingReturns.Lib.optimalAllocationGivenDiminishingMarginalReturnsFunctions2,
|
|
||||||
DiminishingReturns.Lib.optimalAllocationGivenDiminishingMarginalReturnsFunctions3,
|
|
||||||
DiminishingReturns.Lib.optimalAllocationGivenDiminishingMarginalReturnsFunctions4,
|
|
||||||
DiminishingReturns.Lib.optimalAllocationGivenDiminishingMarginalReturnsFunctions5,
|
|
||||||
DiminishingReturns.Lib.optimalAllocationGivenDiminishingMarginalReturnsFunctions6,
|
|
||||||
DiminishingReturns.Lib.optimalAllocationGivenDiminishingMarginalReturnsFunctions7,
|
|
||||||
// DiminishingReturns.Lib.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,9 +5,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function peg$subclass(child, parent) {
|
function peg$subclass(child, parent) {
|
||||||
function C() {
|
function C() { this.constructor = child; }
|
||||||
this.constructor = child;
|
|
||||||
}
|
|
||||||
C.prototype = parent.prototype;
|
C.prototype = parent.prototype;
|
||||||
child.prototype = new C();
|
child.prototype = new C();
|
||||||
}
|
}
|
||||||
|
@ -29,15 +27,13 @@ peg$subclass(peg$SyntaxError, Error);
|
||||||
|
|
||||||
function peg$padEnd(str, targetLength, padString) {
|
function peg$padEnd(str, targetLength, padString) {
|
||||||
padString = padString || " ";
|
padString = padString || " ";
|
||||||
if (str.length > targetLength) {
|
if (str.length > targetLength) { return str; }
|
||||||
return str;
|
|
||||||
}
|
|
||||||
targetLength -= str.length;
|
targetLength -= str.length;
|
||||||
padString += padString.repeat(targetLength);
|
padString += padString.repeat(targetLength);
|
||||||
return str + padString.slice(0, targetLength);
|
return str + padString.slice(0, targetLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
peg$SyntaxError.prototype.format = function (sources) {
|
peg$SyntaxError.prototype.format = function(sources) {
|
||||||
var str = "Error: " + this.message;
|
var str = "Error: " + this.message;
|
||||||
if (this.location) {
|
if (this.location) {
|
||||||
var src = null;
|
var src = null;
|
||||||
|
@ -52,24 +48,15 @@ peg$SyntaxError.prototype.format = function (sources) {
|
||||||
var loc = this.location.source + ":" + s.line + ":" + s.column;
|
var loc = this.location.source + ":" + s.line + ":" + s.column;
|
||||||
if (src) {
|
if (src) {
|
||||||
var e = this.location.end;
|
var e = this.location.end;
|
||||||
var filler = peg$padEnd("", s.line.toString().length, " ");
|
var filler = peg$padEnd("", s.line.toString().length, ' ');
|
||||||
var line = src[s.line - 1];
|
var line = src[s.line - 1];
|
||||||
var last = s.line === e.line ? e.column : line.length + 1;
|
var last = s.line === e.line ? e.column : line.length + 1;
|
||||||
var hatLen = last - s.column || 1;
|
var hatLen = (last - s.column) || 1;
|
||||||
str +=
|
str += "\n --> " + loc + "\n"
|
||||||
"\n --> " +
|
+ filler + " |\n"
|
||||||
loc +
|
+ s.line + " | " + line + "\n"
|
||||||
"\n" +
|
+ filler + " | " + peg$padEnd("", s.column - 1, ' ')
|
||||||
filler +
|
+ peg$padEnd("", hatLen, "^");
|
||||||
" |\n" +
|
|
||||||
s.line +
|
|
||||||
" | " +
|
|
||||||
line +
|
|
||||||
"\n" +
|
|
||||||
filler +
|
|
||||||
" | " +
|
|
||||||
peg$padEnd("", s.column - 1, " ") +
|
|
||||||
peg$padEnd("", hatLen, "^");
|
|
||||||
} else {
|
} else {
|
||||||
str += "\n at " + loc;
|
str += "\n at " + loc;
|
||||||
}
|
}
|
||||||
|
@ -77,35 +64,33 @@ peg$SyntaxError.prototype.format = function (sources) {
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
peg$SyntaxError.buildMessage = function (expected, found) {
|
peg$SyntaxError.buildMessage = function(expected, found) {
|
||||||
var DESCRIBE_EXPECTATION_FNS = {
|
var DESCRIBE_EXPECTATION_FNS = {
|
||||||
literal: function (expectation) {
|
literal: function(expectation) {
|
||||||
return '"' + literalEscape(expectation.text) + '"';
|
return "\"" + literalEscape(expectation.text) + "\"";
|
||||||
},
|
},
|
||||||
|
|
||||||
class: function (expectation) {
|
class: function(expectation) {
|
||||||
var escapedParts = expectation.parts.map(function (part) {
|
var escapedParts = expectation.parts.map(function(part) {
|
||||||
return Array.isArray(part)
|
return Array.isArray(part)
|
||||||
? classEscape(part[0]) + "-" + classEscape(part[1])
|
? classEscape(part[0]) + "-" + classEscape(part[1])
|
||||||
: classEscape(part);
|
: classEscape(part);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
|
||||||
"[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]"
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
any: function () {
|
any: function() {
|
||||||
return "any character";
|
return "any character";
|
||||||
},
|
},
|
||||||
|
|
||||||
end: function () {
|
end: function() {
|
||||||
return "end of input";
|
return "end of input";
|
||||||
},
|
},
|
||||||
|
|
||||||
other: function (expectation) {
|
other: function(expectation) {
|
||||||
return expectation.description;
|
return expectation.description;
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function hex(ch) {
|
function hex(ch) {
|
||||||
|
@ -115,17 +100,13 @@ peg$SyntaxError.buildMessage = function (expected, found) {
|
||||||
function literalEscape(s) {
|
function literalEscape(s) {
|
||||||
return s
|
return s
|
||||||
.replace(/\\/g, "\\\\")
|
.replace(/\\/g, "\\\\")
|
||||||
.replace(/"/g, '\\"')
|
.replace(/"/g, "\\\"")
|
||||||
.replace(/\0/g, "\\0")
|
.replace(/\0/g, "\\0")
|
||||||
.replace(/\t/g, "\\t")
|
.replace(/\t/g, "\\t")
|
||||||
.replace(/\n/g, "\\n")
|
.replace(/\n/g, "\\n")
|
||||||
.replace(/\r/g, "\\r")
|
.replace(/\r/g, "\\r")
|
||||||
.replace(/[\x00-\x0F]/g, function (ch) {
|
.replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
|
||||||
return "\\x0" + hex(ch);
|
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
|
||||||
})
|
|
||||||
.replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
|
|
||||||
return "\\x" + hex(ch);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function classEscape(s) {
|
function classEscape(s) {
|
||||||
|
@ -133,17 +114,13 @@ peg$SyntaxError.buildMessage = function (expected, found) {
|
||||||
.replace(/\\/g, "\\\\")
|
.replace(/\\/g, "\\\\")
|
||||||
.replace(/\]/g, "\\]")
|
.replace(/\]/g, "\\]")
|
||||||
.replace(/\^/g, "\\^")
|
.replace(/\^/g, "\\^")
|
||||||
.replace(/-/g, "\\-")
|
.replace(/-/g, "\\-")
|
||||||
.replace(/\0/g, "\\0")
|
.replace(/\0/g, "\\0")
|
||||||
.replace(/\t/g, "\\t")
|
.replace(/\t/g, "\\t")
|
||||||
.replace(/\n/g, "\\n")
|
.replace(/\n/g, "\\n")
|
||||||
.replace(/\r/g, "\\r")
|
.replace(/\r/g, "\\r")
|
||||||
.replace(/[\x00-\x0F]/g, function (ch) {
|
.replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
|
||||||
return "\\x0" + hex(ch);
|
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
|
||||||
})
|
|
||||||
.replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
|
|
||||||
return "\\x" + hex(ch);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function describeExpectation(expectation) {
|
function describeExpectation(expectation) {
|
||||||
|
@ -174,25 +151,17 @@ peg$SyntaxError.buildMessage = function (expected, found) {
|
||||||
return descriptions[0] + " or " + descriptions[1];
|
return descriptions[0] + " or " + descriptions[1];
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return (
|
return descriptions.slice(0, -1).join(", ")
|
||||||
descriptions.slice(0, -1).join(", ") +
|
+ ", or "
|
||||||
", or " +
|
+ descriptions[descriptions.length - 1];
|
||||||
descriptions[descriptions.length - 1]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function describeFound(found) {
|
function describeFound(found) {
|
||||||
return found ? '"' + literalEscape(found) + '"' : "end of input";
|
return found ? "\"" + literalEscape(found) + "\"" : "end of input";
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
|
||||||
"Expected " +
|
|
||||||
describeExpected(expected) +
|
|
||||||
" but " +
|
|
||||||
describeFound(found) +
|
|
||||||
" found."
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function peg$parse(input, options) {
|
function peg$parse(input, options) {
|
||||||
|
@ -208,7 +177,7 @@ function peg$parse(input, options) {
|
||||||
var peg$c1 = "#include";
|
var peg$c1 = "#include";
|
||||||
var peg$c2 = "as";
|
var peg$c2 = "as";
|
||||||
var peg$c3 = "'";
|
var peg$c3 = "'";
|
||||||
var peg$c4 = '"';
|
var peg$c4 = "\"";
|
||||||
var peg$c5 = "//";
|
var peg$c5 = "//";
|
||||||
var peg$c6 = "/*";
|
var peg$c6 = "/*";
|
||||||
var peg$c7 = "*/";
|
var peg$c7 = "*/";
|
||||||
|
@ -228,8 +197,8 @@ function peg$parse(input, options) {
|
||||||
var peg$e3 = peg$otherExpectation("string");
|
var peg$e3 = peg$otherExpectation("string");
|
||||||
var peg$e4 = peg$literalExpectation("'", false);
|
var peg$e4 = peg$literalExpectation("'", false);
|
||||||
var peg$e5 = peg$classExpectation(["'"], true, false);
|
var peg$e5 = peg$classExpectation(["'"], true, false);
|
||||||
var peg$e6 = peg$literalExpectation('"', false);
|
var peg$e6 = peg$literalExpectation("\"", false);
|
||||||
var peg$e7 = peg$classExpectation(['"'], true, false);
|
var peg$e7 = peg$classExpectation(["\""], true, false);
|
||||||
var peg$e8 = peg$otherExpectation("comment");
|
var peg$e8 = peg$otherExpectation("comment");
|
||||||
var peg$e9 = peg$literalExpectation("//", false);
|
var peg$e9 = peg$literalExpectation("//", false);
|
||||||
var peg$e10 = peg$literalExpectation("/*", false);
|
var peg$e10 = peg$literalExpectation("/*", false);
|
||||||
|
@ -243,36 +212,16 @@ function peg$parse(input, options) {
|
||||||
var peg$e18 = peg$classExpectation(["\r", "\n"], true, false);
|
var peg$e18 = peg$classExpectation(["\r", "\n"], true, false);
|
||||||
var peg$e19 = peg$otherExpectation("identifier");
|
var peg$e19 = peg$otherExpectation("identifier");
|
||||||
var peg$e20 = peg$classExpectation(["_", ["a", "z"]], false, false);
|
var peg$e20 = peg$classExpectation(["_", ["a", "z"]], false, false);
|
||||||
var peg$e21 = peg$classExpectation(
|
var peg$e21 = peg$classExpectation(["_", ["a", "z"], ["0", "9"]], false, true);
|
||||||
["_", ["a", "z"], ["0", "9"]],
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
var peg$f0 = function (head, tail) {
|
var peg$f0 = function(head, tail) {return [head, ...tail].filter( e => e != '');};
|
||||||
return [head, ...tail].filter((e) => e != "");
|
var peg$f1 = function() {return [];};
|
||||||
};
|
var peg$f2 = function(file, variable) {return [!variable ? '' : variable, file]};
|
||||||
var peg$f1 = function () {
|
var peg$f3 = function(characters) {return characters.join('');};
|
||||||
return [];
|
var peg$f4 = function(characters) {return characters.join('');};
|
||||||
};
|
var peg$f5 = function() { return '';};
|
||||||
var peg$f2 = function (file, variable) {
|
var peg$f6 = function() { return '';};
|
||||||
return [!variable ? "" : variable, file];
|
var peg$f7 = function() {return text();};
|
||||||
};
|
|
||||||
var peg$f3 = function (characters) {
|
|
||||||
return characters.join("");
|
|
||||||
};
|
|
||||||
var peg$f4 = function (characters) {
|
|
||||||
return characters.join("");
|
|
||||||
};
|
|
||||||
var peg$f5 = function () {
|
|
||||||
return "";
|
|
||||||
};
|
|
||||||
var peg$f6 = function () {
|
|
||||||
return "";
|
|
||||||
};
|
|
||||||
var peg$f7 = function () {
|
|
||||||
return text();
|
|
||||||
};
|
|
||||||
var peg$currPos = 0;
|
var peg$currPos = 0;
|
||||||
var peg$savedPos = 0;
|
var peg$savedPos = 0;
|
||||||
var peg$posDetailsCache = [{ line: 1, column: 1 }];
|
var peg$posDetailsCache = [{ line: 1, column: 1 }];
|
||||||
|
@ -286,9 +235,7 @@ function peg$parse(input, options) {
|
||||||
|
|
||||||
if ("startRule" in options) {
|
if ("startRule" in options) {
|
||||||
if (!(options.startRule in peg$startRuleFunctions)) {
|
if (!(options.startRule in peg$startRuleFunctions)) {
|
||||||
throw new Error(
|
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
|
||||||
"Can't start parsing from rule \"" + options.startRule + '".'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
|
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
|
||||||
|
@ -306,7 +253,7 @@ function peg$parse(input, options) {
|
||||||
return {
|
return {
|
||||||
source: peg$source,
|
source: peg$source,
|
||||||
start: peg$savedPos,
|
start: peg$savedPos,
|
||||||
end: peg$currPos,
|
end: peg$currPos
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,10 +262,9 @@ function peg$parse(input, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function expected(description, location) {
|
function expected(description, location) {
|
||||||
location =
|
location = location !== undefined
|
||||||
location !== undefined
|
? location
|
||||||
? location
|
: peg$computeLocation(peg$savedPos, peg$currPos);
|
||||||
: peg$computeLocation(peg$savedPos, peg$currPos);
|
|
||||||
|
|
||||||
throw peg$buildStructuredError(
|
throw peg$buildStructuredError(
|
||||||
[peg$otherExpectation(description)],
|
[peg$otherExpectation(description)],
|
||||||
|
@ -328,10 +274,9 @@ function peg$parse(input, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(message, location) {
|
function error(message, location) {
|
||||||
location =
|
location = location !== undefined
|
||||||
location !== undefined
|
? location
|
||||||
? location
|
: peg$computeLocation(peg$savedPos, peg$currPos);
|
||||||
: peg$computeLocation(peg$savedPos, peg$currPos);
|
|
||||||
|
|
||||||
throw peg$buildSimpleError(message, location);
|
throw peg$buildSimpleError(message, location);
|
||||||
}
|
}
|
||||||
|
@ -341,12 +286,7 @@ function peg$parse(input, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function peg$classExpectation(parts, inverted, ignoreCase) {
|
function peg$classExpectation(parts, inverted, ignoreCase) {
|
||||||
return {
|
return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
|
||||||
type: "class",
|
|
||||||
parts: parts,
|
|
||||||
inverted: inverted,
|
|
||||||
ignoreCase: ignoreCase,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function peg$anyExpectation() {
|
function peg$anyExpectation() {
|
||||||
|
@ -376,7 +316,7 @@ function peg$parse(input, options) {
|
||||||
details = peg$posDetailsCache[p];
|
details = peg$posDetailsCache[p];
|
||||||
details = {
|
details = {
|
||||||
line: details.line,
|
line: details.line,
|
||||||
column: details.column,
|
column: details.column
|
||||||
};
|
};
|
||||||
|
|
||||||
while (p < pos) {
|
while (p < pos) {
|
||||||
|
@ -405,20 +345,18 @@ function peg$parse(input, options) {
|
||||||
start: {
|
start: {
|
||||||
offset: startPos,
|
offset: startPos,
|
||||||
line: startPosDetails.line,
|
line: startPosDetails.line,
|
||||||
column: startPosDetails.column,
|
column: startPosDetails.column
|
||||||
},
|
},
|
||||||
end: {
|
end: {
|
||||||
offset: endPos,
|
offset: endPos,
|
||||||
line: endPosDetails.line,
|
line: endPosDetails.line,
|
||||||
column: endPosDetails.column,
|
column: endPosDetails.column
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function peg$fail(expected) {
|
function peg$fail(expected) {
|
||||||
if (peg$currPos < peg$maxFailPos) {
|
if (peg$currPos < peg$maxFailPos) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (peg$currPos > peg$maxFailPos) {
|
if (peg$currPos > peg$maxFailPos) {
|
||||||
peg$maxFailPos = peg$currPos;
|
peg$maxFailPos = peg$currPos;
|
||||||
|
@ -578,9 +516,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s2 = peg$FAILED;
|
s2 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e0); }
|
||||||
peg$fail(peg$e0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
peg$silentFails--;
|
peg$silentFails--;
|
||||||
if (s2 === peg$FAILED) {
|
if (s2 === peg$FAILED) {
|
||||||
|
@ -650,9 +586,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos += 8;
|
peg$currPos += 8;
|
||||||
} else {
|
} else {
|
||||||
s2 = peg$FAILED;
|
s2 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e1); }
|
||||||
peg$fail(peg$e1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (s2 !== peg$FAILED) {
|
if (s2 !== peg$FAILED) {
|
||||||
s3 = [];
|
s3 = [];
|
||||||
|
@ -685,9 +619,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos += 2;
|
peg$currPos += 2;
|
||||||
} else {
|
} else {
|
||||||
s7 = peg$FAILED;
|
s7 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e2); }
|
||||||
peg$fail(peg$e2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (s7 !== peg$FAILED) {
|
if (s7 !== peg$FAILED) {
|
||||||
s8 = [];
|
s8 = [];
|
||||||
|
@ -784,9 +716,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s2 = peg$FAILED;
|
s2 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e4); }
|
||||||
peg$fail(peg$e4);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (s2 !== peg$FAILED) {
|
if (s2 !== peg$FAILED) {
|
||||||
s3 = [];
|
s3 = [];
|
||||||
|
@ -795,9 +725,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s4 = peg$FAILED;
|
s4 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e5); }
|
||||||
peg$fail(peg$e5);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (s4 !== peg$FAILED) {
|
while (s4 !== peg$FAILED) {
|
||||||
s3.push(s4);
|
s3.push(s4);
|
||||||
|
@ -806,9 +734,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s4 = peg$FAILED;
|
s4 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e5); }
|
||||||
peg$fail(peg$e5);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (input.charCodeAt(peg$currPos) === 39) {
|
if (input.charCodeAt(peg$currPos) === 39) {
|
||||||
|
@ -816,9 +742,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s4 = peg$FAILED;
|
s4 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e4); }
|
||||||
peg$fail(peg$e4);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (s4 !== peg$FAILED) {
|
if (s4 !== peg$FAILED) {
|
||||||
s1 = s3;
|
s1 = s3;
|
||||||
|
@ -843,9 +767,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s2 = peg$FAILED;
|
s2 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e6); }
|
||||||
peg$fail(peg$e6);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (s2 !== peg$FAILED) {
|
if (s2 !== peg$FAILED) {
|
||||||
s3 = [];
|
s3 = [];
|
||||||
|
@ -854,9 +776,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s4 = peg$FAILED;
|
s4 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e7); }
|
||||||
peg$fail(peg$e7);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (s4 !== peg$FAILED) {
|
while (s4 !== peg$FAILED) {
|
||||||
s3.push(s4);
|
s3.push(s4);
|
||||||
|
@ -865,9 +785,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s4 = peg$FAILED;
|
s4 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e7); }
|
||||||
peg$fail(peg$e7);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (input.charCodeAt(peg$currPos) === 34) {
|
if (input.charCodeAt(peg$currPos) === 34) {
|
||||||
|
@ -875,9 +793,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s4 = peg$FAILED;
|
s4 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e6); }
|
||||||
peg$fail(peg$e6);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (s4 !== peg$FAILED) {
|
if (s4 !== peg$FAILED) {
|
||||||
s1 = s3;
|
s1 = s3;
|
||||||
|
@ -898,9 +814,7 @@ function peg$parse(input, options) {
|
||||||
peg$silentFails--;
|
peg$silentFails--;
|
||||||
if (s0 === peg$FAILED) {
|
if (s0 === peg$FAILED) {
|
||||||
s1 = peg$FAILED;
|
s1 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e3); }
|
||||||
peg$fail(peg$e3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
||||||
|
@ -963,9 +877,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos += 2;
|
peg$currPos += 2;
|
||||||
} else {
|
} else {
|
||||||
s1 = peg$FAILED;
|
s1 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e9); }
|
||||||
peg$fail(peg$e9);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (s1 !== peg$FAILED) {
|
if (s1 !== peg$FAILED) {
|
||||||
s2 = [];
|
s2 = [];
|
||||||
|
@ -998,9 +910,7 @@ function peg$parse(input, options) {
|
||||||
peg$silentFails--;
|
peg$silentFails--;
|
||||||
if (s0 === peg$FAILED) {
|
if (s0 === peg$FAILED) {
|
||||||
s1 = peg$FAILED;
|
s1 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e8); }
|
||||||
peg$fail(peg$e8);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
||||||
|
@ -1027,9 +937,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos += 2;
|
peg$currPos += 2;
|
||||||
} else {
|
} else {
|
||||||
s1 = peg$FAILED;
|
s1 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e10); }
|
||||||
peg$fail(peg$e10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (s1 !== peg$FAILED) {
|
if (s1 !== peg$FAILED) {
|
||||||
s2 = [];
|
s2 = [];
|
||||||
|
@ -1038,9 +946,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s3 = peg$FAILED;
|
s3 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e11); }
|
||||||
peg$fail(peg$e11);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (s3 !== peg$FAILED) {
|
while (s3 !== peg$FAILED) {
|
||||||
s2.push(s3);
|
s2.push(s3);
|
||||||
|
@ -1049,9 +955,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s3 = peg$FAILED;
|
s3 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e11); }
|
||||||
peg$fail(peg$e11);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (input.substr(peg$currPos, 2) === peg$c7) {
|
if (input.substr(peg$currPos, 2) === peg$c7) {
|
||||||
|
@ -1059,9 +963,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos += 2;
|
peg$currPos += 2;
|
||||||
} else {
|
} else {
|
||||||
s3 = peg$FAILED;
|
s3 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e12); }
|
||||||
peg$fail(peg$e12);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (s3 !== peg$FAILED) {
|
if (s3 !== peg$FAILED) {
|
||||||
peg$savedPos = s0;
|
peg$savedPos = s0;
|
||||||
|
@ -1077,9 +979,7 @@ function peg$parse(input, options) {
|
||||||
peg$silentFails--;
|
peg$silentFails--;
|
||||||
if (s0 === peg$FAILED) {
|
if (s0 === peg$FAILED) {
|
||||||
s1 = peg$FAILED;
|
s1 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e8); }
|
||||||
peg$fail(peg$e8);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
||||||
|
@ -1105,16 +1005,12 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s0 = peg$FAILED;
|
s0 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e14); }
|
||||||
peg$fail(peg$e14);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
peg$silentFails--;
|
peg$silentFails--;
|
||||||
if (s0 === peg$FAILED) {
|
if (s0 === peg$FAILED) {
|
||||||
s1 = peg$FAILED;
|
s1 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e13); }
|
||||||
peg$fail(peg$e13);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
||||||
|
@ -1140,16 +1036,12 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s0 = peg$FAILED;
|
s0 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e16); }
|
||||||
peg$fail(peg$e16);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
peg$silentFails--;
|
peg$silentFails--;
|
||||||
if (s0 === peg$FAILED) {
|
if (s0 === peg$FAILED) {
|
||||||
s1 = peg$FAILED;
|
s1 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e15); }
|
||||||
peg$fail(peg$e15);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
||||||
|
@ -1175,16 +1067,12 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s0 = peg$FAILED;
|
s0 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e18); }
|
||||||
peg$fail(peg$e18);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
peg$silentFails--;
|
peg$silentFails--;
|
||||||
if (s0 === peg$FAILED) {
|
if (s0 === peg$FAILED) {
|
||||||
s1 = peg$FAILED;
|
s1 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e17); }
|
||||||
peg$fail(peg$e17);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
||||||
|
@ -1213,9 +1101,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s3 = peg$FAILED;
|
s3 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e20); }
|
||||||
peg$fail(peg$e20);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (s3 !== peg$FAILED) {
|
if (s3 !== peg$FAILED) {
|
||||||
while (s3 !== peg$FAILED) {
|
while (s3 !== peg$FAILED) {
|
||||||
|
@ -1225,9 +1111,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s3 = peg$FAILED;
|
s3 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e20); }
|
||||||
peg$fail(peg$e20);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1240,9 +1124,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s4 = peg$FAILED;
|
s4 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e21); }
|
||||||
peg$fail(peg$e21);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (s4 !== peg$FAILED) {
|
while (s4 !== peg$FAILED) {
|
||||||
s3.push(s4);
|
s3.push(s4);
|
||||||
|
@ -1251,9 +1133,7 @@ function peg$parse(input, options) {
|
||||||
peg$currPos++;
|
peg$currPos++;
|
||||||
} else {
|
} else {
|
||||||
s4 = peg$FAILED;
|
s4 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e21); }
|
||||||
peg$fail(peg$e21);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s2 = [s2, s3];
|
s2 = [s2, s3];
|
||||||
|
@ -1270,9 +1150,7 @@ function peg$parse(input, options) {
|
||||||
peg$silentFails--;
|
peg$silentFails--;
|
||||||
if (s0 === peg$FAILED) {
|
if (s0 === peg$FAILED) {
|
||||||
s1 = peg$FAILED;
|
s1 = peg$FAILED;
|
||||||
if (peg$silentFails === 0) {
|
if (peg$silentFails === 0) { peg$fail(peg$e19); }
|
||||||
peg$fail(peg$e19);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
|
||||||
|
@ -1301,5 +1179,5 @@ function peg$parse(input, options) {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
SyntaxError: peg$SyntaxError,
|
SyntaxError: peg$SyntaxError,
|
||||||
parse: peg$parse,
|
parse: peg$parse
|
||||||
};
|
};
|
||||||
|
|
|
@ -69,28 +69,18 @@ Danger.integrateFunctionBetweenWithEpsilon: (number => number, number, number, n
|
||||||
|
|
||||||
Same caveats as `integrateFunctionBetweenWithNumIntegrationPoints` apply.
|
Same caveats as `integrateFunctionBetweenWithNumIntegrationPoints` apply.
|
||||||
|
|
||||||
### optimalAllocationGivenDiminishingMarginalReturnsFunctions2
|
### optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions
|
||||||
|
|
||||||
```js
|
```js
|
||||||
Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions2: (number => number, number => number, number, number) => number
|
Danger.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions: (array<number => number>, number, number) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
`Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions2(f1, f2, funds, approximateIncrement)` computes the optimal allocation of $`funds` between `f1` and `f2`. For the answer given to be correct, `f1` and `f2` will have to be decreasing, i.e., if `x > y`, then `f_i(x) < f_i(y)`
|
`Danger.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions([f1, f2], funds, approximateIncrement)` computes the optimal allocation of $`funds` between `f1` and `f2`. For the answer given to be correct, `f1` and `f2` will have to be decreasing, i.e., if `x > y`, then `f_i(x) < f_i(y)`.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions2({|x| 20-x}, {|y| 10}, 100, 0.01)
|
Danger.optimalAllocationGivenDiminishingMarginalReturnsForManyFunctions({|x| 20-x}, {|y| 10}, 100, 0.01)
|
||||||
```
|
```
|
||||||
|
|
||||||
### optimalAllocationGivenDiminishingMarginalReturnsFunctions3 to optimalAllocationGivenDiminishingMarginalReturnsFunctions7
|
Note also that the array ought to have more than one function in it.
|
||||||
|
|
||||||
Equivalent to the above, but they take more functional arguments. Their type is given below:
|
|
||||||
|
|
||||||
```js
|
|
||||||
Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions3: (number => number, number => number, number => number, number, number) => number
|
|
||||||
Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions5: (number => number, number => number, umber => number, number => number, number, number) => number
|
|
||||||
Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions5: (number => number, number => number, umber => number, number => number, number => number, number, number) => number
|
|
||||||
Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions6: (number => number, number => number, number => number, number => number, number => number, number => number, number, number) => number
|
|
||||||
Danger.optimalAllocationGivenDiminishingMarginalReturnsFunctions7: (number => number, number => number, number => number, number => number, umber => number, number => number, number => number, number, number) => number
|
|
||||||
```
|
|
10
yarn.lock
10
yarn.lock
|
@ -4575,10 +4575,10 @@
|
||||||
"@types/history" "^4.7.11"
|
"@types/history" "^4.7.11"
|
||||||
"@types/react" "*"
|
"@types/react" "*"
|
||||||
|
|
||||||
"@types/react@*", "@types/react@^18.0.1", "@types/react@^18.0.18":
|
"@types/react@*", "@types/react@17.0.43", "@types/react@^18.0.18":
|
||||||
version "18.0.18"
|
version "17.0.43"
|
||||||
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.18.tgz#9f16f33d57bc5d9dca848d12c3572110ff9429ac"
|
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.43.tgz#4adc142887dd4a2601ce730bc56c3436fdb07a55"
|
||||||
integrity sha512-6hI08umYs6NaiHFEEGioXnxJ+oEhY3eRz8VCUaudZmGdtvPviCJB8mgaMxaDWAdPSYd4eFavrPk2QIolwbLYrg==
|
integrity sha512-8Q+LNpdxf057brvPu1lMtC5Vn7J119xrP1aq4qiaefNioQUYANF/CYeK4NsKorSZyUGJ66g0IM+4bbjwx45o2A==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/prop-types" "*"
|
"@types/prop-types" "*"
|
||||||
"@types/scheduler" "*"
|
"@types/scheduler" "*"
|
||||||
|
@ -14921,7 +14921,7 @@ react-vega@^7.6.0:
|
||||||
prop-types "^15.8.1"
|
prop-types "^15.8.1"
|
||||||
vega-embed "^6.5.1"
|
vega-embed "^6.5.1"
|
||||||
|
|
||||||
react@^18.0.0, react@^18.1.0:
|
react@^18.1.0:
|
||||||
version "18.2.0"
|
version "18.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
|
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
|
||||||
integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==
|
integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==
|
||||||
|
|
Loading…
Reference in New Issue
Block a user