implement lambda calls in web components

This commit is contained in:
Vyacheslav Matyukhin 2022-08-30 15:16:57 +04:00
parent a7bbfad94b
commit ba280c9292
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
10 changed files with 185 additions and 219 deletions

View File

@ -1,5 +1,5 @@
import * as React from "react"; import * as React from "react";
import { SqLambda, environment } from "@quri/squiggle-lang"; import { SqLambda, environment, SqValueTag } from "@quri/squiggle-lang";
import { FunctionChart1Dist } from "./FunctionChart1Dist"; import { FunctionChart1Dist } from "./FunctionChart1Dist";
import { FunctionChart1Number } from "./FunctionChart1Number"; import { FunctionChart1Number } from "./FunctionChart1Number";
import { DistributionPlottingSettings } from "./DistributionChart"; import { DistributionPlottingSettings } from "./DistributionChart";
@ -33,10 +33,8 @@ export const FunctionChart: React.FC<FunctionChartProps> = ({
</MessageAlert> </MessageAlert>
); );
} }
return <div>NOT IMPLEMENTED IN 0.4 YET</div>; const result1 = fn.call([chartSettings.start]);
/* const result2 = fn.call([chartSettings.stop]);
const result1 = runForeign(fn, [chartSettings.start], environment);
const result2 = runForeign(fn, [chartSettings.stop], environment);
const getValidResult = () => { const getValidResult = () => {
if (result1.tag === "Ok") { if (result1.tag === "Ok") {
return result1; return result1;
@ -55,7 +53,7 @@ export const FunctionChart: React.FC<FunctionChartProps> = ({
} }
switch (validResult.value.tag) { switch (validResult.value.tag) {
case "distribution": case SqValueTag.Distribution:
return ( return (
<FunctionChart1Dist <FunctionChart1Dist
fn={fn} fn={fn}
@ -65,7 +63,7 @@ export const FunctionChart: React.FC<FunctionChartProps> = ({
distributionPlotSettings={distributionPlotSettings} distributionPlotSettings={distributionPlotSettings}
/> />
); );
case "number": case SqValueTag.Number:
return ( return (
<FunctionChart1Number <FunctionChart1Number
fn={fn} fn={fn}
@ -82,5 +80,4 @@ export const FunctionChart: React.FC<FunctionChartProps> = ({
</MessageAlert> </MessageAlert>
); );
} }
*/
}; };

View File

