From ba280c9292d12615e3d3e578261393bf1ac956d6 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 30 Aug 2022 15:16:57 +0400 Subject: [PATCH] implement lambda calls in web components --- .../src/components/FunctionChart.tsx | 13 +- .../src/components/FunctionChart1Dist.tsx | 69 ++--- .../src/components/FunctionChart1Number.tsx | 23 +- packages/squiggle-lang/src/js/SqError.ts | 8 + packages/squiggle-lang/src/js/SqLambda.ts | 31 +++ .../squiggle-lang/src/js/SqPointSetDist.ts | 5 + ...orTS_Distribution_PointSetDistribution.res | 3 + .../ForTS/ForTS_Reducer_ErrorValue.res | 6 + .../rescript/Reducer/Reducer_ErrorValue.res | 2 + .../ReducerProject_IncludeParser.js | 244 ++++++------------ 10 files changed, 185 insertions(+), 219 deletions(-) diff --git a/packages/components/src/components/FunctionChart.tsx b/packages/components/src/components/FunctionChart.tsx index 2e4e5754..2da5d367 100644 --- a/packages/components/src/components/FunctionChart.tsx +++ b/packages/components/src/components/FunctionChart.tsx @@ -1,5 +1,5 @@ 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 { FunctionChart1Number } from "./FunctionChart1Number"; import { DistributionPlottingSettings } from "./DistributionChart"; @@ -33,10 +33,8 @@ export const FunctionChart: React.FC = ({ ); } - return
NOT IMPLEMENTED IN 0.4 YET
; - /* - const result1 = runForeign(fn, [chartSettings.start], environment); - const result2 = runForeign(fn, [chartSettings.stop], environment); + const result1 = fn.call([chartSettings.start]); + const result2 = fn.call([chartSettings.stop]); const getValidResult = () => { if (result1.tag === "Ok") { return result1; @@ -55,7 +53,7 @@ export const FunctionChart: React.FC = ({ } switch (validResult.value.tag) { - case "distribution": + case SqValueTag.Distribution: return ( = ({ distributionPlotSettings={distributionPlotSettings} /> ); - case "number": + case SqValueTag.Number: return ( = ({ ); } - */ }; diff --git a/packages/components/src/components/FunctionChart1Dist.tsx b/packages/components/src/components/FunctionChart1Dist.tsx index f7b842ab..c6064e7b 100644 --- a/packages/components/src/components/FunctionChart1Dist.tsx +++ b/packages/components/src/components/FunctionChart1Dist.tsx @@ -6,6 +6,9 @@ import { result, SqLambda, environment, + SqError, + SqValue, + SqValueTag, } from "@quri/squiggle-lang"; import { createClassFromSpec } from "react-vega"; import * as percentilesSpec from "../vega-specs/spec-percentiles.json"; @@ -75,9 +78,15 @@ type errors = _.Dictionary< type point = { x: number; value: result }; -let getPercentiles = ({ chartSettings, fn, environment }) => { - throw new Error("NOT IMPLEMENTED IN 0.4 YET"); - /* +let getPercentiles = ({ + chartSettings, + fn, + environment, +}: { + chartSettings: FunctionChartSettings; + fn: SqLambda; + environment: environment; +}) => { let chartPointsToRender = _rangeByCount( chartSettings.start, chartSettings.stop, @@ -85,9 +94,9 @@ let getPercentiles = ({ chartSettings, fn, environment }) => { ); let chartPointsData: point[] = chartPointsToRender.map((x) => { - let result = runForeign(fn, [x], environment); + let result = fn.call([x]); if (result.tag === "Ok") { - if (result.value.tag === "distribution") { + if (result.value.tag === SqValueTag.Distribution) { return { x, value: { tag: "Ok", value: result.value.value } }; } else { return { @@ -108,7 +117,7 @@ let getPercentiles = ({ chartSettings, fn, environment }) => { }); let initialPartition: [ - { x: number; value: Distribution }[], + { x: number; value: SqDistribution }[], { 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 // distribution, it doesn't internally convert it to a pointSet distribution for every // single inv() call. - let toPointSet: Distribution = unwrap(value.toPointSet()); + let toPointSet = unwrap(value.pointSet(environment)).asDistribution(); return { x: x, - p1: unwrap(toPointSet.inv(0.01)), - p5: unwrap(toPointSet.inv(0.05)), - p10: unwrap(toPointSet.inv(0.1)), - p20: unwrap(toPointSet.inv(0.2)), - p30: unwrap(toPointSet.inv(0.3)), - p40: unwrap(toPointSet.inv(0.4)), - p50: unwrap(toPointSet.inv(0.5)), - p60: unwrap(toPointSet.inv(0.6)), - p70: unwrap(toPointSet.inv(0.7)), - p80: unwrap(toPointSet.inv(0.8)), - p90: unwrap(toPointSet.inv(0.9)), - p95: unwrap(toPointSet.inv(0.95)), - p99: unwrap(toPointSet.inv(0.99)), + p1: unwrap(toPointSet.inv(environment, 0.01)), + p5: unwrap(toPointSet.inv(environment, 0.05)), + p10: unwrap(toPointSet.inv(environment, 0.1)), + p20: unwrap(toPointSet.inv(environment, 0.2)), + p30: unwrap(toPointSet.inv(environment, 0.3)), + p40: unwrap(toPointSet.inv(environment, 0.4)), + p50: unwrap(toPointSet.inv(environment, 0.5)), + p60: unwrap(toPointSet.inv(environment, 0.6)), + p70: unwrap(toPointSet.inv(environment, 0.7)), + p80: unwrap(toPointSet.inv(environment, 0.8)), + p90: unwrap(toPointSet.inv(environment, 0.9)), + p95: unwrap(toPointSet.inv(environment, 0.95)), + p99: unwrap(toPointSet.inv(environment, 0.99)), }; }); return { percentiles, errors: groupedErrors }; - */ }; export const FunctionChart1Dist: React.FC = ({ @@ -166,23 +174,21 @@ export const FunctionChart1Dist: React.FC = ({ } const signalListeners = { mousemove: handleHover, mouseout: handleOut }; - return
NOT IMPLEMENTED IN 0.4 YET
; - - /* //TODO: This custom error handling is a bit hacky and should be improved. - let mouseItem: result = !!mouseOverlay - ? runForeign(fn, [mouseOverlay], environment) + let mouseItem: result = !!mouseOverlay + ? fn.call([mouseOverlay]) : { tag: "Error", - value: { - tag: "RETodo", - value: "Hover x-coordinate returned NaN. Expected a number.", - }, + value: SqError.createOtherError( + "Hover x-coordinate returned NaN. Expected a number." + ), }; let showChart = - mouseItem.tag === "Ok" && mouseItem.value.tag === "distribution" ? ( + mouseItem.tag === "Ok" && + mouseItem.value.tag === SqValueTag.Distribution ? ( = ({ )} ); - */ }; diff --git a/packages/components/src/components/FunctionChart1Number.tsx b/packages/components/src/components/FunctionChart1Number.tsx index 76e74cca..e0a3b33b 100644 --- a/packages/components/src/components/FunctionChart1Number.tsx +++ b/packages/components/src/components/FunctionChart1Number.tsx @@ -1,10 +1,11 @@ import * as React from "react"; import _ from "lodash"; 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 * as lineChartSpec from "../vega-specs/spec-line-chart.json"; import { ErrorAlert } from "./Alert"; +import { squiggleValueTag } from "@quri/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_tag"; let SquiggleLineChart = createClassFromSpec({ spec: lineChartSpec as Spec, @@ -32,9 +33,15 @@ interface FunctionChart1NumberProps { type point = { x: number; value: result }; -let getFunctionImage = ({ chartSettings, fn, environment }) => { - throw new Error("NOT IMPLEMENTED IN 0.4 YET"); - /* +let getFunctionImage = ({ + chartSettings, + fn, + environment, +}: { + chartSettings: FunctionChartSettings; + fn: SqLambda; + environment: environment; +}) => { let chartPointsToRender = _rangeByCount( chartSettings.start, chartSettings.stop, @@ -42,9 +49,9 @@ let getFunctionImage = ({ chartSettings, fn, environment }) => { ); let chartPointsData: point[] = chartPointsToRender.map((x) => { - let result = runForeign(fn, [x], environment); + let result = fn.call([x]); if (result.tag === "Ok") { - if (result.value.tag == "number") { + if (result.value.tag === SqValueTag.Number) { return { x, value: { tag: "Ok", value: result.value.value } }; } else { return { @@ -78,7 +85,6 @@ let getFunctionImage = ({ chartSettings, fn, environment }) => { }, initialPartition); return { errors, functionImage }; - */ }; export const FunctionChart1Number: React.FC = ({ @@ -87,8 +93,6 @@ export const FunctionChart1Number: React.FC = ({ environment, height, }: FunctionChart1NumberProps) => { - return
NOT IMPLEMENTED IN 0.4 YET
; - /* let getFunctionImageMemoized = React.useMemo( () => getFunctionImage({ chartSettings, fn, environment }), [environment, fn] @@ -112,5 +116,4 @@ export const FunctionChart1Number: React.FC = ({ ))} ); - */ }; diff --git a/packages/squiggle-lang/src/js/SqError.ts b/packages/squiggle-lang/src/js/SqError.ts index 573f19a0..317fde4f 100644 --- a/packages/squiggle-lang/src/js/SqError.ts +++ b/packages/squiggle-lang/src/js/SqError.ts @@ -6,4 +6,12 @@ export class SqError { toString() { 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)); + } } diff --git a/packages/squiggle-lang/src/js/SqLambda.ts b/packages/squiggle-lang/src/js/SqLambda.ts index 81fd1c53..ec5714a1 100644 --- a/packages/squiggle-lang/src/js/SqLambda.ts +++ b/packages/squiggle-lang/src/js/SqLambda.ts @@ -1,5 +1,8 @@ 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 { result } from "./types"; type T = RSLambda.squiggleValue_Lambda; @@ -9,4 +12,32 @@ export class SqLambda { parameters() { return RSLambda.parameters(this._value); } + + call(args: (number | string)[]): result { + 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); + } } diff --git a/packages/squiggle-lang/src/js/SqPointSetDist.ts b/packages/squiggle-lang/src/js/SqPointSetDist.ts index 529c6feb..524c9319 100644 --- a/packages/squiggle-lang/src/js/SqPointSetDist.ts +++ b/packages/squiggle-lang/src/js/SqPointSetDist.ts @@ -1,4 +1,5 @@ import * as _ from "lodash"; +import { wrapDistribution } from "./SqDistribution"; 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"; @@ -34,6 +35,10 @@ abstract class SqAbstractPointSetDist { if (!value) throw new Error("Internal casting error"); return value; }; + + asDistribution() { + return wrapDistribution(RSPointSetDist.toDistribution(this._value)); + } } export class SqMixedPointSetDist extends SqAbstractPointSetDist { diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution.res index 3b4193bc..e17bd00c 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution.res @@ -45,3 +45,6 @@ let getContinues = (variant: pointSetDistribution): 'd => | Continuous(continuous) => continuous->Some | _ => None } + +@genType +let toDistribution = (v: pointSetDistribution): DistributionTypes.genericDist => PointSet(v) diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Reducer_ErrorValue.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Reducer_ErrorValue.res index 61dc3bac..d4a8059b 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Reducer_ErrorValue.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Reducer_ErrorValue.res @@ -10,3 +10,9 @@ let getLocation = (e: reducerErrorValue): option => | RESyntaxError(_, optionalLocation) => optionalLocation | _ => None } + +@genType +let createTodoError = (v: string) => Reducer_ErrorValue.RETodo(v) + +@genType +let createOtherError = (v: string) => Reducer_ErrorValue.REOther(v) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res index 55cde709..46da2216 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res @@ -22,6 +22,7 @@ type errorValue = | RETodo(string) // To do | REUnitNotFound(string) | RENeedToRun + | REOther(string) type t = errorValue @@ -59,4 +60,5 @@ let errorToString = err => | REExpectedType(typeName, valueString) => `Expected type: ${typeName} but got: ${valueString}` | REUnitNotFound(unitName) => `Unit not found: ${unitName}` | RENeedToRun => "Need to run" + | REOther(msg) => `Error: ${msg}` } diff --git a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_IncludeParser.js b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_IncludeParser.js index abb57e82..e04b8ba2 100644 --- a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_IncludeParser.js +++ b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_IncludeParser.js @@ -5,9 +5,7 @@ "use strict"; function peg$subclass(child, parent) { - function C() { - this.constructor = child; - } + function C() { this.constructor = child; } C.prototype = parent.prototype; child.prototype = new C(); } @@ -29,15 +27,13 @@ peg$subclass(peg$SyntaxError, Error); function peg$padEnd(str, targetLength, padString) { padString = padString || " "; - if (str.length > targetLength) { - return str; - } + if (str.length > targetLength) { return str; } targetLength -= str.length; padString += padString.repeat(targetLength); return str + padString.slice(0, targetLength); } -peg$SyntaxError.prototype.format = function (sources) { +peg$SyntaxError.prototype.format = function(sources) { var str = "Error: " + this.message; if (this.location) { var src = null; @@ -52,24 +48,15 @@ peg$SyntaxError.prototype.format = function (sources) { var loc = this.location.source + ":" + s.line + ":" + s.column; if (src) { 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 last = s.line === e.line ? e.column : line.length + 1; - var hatLen = last - s.column || 1; - str += - "\n --> " + - loc + - "\n" + - filler + - " |\n" + - s.line + - " | " + - line + - "\n" + - filler + - " | " + - peg$padEnd("", s.column - 1, " ") + - peg$padEnd("", hatLen, "^"); + var hatLen = (last - s.column) || 1; + str += "\n --> " + loc + "\n" + + filler + " |\n" + + s.line + " | " + line + "\n" + + filler + " | " + peg$padEnd("", s.column - 1, ' ') + + peg$padEnd("", hatLen, "^"); } else { str += "\n at " + loc; } @@ -77,35 +64,33 @@ peg$SyntaxError.prototype.format = function (sources) { return str; }; -peg$SyntaxError.buildMessage = function (expected, found) { +peg$SyntaxError.buildMessage = function(expected, found) { var DESCRIBE_EXPECTATION_FNS = { - literal: function (expectation) { - return '"' + literalEscape(expectation.text) + '"'; + literal: function(expectation) { + return "\"" + literalEscape(expectation.text) + "\""; }, - class: function (expectation) { - var escapedParts = expectation.parts.map(function (part) { + class: function(expectation) { + var escapedParts = expectation.parts.map(function(part) { return Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part); }); - return ( - "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" - ); + return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]"; }, - any: function () { + any: function() { return "any character"; }, - end: function () { + end: function() { return "end of input"; }, - other: function (expectation) { + other: function(expectation) { return expectation.description; - }, + } }; function hex(ch) { @@ -115,17 +100,13 @@ peg$SyntaxError.buildMessage = function (expected, found) { function literalEscape(s) { return s .replace(/\\/g, "\\\\") - .replace(/"/g, '\\"') + .replace(/"/g, "\\\"") .replace(/\0/g, "\\0") .replace(/\t/g, "\\t") .replace(/\n/g, "\\n") .replace(/\r/g, "\\r") - .replace(/[\x00-\x0F]/g, function (ch) { - return "\\x0" + hex(ch); - }) - .replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { - return "\\x" + hex(ch); - }); + .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); }) + .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); }); } function classEscape(s) { @@ -133,17 +114,13 @@ peg$SyntaxError.buildMessage = function (expected, found) { .replace(/\\/g, "\\\\") .replace(/\]/g, "\\]") .replace(/\^/g, "\\^") - .replace(/-/g, "\\-") + .replace(/-/g, "\\-") .replace(/\0/g, "\\0") .replace(/\t/g, "\\t") .replace(/\n/g, "\\n") .replace(/\r/g, "\\r") - .replace(/[\x00-\x0F]/g, function (ch) { - return "\\x0" + hex(ch); - }) - .replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { - return "\\x" + hex(ch); - }); + .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); }) + .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); }); } function describeExpectation(expectation) { @@ -174,25 +151,17 @@ peg$SyntaxError.buildMessage = function (expected, found) { return descriptions[0] + " or " + descriptions[1]; default: - return ( - descriptions.slice(0, -1).join(", ") + - ", or " + - descriptions[descriptions.length - 1] - ); + return descriptions.slice(0, -1).join(", ") + + ", or " + + descriptions[descriptions.length - 1]; } } function describeFound(found) { - return found ? '"' + literalEscape(found) + '"' : "end of input"; + return found ? "\"" + literalEscape(found) + "\"" : "end of input"; } - return ( - "Expected " + - describeExpected(expected) + - " but " + - describeFound(found) + - " found." - ); + return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; }; function peg$parse(input, options) { @@ -206,7 +175,7 @@ function peg$parse(input, options) { var peg$c0 = "#include"; var peg$c1 = "'"; - var peg$c2 = '"'; + var peg$c2 = "\""; var peg$c3 = "//"; var peg$c4 = "/*"; var peg$c5 = "*/"; @@ -222,8 +191,8 @@ function peg$parse(input, options) { var peg$e1 = peg$otherExpectation("string"); var peg$e2 = peg$literalExpectation("'", false); var peg$e3 = peg$classExpectation(["'"], true, false); - var peg$e4 = peg$literalExpectation('"', false); - var peg$e5 = peg$classExpectation(['"'], true, false); + var peg$e4 = peg$literalExpectation("\"", false); + var peg$e5 = peg$classExpectation(["\""], true, false); var peg$e6 = peg$literalExpectation("//", false); var peg$e7 = peg$literalExpectation("/*", 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$e14 = peg$classExpectation(["\r", "\n"], true, false); - var peg$f0 = function (head, tail) { - return [head, ...tail].filter((e) => e != ""); - }; - var peg$f1 = 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$f0 = function(head, tail) {return [head, ...tail].filter( e => e != '');}; + var peg$f1 = 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$savedPos = 0; var peg$posDetailsCache = [{ line: 1, column: 1 }]; @@ -265,9 +222,7 @@ function peg$parse(input, options) { if ("startRule" in options) { if (!(options.startRule in peg$startRuleFunctions)) { - throw new Error( - "Can't start parsing from rule \"" + options.startRule + '".' - ); + throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); } peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; @@ -285,7 +240,7 @@ function peg$parse(input, options) { return { source: peg$source, start: peg$savedPos, - end: peg$currPos, + end: peg$currPos }; } @@ -294,10 +249,9 @@ function peg$parse(input, options) { } function expected(description, location) { - location = - location !== undefined - ? location - : peg$computeLocation(peg$savedPos, peg$currPos); + location = location !== undefined + ? location + : peg$computeLocation(peg$savedPos, peg$currPos); throw peg$buildStructuredError( [peg$otherExpectation(description)], @@ -307,10 +261,9 @@ function peg$parse(input, options) { } function error(message, location) { - location = - location !== undefined - ? location - : peg$computeLocation(peg$savedPos, peg$currPos); + location = location !== undefined + ? location + : peg$computeLocation(peg$savedPos, peg$currPos); throw peg$buildSimpleError(message, location); } @@ -320,12 +273,7 @@ function peg$parse(input, options) { } function peg$classExpectation(parts, inverted, ignoreCase) { - return { - type: "class", - parts: parts, - inverted: inverted, - ignoreCase: ignoreCase, - }; + return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; } function peg$anyExpectation() { @@ -355,7 +303,7 @@ function peg$parse(input, options) { details = peg$posDetailsCache[p]; details = { line: details.line, - column: details.column, + column: details.column }; while (p < pos) { @@ -384,20 +332,18 @@ function peg$parse(input, options) { start: { offset: startPos, line: startPosDetails.line, - column: startPosDetails.column, + column: startPosDetails.column }, end: { offset: endPos, line: endPosDetails.line, - column: endPosDetails.column, - }, + column: endPosDetails.column + } }; } function peg$fail(expected) { - if (peg$currPos < peg$maxFailPos) { - return; - } + if (peg$currPos < peg$maxFailPos) { return; } if (peg$currPos > peg$maxFailPos) { peg$maxFailPos = peg$currPos; @@ -585,9 +531,7 @@ function peg$parse(input, options) { peg$currPos += 8; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e0); - } + if (peg$silentFails === 0) { peg$fail(peg$e0); } } if (s2 !== peg$FAILED) { s3 = []; @@ -645,9 +589,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e2); - } + if (peg$silentFails === 0) { peg$fail(peg$e2); } } if (s2 !== peg$FAILED) { s3 = []; @@ -656,9 +598,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e3); - } + if (peg$silentFails === 0) { peg$fail(peg$e3); } } while (s4 !== peg$FAILED) { s3.push(s4); @@ -667,9 +607,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e3); - } + if (peg$silentFails === 0) { peg$fail(peg$e3); } } } if (input.charCodeAt(peg$currPos) === 39) { @@ -677,9 +615,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e2); - } + if (peg$silentFails === 0) { peg$fail(peg$e2); } } if (s4 !== peg$FAILED) { s1 = s3; @@ -704,9 +640,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e4); - } + if (peg$silentFails === 0) { peg$fail(peg$e4); } } if (s2 !== peg$FAILED) { s3 = []; @@ -715,9 +649,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e5); - } + if (peg$silentFails === 0) { peg$fail(peg$e5); } } while (s4 !== peg$FAILED) { s3.push(s4); @@ -726,9 +658,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e5); - } + if (peg$silentFails === 0) { peg$fail(peg$e5); } } } if (input.charCodeAt(peg$currPos) === 34) { @@ -736,9 +666,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e4); - } + if (peg$silentFails === 0) { peg$fail(peg$e4); } } if (s4 !== peg$FAILED) { s1 = s3; @@ -759,9 +687,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e1); - } + if (peg$silentFails === 0) { peg$fail(peg$e1); } } peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; @@ -823,9 +749,7 @@ function peg$parse(input, options) { peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e6); - } + if (peg$silentFails === 0) { peg$fail(peg$e6); } } if (s1 !== peg$FAILED) { s2 = []; @@ -864,9 +788,7 @@ function peg$parse(input, options) { peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e7); - } + if (peg$silentFails === 0) { peg$fail(peg$e7); } } if (s1 !== peg$FAILED) { s2 = []; @@ -875,9 +797,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e8); - } + if (peg$silentFails === 0) { peg$fail(peg$e8); } } while (s3 !== peg$FAILED) { s2.push(s3); @@ -886,9 +806,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e8); - } + if (peg$silentFails === 0) { peg$fail(peg$e8); } } } if (input.substr(peg$currPos, 2) === peg$c5) { @@ -896,9 +814,7 @@ function peg$parse(input, options) { peg$currPos += 2; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e9); - } + if (peg$silentFails === 0) { peg$fail(peg$e9); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; @@ -935,16 +851,12 @@ function peg$parse(input, options) { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e11); - } + if (peg$silentFails === 0) { peg$fail(peg$e11); } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e10); - } + if (peg$silentFails === 0) { peg$fail(peg$e10); } } peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; @@ -970,16 +882,12 @@ function peg$parse(input, options) { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e13); - } + if (peg$silentFails === 0) { peg$fail(peg$e13); } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e12); - } + if (peg$silentFails === 0) { peg$fail(peg$e12); } } peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; @@ -1004,9 +912,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { - peg$fail(peg$e14); - } + if (peg$silentFails === 0) { peg$fail(peg$e14); } } peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; @@ -1035,5 +941,5 @@ function peg$parse(input, options) { module.exports = { SyntaxError: peg$SyntaxError, - parse: peg$parse, + parse: peg$parse };