@ -6,6 +6,9 @@ import {
result, result,
SqLambda, SqLambda,
environment, environment,
SqError,
SqValue,
SqValueTag,
} from "@quri/squiggle-lang"; } from "@quri/squiggle-lang";
import { createClassFromSpec } from "react-vega"; import { createClassFromSpec } from "react-vega";
import * as percentilesSpec from "../vega-specs/spec-percentiles.json"; import * as percentilesSpec from "../vega-specs/spec-percentiles.json";
@ -75,9 +78,15 @@ type errors = _.Dictionary<
type point = { x: number; value: result<SqDistribution, string> }; type point = { x: number; value: result<SqDistribution, string> };
let getPercentiles = ({ chartSettings, fn, environment }) => { let getPercentiles = ({
throw new Error("NOT IMPLEMENTED IN 0.4 YET"); chartSettings,
/* fn,
environment,
}: {
chartSettings: FunctionChartSettings;
fn: SqLambda;
environment: environment;
}) => {
let chartPointsToRender = _rangeByCount( let chartPointsToRender = _rangeByCount(
chartSettings.start, chartSettings.start,
chartSettings.stop, chartSettings.stop,
@ -85,9 +94,9 @@ let getPercentiles = ({ chartSettings, fn, environment }) => {
); );
let chartPointsData: point[] = chartPointsToRender.map((x) => { let chartPointsData: point[] = chartPointsToRender.map((x) => {
let result = runForeign(fn, [x], environment); let result = fn.call([x]);
if (result.tag === "Ok") { if (result.tag === "Ok") {
if (result.value.tag === "distribution") { if (result.value.tag === SqValueTag.Distribution) {
return { x, value: { tag: "Ok", value: result.value.value } }; return { x, value: { tag: "Ok", value: result.value.value } };
} else { } else {
return { return {
@ -108,7 +117,7 @@ let getPercentiles = ({ chartSettings, fn, environment }) => {
}); });
let initialPartition: [ let initialPartition: [
{ x: number; value: Distribution }[], { x: number; value: SqDistribution }[],
{ x: number; value: string }[] { x: number; value: string }[]
] = [[], []]; ] = [[], []];
@ -127,27 +136,26 @@ let getPercentiles = ({ chartSettings, fn, environment }) => {
// We convert it to to a pointSet distribution first, so that in case its a sample set // We convert it to to a pointSet distribution first, so that in case its a sample set
// distribution, it doesn't internally convert it to a pointSet distribution for every // distribution, it doesn't internally convert it to a pointSet distribution for every
// single inv() call. // single inv() call.
let toPointSet: Distribution = unwrap(value.toPointSet()); let toPointSet = unwrap(value.pointSet(environment)).asDistribution();
return { return {
x: x, x: x,
p1: unwrap(toPointSet.inv(0.01)), p1: unwrap(toPointSet.inv(environment, 0.01)),
p5: unwrap(toPointSet.inv(0.05)), p5: unwrap(toPointSet.inv(environment, 0.05)),
p10: unwrap(toPointSet.inv(0.1)), p10: unwrap(toPointSet.inv(environment, 0.1)),
p20: unwrap(toPointSet.inv(0.2)), p20: unwrap(toPointSet.inv(environment, 0.2)),
p30: unwrap(toPointSet.inv(0.3)), p30: unwrap(toPointSet.inv(environment, 0.3)),
p40: unwrap(toPointSet.inv(0.4)), p40: unwrap(toPointSet.inv(environment, 0.4)),
p50: unwrap(toPointSet.inv(0.5)), p50: unwrap(toPointSet.inv(environment, 0.5)),
p60: unwrap(toPointSet.inv(0.6)), p60: unwrap(toPointSet.inv(environment, 0.6)),
p70: unwrap(toPointSet.inv(0.7)), p70: unwrap(toPointSet.inv(environment, 0.7)),
p80: unwrap(toPointSet.inv(0.8)), p80: unwrap(toPointSet.inv(environment, 0.8)),
p90: unwrap(toPointSet.inv(0.9)), p90: unwrap(toPointSet.inv(environment, 0.9)),
p95: unwrap(toPointSet.inv(0.95)), p95: unwrap(toPointSet.inv(environment, 0.95)),
p99: unwrap(toPointSet.inv(0.99)), p99: unwrap(toPointSet.inv(environment, 0.99)),
}; };
}); });
return { percentiles, errors: groupedErrors }; return { percentiles, errors: groupedErrors };
*/
}; };
export const FunctionChart1Dist: React.FC<FunctionChart1DistProps> = ({ export const FunctionChart1Dist: React.FC<FunctionChart1DistProps> = ({
@ -166,23 +174,21 @@ export const FunctionChart1Dist: React.FC<FunctionChart1DistProps> = ({
} }
const signalListeners = { mousemove: handleHover, mouseout: handleOut }; const signalListeners = { mousemove: handleHover, mouseout: handleOut };
return <div>NOT IMPLEMENTED IN 0.4 YET</div>;
/*
//TODO: This custom error handling is a bit hacky and should be improved. //TODO: This custom error handling is a bit hacky and should be improved.
let mouseItem: result<squiggleExpression, errorValue> = !!mouseOverlay let mouseItem: result<SqValue, SqError> = !!mouseOverlay
? runForeign(fn, [mouseOverlay], environment) ? fn.call([mouseOverlay])
: { : {
tag: "Error", tag: "Error",
value: { value: SqError.createOtherError(
tag: "RETodo", "Hover x-coordinate returned NaN. Expected a number."
value: "Hover x-coordinate returned NaN. Expected a number.", ),
},
}; };
let showChart = let showChart =
mouseItem.tag === "Ok" && mouseItem.value.tag === "distribution" ? ( mouseItem.tag === "Ok" &&
mouseItem.value.tag === SqValueTag.Distribution ? (
<DistributionChart <DistributionChart
plot={defaultPlot(mouseItem.value.value)} plot={defaultPlot(mouseItem.value.value)}
environment={environment}
width={400} width={400}
height={50} height={50}
{...distributionPlotSettings} {...distributionPlotSettings}
@ -219,5 +225,4 @@ export const FunctionChart1Dist: React.FC<FunctionChart1DistProps> = ({
)} )}
</> </>
); );
*/
}; };

View File

@ -1,10 +1,11 @@
import * as React from "react"; import * as React from "react";
import _ from "lodash"; import _ from "lodash";
import type { Spec } from "vega"; import type { Spec } from "vega";
import { result, SqLambda, environment } from "@quri/squiggle-lang"; import { result, SqLambda, environment, SqValueTag } from "@quri/squiggle-lang";
import { createClassFromSpec } from "react-vega"; import { createClassFromSpec } from "react-vega";
import * as lineChartSpec from "../vega-specs/spec-line-chart.json"; import * as lineChartSpec from "../vega-specs/spec-line-chart.json";
import { ErrorAlert } from "./Alert"; import { ErrorAlert } from "./Alert";
import { squiggleValueTag } from "@quri/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_tag";
let SquiggleLineChart = createClassFromSpec({ let SquiggleLineChart = createClassFromSpec({
spec: lineChartSpec as Spec, spec: lineChartSpec as Spec,
@ -32,9 +33,15 @@ interface FunctionChart1NumberProps {
type point = { x: number; value: result<number, string> }; type point = { x: number; value: result<number, string> };
let getFunctionImage = ({ chartSettings, fn, environment }) => { let getFunctionImage = ({
throw new Error("NOT IMPLEMENTED IN 0.4 YET"); chartSettings,
/* fn,
environment,
}: {
chartSettings: FunctionChartSettings;
fn: SqLambda;
environment: environment;
}) => {
let chartPointsToRender = _rangeByCount( let chartPointsToRender = _rangeByCount(
chartSettings.start, chartSettings.start,
chartSettings.stop, chartSettings.stop,
@ -42,9 +49,9 @@ let getFunctionImage = ({ chartSettings, fn, environment }) => {
); );
let chartPointsData: point[] = chartPointsToRender.map((x) => { let chartPointsData: point[] = chartPointsToRender.map((x) => {
let result = runForeign(fn, [x], environment); let result = fn.call([x]);
if (result.tag === "Ok") { if (result.tag === "Ok") {
if (result.value.tag == "number") { if (result.value.tag === SqValueTag.Number) {
return { x, value: { tag: "Ok", value: result.value.value } }; return { x, value: { tag: "Ok", value: result.value.value } };
} else { } else {
return { return {
@ -78,7 +85,6 @@ let getFunctionImage = ({ chartSettings, fn, environment }) => {
}, initialPartition); }, initialPartition);
return { errors, functionImage }; return { errors, functionImage };
*/
}; };
export const FunctionChart1Number: React.FC<FunctionChart1NumberProps> = ({ export const FunctionChart1Number: React.FC<FunctionChart1NumberProps> = ({
@ -87,8 +93,6 @@ export const FunctionChart1Number: React.FC<FunctionChart1NumberProps> = ({
environment, environment,
height, height,
}: FunctionChart1NumberProps) => { }: FunctionChart1NumberProps) => {
return <div>NOT IMPLEMENTED IN 0.4 YET</div>;
/*
let getFunctionImageMemoized = React.useMemo( let getFunctionImageMemoized = React.useMemo(
() => getFunctionImage({ chartSettings, fn, environment }), () => getFunctionImage({ chartSettings, fn, environment }),
[environment, fn] [environment, fn]
@ -112,5 +116,4 @@ export const FunctionChart1Number: React.FC<FunctionChart1NumberProps> = ({
))} ))}
</> </>
); );
*/
}; };

View File

@ -6,4 +6,12 @@ export class SqError {
toString() { toString() {
return RSErrorValue.toString(this._value); return RSErrorValue.toString(this._value);
} }
static createTodoError(v: string) {
return new SqError(RSErrorValue.createTodoError(v));
}
static createOtherError(v: string) {
return new SqError(RSErrorValue.createOtherError(v));
}
} }

View File

@ -1,5 +1,8 @@
import * as RSLambda from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Lambda.gen"; import * as RSLambda from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Lambda.gen";
import { SqError } from "./SqError";
import { SqValue } from "./SqValue";
import { SqValueLocation } from "./SqValueLocation"; import { SqValueLocation } from "./SqValueLocation";
import { result } from "./types";
type T = RSLambda.squiggleValue_Lambda; type T = RSLambda.squiggleValue_Lambda;
@ -9,4 +12,32 @@ export class SqLambda {
parameters() { parameters() {
return RSLambda.parameters(this._value); return RSLambda.parameters(this._value);
} }
call(args: (number | string)[]): result<SqValue, SqError> {
const { project, sourceId } = this.location;
// Might be good to use uuid instead, but there's no way to remove sources from projects.
// So this is not thread-safe.
const callId = "__lambda__";
if (this.location.path.root !== "bindings") {
return {
tag: "Error",
value: SqError.createTodoError("Only bindings lambdas can be rendered"),
};
}
const quote = (arg: string) =>
`"${arg.replace(new RegExp('"', "g"), '\\"')}"`;
const argsSource = args
.map((arg) => (typeof arg === "number" ? arg : quote(arg)))
.join(",");
const functionNameSource = this.location.path.items
.map((item, i) =>
typeof item === "string" ? (i ? "." + item : item) : `[${item}]`
)
.join("");
const source = `${functionNameSource}(${argsSource})`;
project.setSource(callId, source);
project.setContinues(callId, [sourceId]);
project.run(callId);
return project.getResult(callId);
}
} }

View File

@ -1,4 +1,5 @@
import * as _ from "lodash"; import * as _ from "lodash";
import { wrapDistribution } from "./SqDistribution";
import * as RSPointSetDist from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution.gen"; import * as RSPointSetDist from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution.gen";
import { pointSetDistributionTag as Tag } from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution_tag"; import { pointSetDistributionTag as Tag } from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution_tag";
@ -34,6 +35,10 @@ abstract class SqAbstractPointSetDist {
if (!value) throw new Error("Internal casting error"); if (!value) throw new Error("Internal casting error");
return value; return value;
}; };
asDistribution() {
return wrapDistribution(RSPointSetDist.toDistribution(this._value));
}
} }
export class SqMixedPointSetDist extends SqAbstractPointSetDist { export class SqMixedPointSetDist extends SqAbstractPointSetDist {

View File

@ -45,3 +45,6 @@ let getContinues = (variant: pointSetDistribution): 'd =>
| Continuous(continuous) => continuous->Some | Continuous(continuous) => continuous->Some
| _ => None | _ => None
} }
@genType
let toDistribution = (v: pointSetDistribution): DistributionTypes.genericDist => PointSet(v)

View File

@ -10,3 +10,9 @@ let getLocation = (e: reducerErrorValue): option<syntaxErrorLocation> =>
| RESyntaxError(_, optionalLocation) => optionalLocation | RESyntaxError(_, optionalLocation) => optionalLocation
| _ => None | _ => None
} }
@genType
let createTodoError = (v: string) => Reducer_ErrorValue.RETodo(v)
@genType
let createOtherError = (v: string) => Reducer_ErrorValue.REOther(v)

View File

@ -22,6 +22,7 @@ type errorValue =
| RETodo(string) // To do | RETodo(string) // To do
| REUnitNotFound(string) | REUnitNotFound(string)
| RENeedToRun | RENeedToRun
| REOther(string)
type t = errorValue type t = errorValue
@ -59,4 +60,5 @@ let errorToString = err =>
| REExpectedType(typeName, valueString) => `Expected type: ${typeName} but got: ${valueString}` | REExpectedType(typeName, valueString) => `Expected type: ${typeName} but got: ${valueString}`
| REUnitNotFound(unitName) => `Unit not found: ${unitName}` | REUnitNotFound(unitName) => `Unit not found: ${unitName}`
| RENeedToRun => "Need to run" | RENeedToRun => "Need to run"
| REOther(msg) => `Error: ${msg}`
} }

View File

@ -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,9 +27,7 @@ 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);
@ -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;
} }
@ -80,7 +67,7 @@ peg$SyntaxError.prototype.format = function (sources) {
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) {
@ -90,9 +77,7 @@ peg$SyntaxError.buildMessage = function (expected, found) {
: classEscape(part); : classEscape(part);
}); });
return ( return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
"[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]"
);
}, },
any: function() { any: function() {
@ -105,7 +90,7 @@ peg$SyntaxError.buildMessage = function (expected, found) {
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) {
@ -138,12 +119,8 @@ peg$SyntaxError.buildMessage = function (expected, found) {
.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) {
@ -206,7 +175,7 @@ function peg$parse(input, options) {
var peg$c0 = "#include"; var peg$c0 = "#include";
var peg$c1 = "'"; var peg$c1 = "'";
var peg$c2 = '"'; var peg$c2 = "\"";
var peg$c3 = "//"; var peg$c3 = "//";
var peg$c4 = "/*"; var peg$c4 = "/*";
var peg$c5 = "*/"; var peg$c5 = "*/";
@ -222,8 +191,8 @@ function peg$parse(input, options) {
var peg$e1 = peg$otherExpectation("string"); var peg$e1 = peg$otherExpectation("string");
var peg$e2 = peg$literalExpectation("'", false); var peg$e2 = peg$literalExpectation("'", false);
var peg$e3 = peg$classExpectation(["'"], true, false); var peg$e3 = peg$classExpectation(["'"], true, false);
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$literalExpectation("/*", false); var peg$e7 = peg$literalExpectation("/*", false);
var peg$e8 = peg$classExpectation(["*"], true, false); var peg$e8 = peg$classExpectation(["*"], true, false);
@ -234,24 +203,12 @@ function peg$parse(input, options) {
var peg$e13 = peg$classExpectation(["\n", "\r"], false, false); var peg$e13 = peg$classExpectation(["\n", "\r"], false, false);
var peg$e14 = peg$classExpectation(["\r", "\n"], true, false); var peg$e14 = peg$classExpectation(["\r", "\n"], true, false);
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(characters) {return characters.join('');};
var peg$f1 = function () { var peg$f3 = function(characters) {return characters.join('');};
return []; var peg$f4 = function() { return '';};
}; var peg$f5 = function() { return '';};
var peg$f2 = function (characters) {
return characters.join("");
};
var peg$f3 = function (characters) {
return characters.join("");
};
var peg$f4 = function () {
return "";
};
var peg$f5 = function () {
return "";
};
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 }];
@ -265,9 +222,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];
@ -285,7 +240,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
}; };
} }
@ -294,8 +249,7 @@ 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);
@ -307,8 +261,7 @@ 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);
@ -320,12 +273,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() {
@ -355,7 +303,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) {
@ -384,20 +332,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;
@ -585,9 +531,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$e0); }
peg$fail(peg$e0);
}
} }
if (s2 !== peg$FAILED) { if (s2 !== peg$FAILED) {
s3 = []; s3 = [];
@ -645,9 +589,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$e2); }
peg$fail(peg$e2);
}
} }
if (s2 !== peg$FAILED) { if (s2 !== peg$FAILED) {
s3 = []; s3 = [];
@ -656,9 +598,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$e3); }
peg$fail(peg$e3);
}
} }
while (s4 !== peg$FAILED) { while (s4 !== peg$FAILED) {
s3.push(s4); s3.push(s4);
@ -667,9 +607,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$e3); }
peg$fail(peg$e3);
}
} }
} }
if (input.charCodeAt(peg$currPos) === 39) { if (input.charCodeAt(peg$currPos) === 39) {
@ -677,9 +615,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$e2); }
peg$fail(peg$e2);
}
} }
if (s4 !== peg$FAILED) { if (s4 !== peg$FAILED) {
s1 = s3; s1 = s3;
@ -704,9 +640,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 = [];
@ -715,9 +649,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);
@ -726,9 +658,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) === 34) { if (input.charCodeAt(peg$currPos) === 34) {
@ -736,9 +666,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;
@ -759,9 +687,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$e1); }
peg$fail(peg$e1);
}
} }
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -823,9 +749,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$e6); }
peg$fail(peg$e6);
}
} }
if (s1 !== peg$FAILED) { if (s1 !== peg$FAILED) {
s2 = []; s2 = [];
@ -864,9 +788,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$e7); }
peg$fail(peg$e7);
}
} }
if (s1 !== peg$FAILED) { if (s1 !== peg$FAILED) {
s2 = []; s2 = [];
@ -875,9 +797,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$e8); }
peg$fail(peg$e8);
}
} }
while (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) {
s2.push(s3); s2.push(s3);
@ -886,9 +806,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$e8); }
peg$fail(peg$e8);
}
} }
} }
if (input.substr(peg$currPos, 2) === peg$c5) { if (input.substr(peg$currPos, 2) === peg$c5) {
@ -896,9 +814,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$e9); }
peg$fail(peg$e9);
}
} }
if (s3 !== peg$FAILED) { if (s3 !== peg$FAILED) {
peg$savedPos = s0; peg$savedPos = s0;
@ -935,16 +851,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$e11); }
peg$fail(peg$e11);
}
} }
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$e10); }
peg$fail(peg$e10);
}
} }
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -970,16 +882,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$e13); }
peg$fail(peg$e13);
}
} }
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$e12); }
peg$fail(peg$e12);
}
} }
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -1004,9 +912,7 @@ 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$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -1035,5 +941,5 @@ function peg$parse(input, options) {
module.exports = { module.exports = {
SyntaxError: peg$SyntaxError, SyntaxError: peg$SyntaxError,
parse: peg$parse, parse: peg$parse
}; };