From 364190dc7b4328da77c4e9edd1923b85a1f66133 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 22 May 2022 18:37:07 -0400 Subject: [PATCH 01/14] Simple dateTime integration --- .../src/components/SquiggleChart.tsx | 12 ++++ packages/squiggle-lang/src/js/index.ts | 4 ++ .../squiggle-lang/src/js/rescript_interop.ts | 16 ++++- .../ReducerInterface_DateTime.res | 62 +++++++++++++++++++ .../ReducerInterface_ExpressionValue.res | 12 ++++ .../ReducerInterface_ExternalLibrary.res | 8 ++- .../squiggle-lang/src/rescript/Utility/E.res | 43 +++++++++++++ 7 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index ce562368..5214dafc 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -189,6 +189,18 @@ const SquiggleItem: React.FC = ({ {expression.value.map((r) => `"${r}"`).join(", ")} ); + case "date": + return ( + + {expression.value.toString()} + + ); + case "timeDuration": + return ( + + + + ); case "lambda": return ( | tagged<"distribution", Distribution> | tagged<"number", number> - | tagged<"record", { [key: string]: squiggleExpression }>; + | tagged<"date", Date> + | tagged<"timeDuration", number> + | tagged<"record", { [key: string]: squiggleExpression }> export { lambdaValue }; @@ -127,6 +137,10 @@ export function convertRawToTypescript( return tag("string", result._0); case 9: // EvSymbol return tag("symbol", result._0); + case 10: // EvDate + return tag("date", result._0); + case 11: // EvTimeDuration + return tag("number", result._0); } } diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res new file mode 100644 index 00000000..3f94f3f4 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res @@ -0,0 +1,62 @@ +module ExpressionValue = ReducerInterface_ExpressionValue +type expressionValue = ExpressionValue.expressionValue + +let dateDispatch = (call: ExpressionValue.functionCall, env: DistributionOperation.env): option< + result, +> => { + switch call { + | ("toString", [EvDate(t)]) => EvString(E.Date.toString(t))->Ok->Some + | ("makeDateFromYear", [EvNumber(year)]) => + EvDate(E.Date.makeWithYM(~year, ~month=0.0, ()))->Ok->Some + | ("fromMilliseconds", [EvNumber(f)]) => EvDate(E.Date.fromFloat(f))->Ok->Some + | ("toMilliseconds", [EvDate(f)]) => EvNumber(E.Date.toFloat(f))->Ok->Some + | ("subtract", [EvDate(d1), EvDate(d2)]) => + switch E.Date.subtract(d1, d2) { + | Ok(d) => EvTimeDuration(d)->Ok + | Error(e) => Error(RETodo(e)) + }->Some + | ("subtract", [EvDate(d1), EvTimeDuration(d2)]) => + EvDate(E.Date.subtractDuration(d1, d2))->Ok->Some + | ("add", [EvDate(d1), EvTimeDuration(d2)]) => EvDate(E.Date.addDuration(d1, d2))->Ok->Some + | _ => None + } +} + +let durationDispatch = (call: ExpressionValue.functionCall, env: DistributionOperation.env): option< + result, +> => { + switch call { + | ("toString", [EvTimeDuration(t)]) => EvString(E.Duration.toString(t))->Ok->Some + | ("hours", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromHours(f))->Ok->Some + | ("years", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromYears(f))->Ok->Some + | ("toHours", [EvTimeDuration(f)]) => EvNumber(E.Duration.toHours(f))->Ok->Some + | ("toYears", [EvTimeDuration(f)]) => EvNumber(E.Duration.toYears(f))->Ok->Some + | ( + ("add" | "subtract" | "multiply" | "divide") as op, + [EvTimeDuration(d1), EvTimeDuration(d2)], + ) => { + let op = switch op { + | "subtract" => E.Duration.subtract + | "multiply" => E.Duration.multiply + | "divide" => E.Duration.divide + | "add" + | _ => E.Duration.add + } + EvTimeDuration(op(d1, d2))->Ok->Some + } + | _ => None + } +} + +let dispatch = (call: ExpressionValue.functionCall, env: DistributionOperation.env): option< + result, +> => { + switch dateDispatch(call, env) { + | Some(r) => Some(r) + | None => + switch durationDispatch(call, env) { + | Some(r) => Some(r) + | None => None + } + } +} diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res index 7b896509..6da34db1 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res @@ -20,6 +20,8 @@ type rec expressionValue = | EvRecord(record) | EvString(string) | EvSymbol(string) + | EvDate(Js.Date.t) + | EvTimeDuration(float) and record = Js.Dict.t and externalBindings = record and lambdaValue = { @@ -51,6 +53,8 @@ let rec toString = aValue => | EvSymbol(aString) => `:${aString}` | EvRecord(aRecord) => aRecord->toStringRecord | EvDistribution(dist) => GenericDist.toString(dist) + | EvDate(date) => E.Date.toString(date) + | EvTimeDuration(t) => E.Duration.toString(t) } and toStringRecord = aRecord => { let pairs = @@ -73,6 +77,8 @@ let toStringWithType = aValue => | EvRecord(_) => `Record::${toString(aValue)}` | EvString(_) => `String::${toString(aValue)}` | EvSymbol(_) => `Symbol::${toString(aValue)}` + | EvDate(_) => `Date::${toString(aValue)}` + | EvTimeDuration(_) => `Date::${toString(aValue)}` } let argsToString = (args: array): string => { @@ -116,6 +122,8 @@ type expressionValueType = | EvtRecord | EvtString | EvtSymbol + | EvtDate + | EvtTimeDuration type functionCallSignature = CallSignature(string, array) type functionDefinitionSignature = @@ -133,6 +141,8 @@ let valueToValueType = value => | EvRecord(_) => EvtRecord | EvString(_) => EvtArray | EvSymbol(_) => EvtSymbol + | EvDate(_) => EvtDate + | EvTimeDuration(_) => EvtTimeDuration } let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => { @@ -152,6 +162,8 @@ let valueTypeToString = (valueType: expressionValueType): string => | EvtRecord => `Record` | EvtString => `String` | EvtSymbol => `Symbol` + | EvtDate => `Date` + | EvtTimeDuration => `Duration` } let functionCallSignatureToString = (functionCallSignature: functionCallSignature): string => { diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalLibrary.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalLibrary.res index 0bdb0748..7e9448f0 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalLibrary.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalLibrary.res @@ -18,9 +18,11 @@ let dispatch = (call: ExpressionValue.functionCall, environment, chain): result< expressionValue, 'e, > => - ReducerInterface_GenericDistribution.dispatch(call, environment) |> E.O.default( - chain(call, environment), - ) + switch ReducerInterface_GenericDistribution.dispatch(call, environment) { + | Some(r) => r + | None => + ReducerInterface_DateTime.dispatch(call, environment) |> E.O.default(chain(call, environment)) + } /* If your dispatch is too big you can divide it into smaller dispatches and pass the call so that it gets called finally. diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index b08754ef..d2ad62f4 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -833,3 +833,46 @@ module JsArray = { |> Js.Array.map(O.toExn("Warning: This should not have happened")) let filter = Js.Array.filter } + +module Duration = { + //Stores in Unix milliseconds + type t = float + let minute = Belt.Float.fromInt(60 * 1000) + let hour = Belt.Float.fromInt(60 * 60 * 1000) + let day = Belt.Float.fromInt(24 * 60 * 60 * 1000) + let year = Belt.Float.fromInt(24 * 60 * 60 * 1000 * 365) + let fromFloat = (f: float): t => f + let toFloat = (d: t): float => d + let fromHours = (h: float): t => h *. hour + let fromDays = (d: float): t => d *. day + let fromYears = (y: float): t => y *. year + let toHours = (t: t): float => t /. hour + let toDays = (t: t): float => t /. day + let toYears = (t: t): float => t /. year + let toString = (t: t) => `${Float.with2DigitsPrecision(t)}ms` + let add = (t1, t2): t => t1 +. t2 + let subtract = (t1, t2): t => t1 -. t2 + let multiply = (t1, t2): t => t1 *. t2 + let divide = (t1, t2): t => t1 /. t2 +} + +module Date = { + type t = Js.Date.t + type year + let makeWithYM = Js.Date.makeWithYM + let toString = Js.Date.toString + let fromFloat = Js.Date.fromFloat + let toFloat = Js.Date.getTime + let fmap = (t: t, fn: float => float) => t->toFloat->fn->fromFloat + let subtract = (t1: t, t2: t) => { + let (f1, f2) = (toFloat(t1), toFloat(t2)) + let diff = f1 -. f2 + if diff < 0.0 { + Error("Cannot subtract a date by one that is in its future") + } else { + Ok(Duration.fromFloat(diff)) + } + } + let addDuration = (t: t, duration: Duration.t) => fmap(t, t => t +. duration) + let subtractDuration = (t: t, duration: Duration.t) => fmap(t, t => t -. duration) +} From f1d2a1a12f0343759ad4714213959fc9dba5a428 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 22 May 2022 21:40:06 -0400 Subject: [PATCH 02/14] Added better Duration toString and Date makeWithYear functionality --- .../src/components/SquiggleChart.tsx | 5 +-- .../ReducerInterface_DateTime.res | 9 +++-- .../squiggle-lang/src/rescript/Utility/E.res | 36 +++++++++++++++---- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 5214dafc..fe79a018 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -192,15 +192,16 @@ const SquiggleItem: React.FC = ({ case "date": return ( - {expression.value.toString()} + {expression.value.toDateString()} ); - case "timeDuration": + case "timeDuration":{ return ( ); + } case "lambda": return ( EvString(E.Date.toString(t))->Ok->Some | ("makeDateFromYear", [EvNumber(year)]) => - EvDate(E.Date.makeWithYM(~year, ~month=0.0, ()))->Ok->Some + switch E.Date.makeWithYear(Belt.Float.toInt(year)) { + | Ok(t) => EvDate(t)->Ok->Some + | Error(e) => RETodo(e)->Error->Some + } | ("fromMilliseconds", [EvNumber(f)]) => EvDate(E.Date.fromFloat(f))->Ok->Some | ("toMilliseconds", [EvDate(f)]) => EvNumber(E.Date.toFloat(f))->Ok->Some | ("subtract", [EvDate(d1), EvDate(d2)]) => @@ -22,14 +25,16 @@ let dateDispatch = (call: ExpressionValue.functionCall, env: DistributionOperati } } -let durationDispatch = (call: ExpressionValue.functionCall, env: DistributionOperation.env): option< +let durationDispatch = (call: ExpressionValue.functionCall, _: DistributionOperation.env): option< result, > => { switch call { | ("toString", [EvTimeDuration(t)]) => EvString(E.Duration.toString(t))->Ok->Some | ("hours", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromHours(f))->Ok->Some + | ("days", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromDays(f))->Ok->Some | ("years", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromYears(f))->Ok->Some | ("toHours", [EvTimeDuration(f)]) => EvNumber(E.Duration.toHours(f))->Ok->Some + | ("toDays", [EvTimeDuration(f)]) => EvNumber(E.Duration.toDays(f))->Ok->Some | ("toYears", [EvTimeDuration(f)]) => EvNumber(E.Duration.toYears(f))->Ok->Some | ( ("add" | "subtract" | "multiply" | "divide") as op, diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index d2ad62f4..088867c9 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -840,7 +840,7 @@ module Duration = { let minute = Belt.Float.fromInt(60 * 1000) let hour = Belt.Float.fromInt(60 * 60 * 1000) let day = Belt.Float.fromInt(24 * 60 * 60 * 1000) - let year = Belt.Float.fromInt(24 * 60 * 60 * 1000 * 365) + let year = Belt.Float.fromInt(24 * 60 * 60 * 1000) *. 365.25 let fromFloat = (f: float): t => f let toFloat = (d: t): float => d let fromHours = (h: float): t => h *. hour @@ -849,7 +849,19 @@ module Duration = { let toHours = (t: t): float => t /. hour let toDays = (t: t): float => t /. day let toYears = (t: t): float => t /. year - let toString = (t: t) => `${Float.with2DigitsPrecision(t)}ms` + let toString = (t: t): string => { + if t >= year { + Float.with3DigitsPrecision(t /. year) ++ " years" + } else if t >= day { + Float.with3DigitsPrecision(t /. day) ++ " days" + } else if t >= hour { + Float.with3DigitsPrecision(t /. hour) ++ " hours" + } else if t >= minute { + Float.with3DigitsPrecision(t /. minute) ++ " minutes" + } else { + Float.toFixed(t) ++ "ms" + } + } let add = (t1, t2): t => t1 +. t2 let subtract = (t1, t2): t => t1 -. t2 let multiply = (t1, t2): t => t1 *. t2 @@ -857,12 +869,24 @@ module Duration = { } module Date = { + //The Rescript/JS implementation of Date is pretty mediocre. It would be good to improve upon later. type t = Js.Date.t - type year - let makeWithYM = Js.Date.makeWithYM - let toString = Js.Date.toString - let fromFloat = Js.Date.fromFloat let toFloat = Js.Date.getTime + let getFullYear = Js.Date.getFullYear + + //The Js.Date.makeWithYM function accepts a float, but only treats it as a whole number. + //Our version takes an integer to make this distinction clearer. + let makeWithYear = (y: int): result => { + if y < 100 { + Error("Year must be over 100") + } else if y > 200000 { + Error("Year must be less than 200000") + } else { + Ok(Js.Date.makeWithYM(~year=Belt.Float.fromInt(y), ~month=0.0, ())) + } + } + let toString = Js.Date.toDateString + let fromFloat = Js.Date.fromFloat let fmap = (t: t, fn: float => float) => t->toFloat->fn->fromFloat let subtract = (t1: t, t2: t) => { let (f1, f2) = (toFloat(t1), toFloat(t2)) From fff2f5da599cc1ab85006cc729cf0f68c8373103 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 22 May 2022 21:57:13 -0400 Subject: [PATCH 03/14] More sophisticated makeFromYear function, that accepts floats --- .../ReducerInterface_DateTime.res | 2 +- .../squiggle-lang/src/rescript/Utility/E.res | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res index 4f474312..97d35c49 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res @@ -7,7 +7,7 @@ let dateDispatch = (call: ExpressionValue.functionCall, env: DistributionOperati switch call { | ("toString", [EvDate(t)]) => EvString(E.Date.toString(t))->Ok->Some | ("makeDateFromYear", [EvNumber(year)]) => - switch E.Date.makeWithYear(Belt.Float.toInt(year)) { + switch E.Date.makeFromYear(year) { | Ok(t) => EvDate(t)->Ok->Some | Error(e) => RETodo(e)->Error->Some } diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index 088867c9..38967979 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -873,18 +873,6 @@ module Date = { type t = Js.Date.t let toFloat = Js.Date.getTime let getFullYear = Js.Date.getFullYear - - //The Js.Date.makeWithYM function accepts a float, but only treats it as a whole number. - //Our version takes an integer to make this distinction clearer. - let makeWithYear = (y: int): result => { - if y < 100 { - Error("Year must be over 100") - } else if y > 200000 { - Error("Year must be less than 200000") - } else { - Ok(Js.Date.makeWithYM(~year=Belt.Float.fromInt(y), ~month=0.0, ())) - } - } let toString = Js.Date.toDateString let fromFloat = Js.Date.fromFloat let fmap = (t: t, fn: float => float) => t->toFloat->fn->fromFloat @@ -899,4 +887,22 @@ module Date = { } let addDuration = (t: t, duration: Duration.t) => fmap(t, t => t +. duration) let subtractDuration = (t: t, duration: Duration.t) => fmap(t, t => t -. duration) + //The Js.Date.makeWithYM function accepts a float, but only treats it as a whole number. + //Our version takes an integer to make this distinction clearer. + let makeWithYearInt = (y: int): result => { + if y < 100 { + Error("Year must be over 100") + } else if y > 200000 { + Error("Year must be less than 200000") + } else { + Ok(Js.Date.makeWithYM(~year=Belt.Float.fromInt(y), ~month=0.0, ())) + } + } + let makeFromYear = (year: float): result => { + let floor = year -> Js.Math.floor_float + makeWithYearInt(Belt.Float.toInt(floor))->R2.fmap(earlyDate => { + let diff = year -. floor + earlyDate->addDuration(diff *. Duration.year) + }) + } } From 6af2e242f809f145f4647c39f7a0c88180186a1c Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 22 May 2022 22:11:28 -0400 Subject: [PATCH 04/14] Simple better format for Duration toString --- .../src/components/SquiggleChart.tsx | 2 +- .../squiggle-lang/src/rescript/Utility/E.res | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index fe79a018..50fcebb3 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -195,7 +195,7 @@ const SquiggleItem: React.FC = ({ {expression.value.toDateString()} ); - case "timeDuration":{ + case "timeDuration": { return ( diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index 38967979..6a66e497 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -849,23 +849,27 @@ module Duration = { let toHours = (t: t): float => t /. hour let toDays = (t: t): float => t /. day let toYears = (t: t): float => t /. year + let toString = (t: t): string => { + let shouldPluralize = f => f != 1.0 + let display = (f: float, s: string) => + `${Float.with3DigitsPrecision(f)} ${s}${shouldPluralize(f) ? "s" : ""}` if t >= year { - Float.with3DigitsPrecision(t /. year) ++ " years" + display(t /. year, "year") } else if t >= day { - Float.with3DigitsPrecision(t /. day) ++ " days" + display(t /. day, "day") } else if t >= hour { - Float.with3DigitsPrecision(t /. hour) ++ " hours" + display(t /. hour, "hour") } else if t >= minute { - Float.with3DigitsPrecision(t /. minute) ++ " minutes" + display(t /. minute, "minute") } else { Float.toFixed(t) ++ "ms" } } - let add = (t1, t2): t => t1 +. t2 - let subtract = (t1, t2): t => t1 -. t2 - let multiply = (t1, t2): t => t1 *. t2 - let divide = (t1, t2): t => t1 /. t2 + let add = (t1: t, t2: t): t => t1 +. t2 + let subtract = (t1: t, t2: t): t => t1 -. t2 + let multiply = (t1: t, t2: t): t => t1 *. t2 + let divide = (t1: t, t2: t): t => t1 /. t2 } module Date = { @@ -899,7 +903,7 @@ module Date = { } } let makeFromYear = (year: float): result => { - let floor = year -> Js.Math.floor_float + let floor = year->Js.Math.floor_float makeWithYearInt(Belt.Float.toInt(floor))->R2.fmap(earlyDate => { let diff = year -. floor earlyDate->addDuration(diff *. Duration.year) From 70574329fcf69de56f81ea8ba4e8192c2e1992b6 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 22 May 2022 22:40:10 -0400 Subject: [PATCH 05/14] Cleaned up arithmetic operations of time durations --- .../ReducerInterface_DateTime.res | 27 +++++++++---------- .../squiggle-lang/src/rescript/Utility/E.res | 15 ++++++----- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res index 97d35c49..a0059392 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res @@ -11,8 +11,8 @@ let dateDispatch = (call: ExpressionValue.functionCall, env: DistributionOperati | Ok(t) => EvDate(t)->Ok->Some | Error(e) => RETodo(e)->Error->Some } - | ("fromMilliseconds", [EvNumber(f)]) => EvDate(E.Date.fromFloat(f))->Ok->Some - | ("toMilliseconds", [EvDate(f)]) => EvNumber(E.Date.toFloat(f))->Ok->Some + | ("dateFromNumber", [EvNumber(f)]) => EvDate(E.Date.fromFloat(f))->Ok->Some + | ("toNumber", [EvDate(f)]) => EvNumber(E.Date.toFloat(f))->Ok->Some | ("subtract", [EvDate(d1), EvDate(d2)]) => switch E.Date.subtract(d1, d2) { | Ok(d) => EvTimeDuration(d)->Ok @@ -31,24 +31,21 @@ let durationDispatch = (call: ExpressionValue.functionCall, _: DistributionOpera switch call { | ("toString", [EvTimeDuration(t)]) => EvString(E.Duration.toString(t))->Ok->Some | ("hours", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromHours(f))->Ok->Some + | ("minutes", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromMinutes(f))->Ok->Some | ("days", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromDays(f))->Ok->Some | ("years", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromYears(f))->Ok->Some | ("toHours", [EvTimeDuration(f)]) => EvNumber(E.Duration.toHours(f))->Ok->Some + | ("toMinutes", [EvTimeDuration(f)]) => EvNumber(E.Duration.toMinutes(f))->Ok->Some | ("toDays", [EvTimeDuration(f)]) => EvNumber(E.Duration.toDays(f))->Ok->Some | ("toYears", [EvTimeDuration(f)]) => EvNumber(E.Duration.toYears(f))->Ok->Some - | ( - ("add" | "subtract" | "multiply" | "divide") as op, - [EvTimeDuration(d1), EvTimeDuration(d2)], - ) => { - let op = switch op { - | "subtract" => E.Duration.subtract - | "multiply" => E.Duration.multiply - | "divide" => E.Duration.divide - | "add" - | _ => E.Duration.add - } - EvTimeDuration(op(d1, d2))->Ok->Some - } + | ("add", [EvTimeDuration(d1), EvTimeDuration(d2)]) => + EvTimeDuration(E.Duration.add(d1, d2))->Ok->Some + | ("subtract", [EvTimeDuration(d1), EvTimeDuration(d2)]) => + EvTimeDuration(E.Duration.subtract(d1, d2))->Ok->Some + | ("multiply", [EvTimeDuration(d1), EvNumber(d2)]) => + EvTimeDuration(E.Duration.multiply(d1, d2))->Ok->Some + | ("divide", [EvTimeDuration(d1), EvNumber(d2)]) => + EvTimeDuration(E.Duration.divide(d1, d2))->Ok->Some | _ => None } } diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index 6a66e497..46787134 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -843,9 +843,11 @@ module Duration = { let year = Belt.Float.fromInt(24 * 60 * 60 * 1000) *. 365.25 let fromFloat = (f: float): t => f let toFloat = (d: t): float => d + let fromMinutes = (h: float): t => h *. minute let fromHours = (h: float): t => h *. hour let fromDays = (d: float): t => d *. day let fromYears = (y: float): t => y *. year + let toMinutes = (t: t): float => t /. minute let toHours = (t: t): float => t /. hour let toDays = (t: t): float => t /. day let toYears = (t: t): float => t /. year @@ -854,13 +856,14 @@ module Duration = { let shouldPluralize = f => f != 1.0 let display = (f: float, s: string) => `${Float.with3DigitsPrecision(f)} ${s}${shouldPluralize(f) ? "s" : ""}` - if t >= year { + let abs = Js.Math.abs_float(t) + if abs >= year { display(t /. year, "year") - } else if t >= day { + } else if abs >= day { display(t /. day, "day") - } else if t >= hour { + } else if abs >= hour { display(t /. hour, "hour") - } else if t >= minute { + } else if abs >= minute { display(t /. minute, "minute") } else { Float.toFixed(t) ++ "ms" @@ -868,8 +871,8 @@ module Duration = { } let add = (t1: t, t2: t): t => t1 +. t2 let subtract = (t1: t, t2: t): t => t1 -. t2 - let multiply = (t1: t, t2: t): t => t1 *. t2 - let divide = (t1: t, t2: t): t => t1 /. t2 + let multiply = (t1: t, t2: float): t => t1 *. t2 + let divide = (t1: t, t2: float): t => t1 /. t2 } module Date = { From 4628140069b5f1a8272e14208b12822edc6718c2 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 23 May 2022 08:13:51 +0200 Subject: [PATCH 06/14] numbers with units (tested) --- .../Reducer_Peggy_Parse_test.res | 7 + .../Reducer_Peggy_ToExpression_test.res | 4 + .../Reducer_Dispatch_BuiltIn.res | 18 ++ .../rescript/Reducer/Reducer_ErrorValue.res | 6 +- .../Reducer_Peggy_GeneratedParser.js | 223 +++++++++++------- .../Reducer_Peggy_GeneratedParser.peggy | 13 +- 6 files changed, 176 insertions(+), 95 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res index 168be4d8..3f1baf12 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res @@ -251,6 +251,13 @@ describe("Peggy parse", () => { "{(::map (::$_constructArray_$ (1 2 3)) {|:x| {(::add :x 1)}})}", ) }) + describe("unit", () => { + testParse("1m", "{(::multiply 1 (::$valueOfUnit 'm'))}") + testParse( + "1m+2cm", + "{(::add (::multiply 1 (::$valueOfUnit 'm')) (::multiply 2 (::$valueOfUnit 'cm')))}", + ) + }) }) describe("parsing new line", () => { diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res index 81bafd97..fa6c58f9 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res @@ -217,4 +217,8 @@ describe("Peggy to Expression", () => { (), ) }) + + describe("unit", () => { + testToExpression("1m", "(:$$_block_$$ (:multiply 1 (:$valueOfUnit 'm')))", ~v="1", ()) + }) }) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res index 141b4a37..1ab8d559 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res @@ -129,6 +129,23 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce ) } + let doValueOfUnit = (aUnit: string) => + switch aUnit { + | "nm" => 0.000000001->EvNumber->Ok + | "um" => 0.000001->EvNumber->Ok + | "mm" => 0.001->EvNumber->Ok + | "cm" => 0.01->EvNumber->Ok + | "dm" => 0.1->EvNumber->Ok + | "m" => 1.->EvNumber->Ok + | "dam" => 10.->EvNumber->Ok + | "hm" => 100.->EvNumber->Ok + | "km" => 1000.->EvNumber->Ok + | "Mm" => 1000000.->EvNumber->Ok + | "Gm" => 1000000000.->EvNumber->Ok + | "Tm" => 1000000000000.->EvNumber->Ok + | _ => REUnitNotFound(aUnit)->Error + } + switch call { | ("$_atIndex_$", [EvArray(aValueArray), EvNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex) | ("$_atIndex_$", [EvRecord(dict), EvString(sIndex)]) => recordAtIndex(dict, sIndex) @@ -137,6 +154,7 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce | ("$_exportBindings_$", [EvRecord(externalBindings)]) => doExportBindings(externalBindings) | ("$_setBindings_$", [EvRecord(externalBindings), EvSymbol(symbol), value]) => doSetBindings(externalBindings, symbol, value) + | ("$valueOfUnit", [EvString(aUnit)]) => doValueOfUnit(aUnit) | ("inspect", [value, EvString(label)]) => inspectLabel(value, label) | ("inspect", [value]) => inspect(value) | ("keep", [EvArray(aValueArray), EvLambda(aLambdaValue)]) => diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res index fc2f86f1..721fbc40 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res @@ -4,18 +4,19 @@ type errorValue = | REArrayIndexNotFound(string, int) | REAssignmentExpected | REDistributionError(DistributionTypes.error) - | REOperationError(Operation.operationError) + | REExpectedType(string) | REExpressionExpected | REFunctionExpected(string) | REFunctionNotFound(string) | REJavaScriptExn(option, option) // Javascript Exception | REMacroNotFound(string) | RENotAFunction(string) + | REOperationError(Operation.operationError) | RERecordPropertyNotFound(string, string) | RESymbolNotFound(string) | RESyntaxError(string) | RETodo(string) // To do - | REExpectedType(string) + | REUnitNotFound(string) type t = errorValue @@ -52,4 +53,5 @@ let errorToString = err => | RESyntaxError(desc) => `Syntax Error: ${desc}` | RETodo(msg) => `TODO: ${msg}` | REExpectedType(typeName) => `Expected type: ${typeName}` + | REUnitNotFound(unitName) => `Unit not found: ${unitName}` } diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js index 3a34dfb2..4c1532dd 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js @@ -538,32 +538,42 @@ function peg$parse(input, options) { var peg$f27 = function (characters) { return nodeString(characters.join("")); }; - var peg$f28 = function () { - return nodeInteger(parseInt(text())); + var peg$f28 = function (number, unit) { + if (unit === null) { + return number; + } else { + return makeFunctionCall("multiply", [ + number, + makeFunctionCall("$valueOfUnit", [nodeString(unit.value)]), + ]); + } }; var peg$f29 = function () { - return nodeFloat(parseFloat(text())); + return nodeInteger(parseInt(text())); }; var peg$f30 = function () { + return nodeFloat(parseFloat(text())); + }; + var peg$f31 = function () { return nodeBoolean(text() === "true"); }; - var peg$f31 = function (args, statements, finalExpression) { + var peg$f32 = function (args, statements, finalExpression) { statements.push(finalExpression); return nodeLambda(args, nodeBlock(statements)); }; - var peg$f32 = function (args, finalExpression) { + var peg$f33 = function (args, finalExpression) { return nodeLambda(args, nodeBlock([finalExpression])); }; - var peg$f33 = function () { + var peg$f34 = function () { return makeFunctionCall("$_constructArray_$", [nodeExpression([])]); }; - var peg$f34 = function (args) { + var peg$f35 = function (args) { return makeFunctionCall("$_constructArray_$", [nodeExpression(args)]); }; - var peg$f35 = function (args) { + var peg$f36 = function (args) { return makeFunctionCall("$_constructRecord_$", [nodeExpression(args)]); }; - var peg$f36 = function (key, value) { + var peg$f37 = function (key, value) { return nodeKeyValue(key, value); }; @@ -738,7 +748,7 @@ function peg$parse(input, options) { function peg$parsestart() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 0; + var key = peg$currPos * 68 + 0; var cached = peg$resultsCache[key]; if (cached) { @@ -771,7 +781,7 @@ function peg$parse(input, options) { function peg$parsezeroOMoreArgumentsBlockOrExpression() { var s0; - var key = peg$currPos * 67 + 1; + var key = peg$currPos * 68 + 1; var cached = peg$resultsCache[key]; if (cached) { @@ -793,7 +803,7 @@ function peg$parse(input, options) { function peg$parseouterBlock() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 2; + var key = peg$currPos * 68 + 2; var cached = peg$resultsCache[key]; if (cached) { @@ -846,7 +856,7 @@ function peg$parse(input, options) { function peg$parseinnerBlockOrExpression() { var s0, s1; - var key = peg$currPos * 67 + 3; + var key = peg$currPos * 68 + 3; var cached = peg$resultsCache[key]; if (cached) { @@ -874,7 +884,7 @@ function peg$parse(input, options) { function peg$parsequotedInnerBlock() { var s0, s1, s2, s3, s4, s5, s6; - var key = peg$currPos * 67 + 4; + var key = peg$currPos * 68 + 4; var cached = peg$resultsCache[key]; if (cached) { @@ -991,7 +1001,7 @@ function peg$parse(input, options) { function peg$parsearray_statements() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 5; + var key = peg$currPos * 68 + 5; var cached = peg$resultsCache[key]; if (cached) { @@ -1046,7 +1056,7 @@ function peg$parse(input, options) { function peg$parsestatement() { var s0; - var key = peg$currPos * 67 + 6; + var key = peg$currPos * 68 + 6; var cached = peg$resultsCache[key]; if (cached) { @@ -1068,7 +1078,7 @@ function peg$parse(input, options) { function peg$parseletStatement() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 7; + var key = peg$currPos * 68 + 7; var cached = peg$resultsCache[key]; if (cached) { @@ -1109,7 +1119,7 @@ function peg$parse(input, options) { function peg$parsedefunStatement() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - var key = peg$currPos * 67 + 8; + var key = peg$currPos * 68 + 8; var cached = peg$resultsCache[key]; if (cached) { @@ -1186,7 +1196,7 @@ function peg$parse(input, options) { function peg$parseassignmentOp() { var s0, s1; - var key = peg$currPos * 67 + 9; + var key = peg$currPos * 68 + 9; var cached = peg$resultsCache[key]; if (cached) { @@ -1221,7 +1231,7 @@ function peg$parse(input, options) { function peg$parsearray_parameters() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 10; + var key = peg$currPos * 68 + 10; var cached = peg$resultsCache[key]; if (cached) { @@ -1300,7 +1310,7 @@ function peg$parse(input, options) { function peg$parseexpression() { var s0; - var key = peg$currPos * 67 + 11; + var key = peg$currPos * 68 + 11; var cached = peg$resultsCache[key]; if (cached) { @@ -1325,7 +1335,7 @@ function peg$parse(input, options) { function peg$parseifthenelse() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11; - var key = peg$currPos * 67 + 12; + var key = peg$currPos * 68 + 12; var cached = peg$resultsCache[key]; if (cached) { @@ -1439,7 +1449,7 @@ function peg$parse(input, options) { function peg$parseternary() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; - var key = peg$currPos * 67 + 13; + var key = peg$currPos * 68 + 13; var cached = peg$resultsCache[key]; if (cached) { @@ -1513,7 +1523,7 @@ function peg$parse(input, options) { function peg$parselogicalAdditive() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 14; + var key = peg$currPos * 68 + 14; var cached = peg$resultsCache[key]; if (cached) { @@ -1578,7 +1588,7 @@ function peg$parse(input, options) { function peg$parselogicalAdditiveOp() { var s0, s1; - var key = peg$currPos * 67 + 15; + var key = peg$currPos * 68 + 15; var cached = peg$resultsCache[key]; if (cached) { @@ -1613,7 +1623,7 @@ function peg$parse(input, options) { function peg$parselogicalMultiplicative() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 16; + var key = peg$currPos * 68 + 16; var cached = peg$resultsCache[key]; if (cached) { @@ -1678,7 +1688,7 @@ function peg$parse(input, options) { function peg$parselogicalMultiplicativeOp() { var s0, s1; - var key = peg$currPos * 67 + 17; + var key = peg$currPos * 68 + 17; var cached = peg$resultsCache[key]; if (cached) { @@ -1713,7 +1723,7 @@ function peg$parse(input, options) { function peg$parseequality() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 18; + var key = peg$currPos * 68 + 18; var cached = peg$resultsCache[key]; if (cached) { @@ -1757,7 +1767,7 @@ function peg$parse(input, options) { function peg$parseequalityOp() { var s0, s1; - var key = peg$currPos * 67 + 19; + var key = peg$currPos * 68 + 19; var cached = peg$resultsCache[key]; if (cached) { @@ -1803,7 +1813,7 @@ function peg$parse(input, options) { function peg$parserelational() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 20; + var key = peg$currPos * 68 + 20; var cached = peg$resultsCache[key]; if (cached) { @@ -1847,7 +1857,7 @@ function peg$parse(input, options) { function peg$parserelationalOp() { var s0, s1; - var key = peg$currPos * 67 + 21; + var key = peg$currPos * 68 + 21; var cached = peg$resultsCache[key]; if (cached) { @@ -1915,7 +1925,7 @@ function peg$parse(input, options) { function peg$parseadditive() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 22; + var key = peg$currPos * 68 + 22; var cached = peg$resultsCache[key]; if (cached) { @@ -1980,7 +1990,7 @@ function peg$parse(input, options) { function peg$parseadditiveOp() { var s0, s1; - var key = peg$currPos * 67 + 23; + var key = peg$currPos * 68 + 23; var cached = peg$resultsCache[key]; if (cached) { @@ -2048,7 +2058,7 @@ function peg$parse(input, options) { function peg$parsemultiplicative() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 24; + var key = peg$currPos * 68 + 24; var cached = peg$resultsCache[key]; if (cached) { @@ -2113,7 +2123,7 @@ function peg$parse(input, options) { function peg$parsemultiplicativeOp() { var s0, s1; - var key = peg$currPos * 67 + 25; + var key = peg$currPos * 68 + 25; var cached = peg$resultsCache[key]; if (cached) { @@ -2181,7 +2191,7 @@ function peg$parse(input, options) { function peg$parsepower() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 26; + var key = peg$currPos * 68 + 26; var cached = peg$resultsCache[key]; if (cached) { @@ -2246,7 +2256,7 @@ function peg$parse(input, options) { function peg$parsepowerOp() { var s0, s1; - var key = peg$currPos * 67 + 27; + var key = peg$currPos * 68 + 27; var cached = peg$resultsCache[key]; if (cached) { @@ -2292,7 +2302,7 @@ function peg$parse(input, options) { function peg$parsecredibleInterval() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 28; + var key = peg$currPos * 68 + 28; var cached = peg$resultsCache[key]; if (cached) { @@ -2377,7 +2387,7 @@ function peg$parse(input, options) { function peg$parsecredibleIntervalOp() { var s0, s1; - var key = peg$currPos * 67 + 29; + var key = peg$currPos * 68 + 29; var cached = peg$resultsCache[key]; if (cached) { @@ -2412,7 +2422,7 @@ function peg$parse(input, options) { function peg$parsechainFunctionCall() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 30; + var key = peg$currPos * 68 + 30; var cached = peg$resultsCache[key]; if (cached) { @@ -2515,7 +2525,7 @@ function peg$parse(input, options) { function peg$parsechainedFunction() { var s0, s1, s2, s3, s4, s5, s6; - var key = peg$currPos * 67 + 31; + var key = peg$currPos * 68 + 31; var cached = peg$resultsCache[key]; if (cached) { @@ -2627,7 +2637,7 @@ function peg$parse(input, options) { function peg$parseunary() { var s0, s1, s2, s3; - var key = peg$currPos * 67 + 32; + var key = peg$currPos * 68 + 32; var cached = peg$resultsCache[key]; if (cached) { @@ -2667,7 +2677,7 @@ function peg$parse(input, options) { function peg$parseunaryOperator() { var s0, s1; - var key = peg$currPos * 67 + 33; + var key = peg$currPos * 68 + 33; var cached = peg$resultsCache[key]; if (cached) { @@ -2724,7 +2734,7 @@ function peg$parse(input, options) { function peg$parseindexedValue() { var s0; - var key = peg$currPos * 67 + 34; + var key = peg$currPos * 68 + 34; var cached = peg$resultsCache[key]; if (cached) { @@ -2749,7 +2759,7 @@ function peg$parse(input, options) { function peg$parsecollectionElement() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - var key = peg$currPos * 67 + 35; + var key = peg$currPos * 68 + 35; var cached = peg$resultsCache[key]; if (cached) { @@ -3051,7 +3061,7 @@ function peg$parse(input, options) { function peg$parsearray_functionArguments() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 36; + var key = peg$currPos * 68 + 36; var cached = peg$resultsCache[key]; if (cached) { @@ -3130,7 +3140,7 @@ function peg$parse(input, options) { function peg$parserecordElement() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; - var key = peg$currPos * 67 + 37; + var key = peg$currPos * 68 + 37; var cached = peg$resultsCache[key]; if (cached) { @@ -3246,7 +3256,7 @@ function peg$parse(input, options) { function peg$parseatom() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 38; + var key = peg$currPos * 68 + 38; var cached = peg$resultsCache[key]; if (cached) { @@ -3306,7 +3316,7 @@ function peg$parse(input, options) { function peg$parsebasicValue() { var s0; - var key = peg$currPos * 67 + 39; + var key = peg$currPos * 68 + 39; var cached = peg$resultsCache[key]; if (cached) { @@ -3328,7 +3338,7 @@ function peg$parse(input, options) { function peg$parsebasicLiteral() { var s0; - var key = peg$currPos * 67 + 40; + var key = peg$currPos * 68 + 40; var cached = peg$resultsCache[key]; if (cached) { @@ -3339,14 +3349,11 @@ function peg$parse(input, options) { s0 = peg$parsestring(); if (s0 === peg$FAILED) { - s0 = peg$parsefloat(); + s0 = peg$parsenumber(); if (s0 === peg$FAILED) { - s0 = peg$parseinteger(); + s0 = peg$parseboolean(); if (s0 === peg$FAILED) { - s0 = peg$parseboolean(); - if (s0 === peg$FAILED) { - s0 = peg$parsedollarIdentifier(); - } + s0 = peg$parsedollarIdentifier(); } } } @@ -3359,7 +3366,7 @@ function peg$parse(input, options) { function peg$parseidentifier() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 41; + var key = peg$currPos * 68 + 41; var cached = peg$resultsCache[key]; if (cached) { @@ -3447,7 +3454,7 @@ function peg$parse(input, options) { function peg$parsedollarIdentifier() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 42; + var key = peg$currPos * 68 + 42; var cached = peg$resultsCache[key]; if (cached) { @@ -3535,7 +3542,7 @@ function peg$parse(input, options) { function peg$parsestring() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 43; + var key = peg$currPos * 68 + 43; var cached = peg$resultsCache[key]; if (cached) { @@ -3676,10 +3683,44 @@ function peg$parse(input, options) { return s0; } + function peg$parsenumber() { + var s0, s1, s2; + + var key = peg$currPos * 68 + 44; + var cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + + s0 = peg$currPos; + s1 = peg$parsefloat(); + if (s1 === peg$FAILED) { + s1 = peg$parseinteger(); + } + if (s1 !== peg$FAILED) { + s2 = peg$parseidentifier(); + if (s2 === peg$FAILED) { + s2 = null; + } + peg$savedPos = s0; + s0 = peg$f28(s1, s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + + return s0; + } + function peg$parseinteger() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 44; + var key = peg$currPos * 68 + 45; var cached = peg$resultsCache[key]; if (cached) { @@ -3740,7 +3781,7 @@ function peg$parse(input, options) { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f28(); + s0 = peg$f29(); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -3769,7 +3810,7 @@ function peg$parse(input, options) { function peg$parsefloat() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 45; + var key = peg$currPos * 68 + 46; var cached = peg$resultsCache[key]; if (cached) { @@ -3898,7 +3939,7 @@ function peg$parse(input, options) { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f29(); + s1 = peg$f30(); } s0 = s1; peg$silentFails--; @@ -3917,7 +3958,7 @@ function peg$parse(input, options) { function peg$parsefloatExponent() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 46; + var key = peg$currPos * 68 + 47; var cached = peg$resultsCache[key]; if (cached) { @@ -3979,7 +4020,7 @@ function peg$parse(input, options) { function peg$parsed() { var s0; - var key = peg$currPos * 67 + 47; + var key = peg$currPos * 68 + 48; var cached = peg$resultsCache[key]; if (cached) { @@ -4006,7 +4047,7 @@ function peg$parse(input, options) { function peg$parseboolean() { var s0, s1; - var key = peg$currPos * 67 + 48; + var key = peg$currPos * 68 + 49; var cached = peg$resultsCache[key]; if (cached) { @@ -4039,7 +4080,7 @@ function peg$parse(input, options) { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f30(); + s1 = peg$f31(); } s0 = s1; peg$silentFails--; @@ -4058,7 +4099,7 @@ function peg$parse(input, options) { function peg$parsevalueConstructor() { var s0; - var key = peg$currPos * 67 + 49; + var key = peg$currPos * 68 + 50; var cached = peg$resultsCache[key]; if (cached) { @@ -4086,7 +4127,7 @@ function peg$parse(input, options) { function peg$parselambda() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12; - var key = peg$currPos * 67 + 50; + var key = peg$currPos * 68 + 51; var cached = peg$resultsCache[key]; if (cached) { @@ -4161,7 +4202,7 @@ function peg$parse(input, options) { } if (s12 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f31(s5, s9, s10); + s0 = peg$f32(s5, s9, s10); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4242,7 +4283,7 @@ function peg$parse(input, options) { } if (s11 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f32(s5, s9); + s0 = peg$f33(s5, s9); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4277,7 +4318,7 @@ function peg$parse(input, options) { function peg$parsearrayConstructor() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 51; + var key = peg$currPos * 68 + 52; var cached = peg$resultsCache[key]; if (cached) { @@ -4310,7 +4351,7 @@ function peg$parse(input, options) { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f33(); + s0 = peg$f34(); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4346,7 +4387,7 @@ function peg$parse(input, options) { } if (s5 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f34(s3); + s0 = peg$f35(s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4376,7 +4417,7 @@ function peg$parse(input, options) { function peg$parsearray_elements() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 52; + var key = peg$currPos * 68 + 53; var cached = peg$resultsCache[key]; if (cached) { @@ -4455,7 +4496,7 @@ function peg$parse(input, options) { function peg$parserecordConstructor() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 53; + var key = peg$currPos * 68 + 54; var cached = peg$resultsCache[key]; if (cached) { @@ -4491,7 +4532,7 @@ function peg$parse(input, options) { } if (s5 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f35(s3); + s0 = peg$f36(s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4520,7 +4561,7 @@ function peg$parse(input, options) { function peg$parsearray_recordArguments() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 54; + var key = peg$currPos * 68 + 55; var cached = peg$resultsCache[key]; if (cached) { @@ -4599,7 +4640,7 @@ function peg$parse(input, options) { function peg$parsekeyValuePair() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 55; + var key = peg$currPos * 68 + 56; var cached = peg$resultsCache[key]; if (cached) { @@ -4626,7 +4667,7 @@ function peg$parse(input, options) { s5 = peg$parseexpression(); if (s5 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f36(s1, s5); + s0 = peg$f37(s1, s5); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4648,7 +4689,7 @@ function peg$parse(input, options) { function peg$parse_() { var s0, s1; - var key = peg$currPos * 67 + 56; + var key = peg$currPos * 68 + 57; var cached = peg$resultsCache[key]; if (cached) { @@ -4678,7 +4719,7 @@ function peg$parse(input, options) { function peg$parse_nl() { var s0, s1; - var key = peg$currPos * 67 + 57; + var key = peg$currPos * 68 + 58; var cached = peg$resultsCache[key]; if (cached) { @@ -4714,7 +4755,7 @@ function peg$parse(input, options) { function peg$parse__() { var s0, s1; - var key = peg$currPos * 67 + 58; + var key = peg$currPos * 68 + 59; var cached = peg$resultsCache[key]; if (cached) { @@ -4750,7 +4791,7 @@ function peg$parse(input, options) { function peg$parse__nl() { var s0, s1; - var key = peg$currPos * 67 + 59; + var key = peg$currPos * 68 + 60; var cached = peg$resultsCache[key]; if (cached) { @@ -4792,7 +4833,7 @@ function peg$parse(input, options) { function peg$parsestatementSeparator() { var s0, s1, s2, s3; - var key = peg$currPos * 67 + 60; + var key = peg$currPos * 68 + 61; var cached = peg$resultsCache[key]; if (cached) { @@ -4860,7 +4901,7 @@ function peg$parse(input, options) { function peg$parsecommentOrNewLine() { var s0, s1, s2; - var key = peg$currPos * 67 + 61; + var key = peg$currPos * 68 + 62; var cached = peg$resultsCache[key]; if (cached) { @@ -4891,7 +4932,7 @@ function peg$parse(input, options) { function peg$parsefinalComment() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 62; + var key = peg$currPos * 68 + 63; var cached = peg$resultsCache[key]; if (cached) { @@ -4967,7 +5008,7 @@ function peg$parse(input, options) { function peg$parsewhiteSpaceCharactersOrComment() { var s0; - var key = peg$currPos * 67 + 63; + var key = peg$currPos * 68 + 64; var cached = peg$resultsCache[key]; if (cached) { @@ -4989,7 +5030,7 @@ function peg$parse(input, options) { function peg$parsedelimitedComment() { var s0, s1, s2, s3; - var key = peg$currPos * 67 + 64; + var key = peg$currPos * 68 + 65; var cached = peg$resultsCache[key]; if (cached) { @@ -5067,7 +5108,7 @@ function peg$parse(input, options) { function peg$parsewhiteSpaceCharacters() { var s0; - var key = peg$currPos * 67 + 65; + var key = peg$currPos * 68 + 66; var cached = peg$resultsCache[key]; if (cached) { @@ -5094,7 +5135,7 @@ function peg$parse(input, options) { function peg$parsenewLine() { var s0, s1; - var key = peg$currPos * 67 + 66; + var key = peg$currPos * 68 + 67; var cached = peg$resultsCache[key]; if (cached) { diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy index 5d3392b3..3b02d85a 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy @@ -248,8 +248,7 @@ basicValue = valueConstructor / basicLiteral basicLiteral = string - / float - / integer + / number / boolean / dollarIdentifier @@ -263,6 +262,16 @@ string 'string' = characters:("'" @([^'])* "'") {return nodeString(characters.join(''))} / characters:('"' @([^"])* '"') {return nodeString(characters.join(''))} +number = number:(float / integer) unit:identifier? + { + if (unit === null) + { return number } + else + { return makeFunctionCall('multiply', + [number, makeFunctionCall('$valueOfUnit', [nodeString(unit.value)])]) + } + } + integer 'integer' = d+ !"\." ![e]i { return nodeInteger(parseInt(text()))} From 107bce506f52cd93d2466ec0a03c31dc724dc0f6 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 23 May 2022 17:46:05 +0200 Subject: [PATCH 07/14] generic unit support --- .../Reducer_Peggy_Parse_test.res | 4 + .../Reducer_Peggy_GeneratedParser.js | 220 ++++++++++-------- .../Reducer_Peggy_GeneratedParser.peggy | 12 +- 3 files changed, 143 insertions(+), 93 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res index 168be4d8..b0e723f4 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res @@ -251,6 +251,10 @@ describe("Peggy parse", () => { "{(::map (::$_constructArray_$ (1 2 3)) {|:x| {(::add :x 1)}})}", ) }) + describe("unit", () => { + testParse("1m", "{(::fromUnit_m 1)}") + testParse("1m+2cm", "{(::add (::fromUnit_m 1) (::fromUnit_cm 2))}") + }) }) describe("parsing new line", () => { diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js index 3a34dfb2..dc70cd8b 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js @@ -538,32 +538,39 @@ function peg$parse(input, options) { var peg$f27 = function (characters) { return nodeString(characters.join("")); }; - var peg$f28 = function () { - return nodeInteger(parseInt(text())); + var peg$f28 = function (number, unit) { + if (unit === null) { + return number; + } else { + return makeFunctionCall("fromUnit_" + unit.value, [number]); + } }; var peg$f29 = function () { - return nodeFloat(parseFloat(text())); + return nodeInteger(parseInt(text())); }; var peg$f30 = function () { + return nodeFloat(parseFloat(text())); + }; + var peg$f31 = function () { return nodeBoolean(text() === "true"); }; - var peg$f31 = function (args, statements, finalExpression) { + var peg$f32 = function (args, statements, finalExpression) { statements.push(finalExpression); return nodeLambda(args, nodeBlock(statements)); }; - var peg$f32 = function (args, finalExpression) { + var peg$f33 = function (args, finalExpression) { return nodeLambda(args, nodeBlock([finalExpression])); }; - var peg$f33 = function () { + var peg$f34 = function () { return makeFunctionCall("$_constructArray_$", [nodeExpression([])]); }; - var peg$f34 = function (args) { + var peg$f35 = function (args) { return makeFunctionCall("$_constructArray_$", [nodeExpression(args)]); }; - var peg$f35 = function (args) { + var peg$f36 = function (args) { return makeFunctionCall("$_constructRecord_$", [nodeExpression(args)]); }; - var peg$f36 = function (key, value) { + var peg$f37 = function (key, value) { return nodeKeyValue(key, value); }; @@ -738,7 +745,7 @@ function peg$parse(input, options) { function peg$parsestart() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 0; + var key = peg$currPos * 68 + 0; var cached = peg$resultsCache[key]; if (cached) { @@ -771,7 +778,7 @@ function peg$parse(input, options) { function peg$parsezeroOMoreArgumentsBlockOrExpression() { var s0; - var key = peg$currPos * 67 + 1; + var key = peg$currPos * 68 + 1; var cached = peg$resultsCache[key]; if (cached) { @@ -793,7 +800,7 @@ function peg$parse(input, options) { function peg$parseouterBlock() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 2; + var key = peg$currPos * 68 + 2; var cached = peg$resultsCache[key]; if (cached) { @@ -846,7 +853,7 @@ function peg$parse(input, options) { function peg$parseinnerBlockOrExpression() { var s0, s1; - var key = peg$currPos * 67 + 3; + var key = peg$currPos * 68 + 3; var cached = peg$resultsCache[key]; if (cached) { @@ -874,7 +881,7 @@ function peg$parse(input, options) { function peg$parsequotedInnerBlock() { var s0, s1, s2, s3, s4, s5, s6; - var key = peg$currPos * 67 + 4; + var key = peg$currPos * 68 + 4; var cached = peg$resultsCache[key]; if (cached) { @@ -991,7 +998,7 @@ function peg$parse(input, options) { function peg$parsearray_statements() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 5; + var key = peg$currPos * 68 + 5; var cached = peg$resultsCache[key]; if (cached) { @@ -1046,7 +1053,7 @@ function peg$parse(input, options) { function peg$parsestatement() { var s0; - var key = peg$currPos * 67 + 6; + var key = peg$currPos * 68 + 6; var cached = peg$resultsCache[key]; if (cached) { @@ -1068,7 +1075,7 @@ function peg$parse(input, options) { function peg$parseletStatement() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 7; + var key = peg$currPos * 68 + 7; var cached = peg$resultsCache[key]; if (cached) { @@ -1109,7 +1116,7 @@ function peg$parse(input, options) { function peg$parsedefunStatement() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - var key = peg$currPos * 67 + 8; + var key = peg$currPos * 68 + 8; var cached = peg$resultsCache[key]; if (cached) { @@ -1186,7 +1193,7 @@ function peg$parse(input, options) { function peg$parseassignmentOp() { var s0, s1; - var key = peg$currPos * 67 + 9; + var key = peg$currPos * 68 + 9; var cached = peg$resultsCache[key]; if (cached) { @@ -1221,7 +1228,7 @@ function peg$parse(input, options) { function peg$parsearray_parameters() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 10; + var key = peg$currPos * 68 + 10; var cached = peg$resultsCache[key]; if (cached) { @@ -1300,7 +1307,7 @@ function peg$parse(input, options) { function peg$parseexpression() { var s0; - var key = peg$currPos * 67 + 11; + var key = peg$currPos * 68 + 11; var cached = peg$resultsCache[key]; if (cached) { @@ -1325,7 +1332,7 @@ function peg$parse(input, options) { function peg$parseifthenelse() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11; - var key = peg$currPos * 67 + 12; + var key = peg$currPos * 68 + 12; var cached = peg$resultsCache[key]; if (cached) { @@ -1439,7 +1446,7 @@ function peg$parse(input, options) { function peg$parseternary() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; - var key = peg$currPos * 67 + 13; + var key = peg$currPos * 68 + 13; var cached = peg$resultsCache[key]; if (cached) { @@ -1513,7 +1520,7 @@ function peg$parse(input, options) { function peg$parselogicalAdditive() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 14; + var key = peg$currPos * 68 + 14; var cached = peg$resultsCache[key]; if (cached) { @@ -1578,7 +1585,7 @@ function peg$parse(input, options) { function peg$parselogicalAdditiveOp() { var s0, s1; - var key = peg$currPos * 67 + 15; + var key = peg$currPos * 68 + 15; var cached = peg$resultsCache[key]; if (cached) { @@ -1613,7 +1620,7 @@ function peg$parse(input, options) { function peg$parselogicalMultiplicative() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 16; + var key = peg$currPos * 68 + 16; var cached = peg$resultsCache[key]; if (cached) { @@ -1678,7 +1685,7 @@ function peg$parse(input, options) { function peg$parselogicalMultiplicativeOp() { var s0, s1; - var key = peg$currPos * 67 + 17; + var key = peg$currPos * 68 + 17; var cached = peg$resultsCache[key]; if (cached) { @@ -1713,7 +1720,7 @@ function peg$parse(input, options) { function peg$parseequality() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 18; + var key = peg$currPos * 68 + 18; var cached = peg$resultsCache[key]; if (cached) { @@ -1757,7 +1764,7 @@ function peg$parse(input, options) { function peg$parseequalityOp() { var s0, s1; - var key = peg$currPos * 67 + 19; + var key = peg$currPos * 68 + 19; var cached = peg$resultsCache[key]; if (cached) { @@ -1803,7 +1810,7 @@ function peg$parse(input, options) { function peg$parserelational() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 20; + var key = peg$currPos * 68 + 20; var cached = peg$resultsCache[key]; if (cached) { @@ -1847,7 +1854,7 @@ function peg$parse(input, options) { function peg$parserelationalOp() { var s0, s1; - var key = peg$currPos * 67 + 21; + var key = peg$currPos * 68 + 21; var cached = peg$resultsCache[key]; if (cached) { @@ -1915,7 +1922,7 @@ function peg$parse(input, options) { function peg$parseadditive() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 22; + var key = peg$currPos * 68 + 22; var cached = peg$resultsCache[key]; if (cached) { @@ -1980,7 +1987,7 @@ function peg$parse(input, options) { function peg$parseadditiveOp() { var s0, s1; - var key = peg$currPos * 67 + 23; + var key = peg$currPos * 68 + 23; var cached = peg$resultsCache[key]; if (cached) { @@ -2048,7 +2055,7 @@ function peg$parse(input, options) { function peg$parsemultiplicative() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 24; + var key = peg$currPos * 68 + 24; var cached = peg$resultsCache[key]; if (cached) { @@ -2113,7 +2120,7 @@ function peg$parse(input, options) { function peg$parsemultiplicativeOp() { var s0, s1; - var key = peg$currPos * 67 + 25; + var key = peg$currPos * 68 + 25; var cached = peg$resultsCache[key]; if (cached) { @@ -2181,7 +2188,7 @@ function peg$parse(input, options) { function peg$parsepower() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 26; + var key = peg$currPos * 68 + 26; var cached = peg$resultsCache[key]; if (cached) { @@ -2246,7 +2253,7 @@ function peg$parse(input, options) { function peg$parsepowerOp() { var s0, s1; - var key = peg$currPos * 67 + 27; + var key = peg$currPos * 68 + 27; var cached = peg$resultsCache[key]; if (cached) { @@ -2292,7 +2299,7 @@ function peg$parse(input, options) { function peg$parsecredibleInterval() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 28; + var key = peg$currPos * 68 + 28; var cached = peg$resultsCache[key]; if (cached) { @@ -2377,7 +2384,7 @@ function peg$parse(input, options) { function peg$parsecredibleIntervalOp() { var s0, s1; - var key = peg$currPos * 67 + 29; + var key = peg$currPos * 68 + 29; var cached = peg$resultsCache[key]; if (cached) { @@ -2412,7 +2419,7 @@ function peg$parse(input, options) { function peg$parsechainFunctionCall() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 30; + var key = peg$currPos * 68 + 30; var cached = peg$resultsCache[key]; if (cached) { @@ -2515,7 +2522,7 @@ function peg$parse(input, options) { function peg$parsechainedFunction() { var s0, s1, s2, s3, s4, s5, s6; - var key = peg$currPos * 67 + 31; + var key = peg$currPos * 68 + 31; var cached = peg$resultsCache[key]; if (cached) { @@ -2627,7 +2634,7 @@ function peg$parse(input, options) { function peg$parseunary() { var s0, s1, s2, s3; - var key = peg$currPos * 67 + 32; + var key = peg$currPos * 68 + 32; var cached = peg$resultsCache[key]; if (cached) { @@ -2667,7 +2674,7 @@ function peg$parse(input, options) { function peg$parseunaryOperator() { var s0, s1; - var key = peg$currPos * 67 + 33; + var key = peg$currPos * 68 + 33; var cached = peg$resultsCache[key]; if (cached) { @@ -2724,7 +2731,7 @@ function peg$parse(input, options) { function peg$parseindexedValue() { var s0; - var key = peg$currPos * 67 + 34; + var key = peg$currPos * 68 + 34; var cached = peg$resultsCache[key]; if (cached) { @@ -2749,7 +2756,7 @@ function peg$parse(input, options) { function peg$parsecollectionElement() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - var key = peg$currPos * 67 + 35; + var key = peg$currPos * 68 + 35; var cached = peg$resultsCache[key]; if (cached) { @@ -3051,7 +3058,7 @@ function peg$parse(input, options) { function peg$parsearray_functionArguments() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 36; + var key = peg$currPos * 68 + 36; var cached = peg$resultsCache[key]; if (cached) { @@ -3130,7 +3137,7 @@ function peg$parse(input, options) { function peg$parserecordElement() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; - var key = peg$currPos * 67 + 37; + var key = peg$currPos * 68 + 37; var cached = peg$resultsCache[key]; if (cached) { @@ -3246,7 +3253,7 @@ function peg$parse(input, options) { function peg$parseatom() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 38; + var key = peg$currPos * 68 + 38; var cached = peg$resultsCache[key]; if (cached) { @@ -3306,7 +3313,7 @@ function peg$parse(input, options) { function peg$parsebasicValue() { var s0; - var key = peg$currPos * 67 + 39; + var key = peg$currPos * 68 + 39; var cached = peg$resultsCache[key]; if (cached) { @@ -3328,7 +3335,7 @@ function peg$parse(input, options) { function peg$parsebasicLiteral() { var s0; - var key = peg$currPos * 67 + 40; + var key = peg$currPos * 68 + 40; var cached = peg$resultsCache[key]; if (cached) { @@ -3339,14 +3346,11 @@ function peg$parse(input, options) { s0 = peg$parsestring(); if (s0 === peg$FAILED) { - s0 = peg$parsefloat(); + s0 = peg$parsenumber(); if (s0 === peg$FAILED) { - s0 = peg$parseinteger(); + s0 = peg$parseboolean(); if (s0 === peg$FAILED) { - s0 = peg$parseboolean(); - if (s0 === peg$FAILED) { - s0 = peg$parsedollarIdentifier(); - } + s0 = peg$parsedollarIdentifier(); } } } @@ -3359,7 +3363,7 @@ function peg$parse(input, options) { function peg$parseidentifier() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 41; + var key = peg$currPos * 68 + 41; var cached = peg$resultsCache[key]; if (cached) { @@ -3447,7 +3451,7 @@ function peg$parse(input, options) { function peg$parsedollarIdentifier() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 42; + var key = peg$currPos * 68 + 42; var cached = peg$resultsCache[key]; if (cached) { @@ -3535,7 +3539,7 @@ function peg$parse(input, options) { function peg$parsestring() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 43; + var key = peg$currPos * 68 + 43; var cached = peg$resultsCache[key]; if (cached) { @@ -3676,10 +3680,44 @@ function peg$parse(input, options) { return s0; } + function peg$parsenumber() { + var s0, s1, s2; + + var key = peg$currPos * 68 + 44; + var cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + + s0 = peg$currPos; + s1 = peg$parsefloat(); + if (s1 === peg$FAILED) { + s1 = peg$parseinteger(); + } + if (s1 !== peg$FAILED) { + s2 = peg$parseidentifier(); + if (s2 === peg$FAILED) { + s2 = null; + } + peg$savedPos = s0; + s0 = peg$f28(s1, s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + + return s0; + } + function peg$parseinteger() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 44; + var key = peg$currPos * 68 + 45; var cached = peg$resultsCache[key]; if (cached) { @@ -3740,7 +3778,7 @@ function peg$parse(input, options) { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f28(); + s0 = peg$f29(); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -3769,7 +3807,7 @@ function peg$parse(input, options) { function peg$parsefloat() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 45; + var key = peg$currPos * 68 + 46; var cached = peg$resultsCache[key]; if (cached) { @@ -3898,7 +3936,7 @@ function peg$parse(input, options) { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f29(); + s1 = peg$f30(); } s0 = s1; peg$silentFails--; @@ -3917,7 +3955,7 @@ function peg$parse(input, options) { function peg$parsefloatExponent() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 46; + var key = peg$currPos * 68 + 47; var cached = peg$resultsCache[key]; if (cached) { @@ -3979,7 +4017,7 @@ function peg$parse(input, options) { function peg$parsed() { var s0; - var key = peg$currPos * 67 + 47; + var key = peg$currPos * 68 + 48; var cached = peg$resultsCache[key]; if (cached) { @@ -4006,7 +4044,7 @@ function peg$parse(input, options) { function peg$parseboolean() { var s0, s1; - var key = peg$currPos * 67 + 48; + var key = peg$currPos * 68 + 49; var cached = peg$resultsCache[key]; if (cached) { @@ -4039,7 +4077,7 @@ function peg$parse(input, options) { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f30(); + s1 = peg$f31(); } s0 = s1; peg$silentFails--; @@ -4058,7 +4096,7 @@ function peg$parse(input, options) { function peg$parsevalueConstructor() { var s0; - var key = peg$currPos * 67 + 49; + var key = peg$currPos * 68 + 50; var cached = peg$resultsCache[key]; if (cached) { @@ -4086,7 +4124,7 @@ function peg$parse(input, options) { function peg$parselambda() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12; - var key = peg$currPos * 67 + 50; + var key = peg$currPos * 68 + 51; var cached = peg$resultsCache[key]; if (cached) { @@ -4161,7 +4199,7 @@ function peg$parse(input, options) { } if (s12 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f31(s5, s9, s10); + s0 = peg$f32(s5, s9, s10); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4242,7 +4280,7 @@ function peg$parse(input, options) { } if (s11 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f32(s5, s9); + s0 = peg$f33(s5, s9); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4277,7 +4315,7 @@ function peg$parse(input, options) { function peg$parsearrayConstructor() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 51; + var key = peg$currPos * 68 + 52; var cached = peg$resultsCache[key]; if (cached) { @@ -4310,7 +4348,7 @@ function peg$parse(input, options) { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f33(); + s0 = peg$f34(); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4346,7 +4384,7 @@ function peg$parse(input, options) { } if (s5 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f34(s3); + s0 = peg$f35(s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4376,7 +4414,7 @@ function peg$parse(input, options) { function peg$parsearray_elements() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 52; + var key = peg$currPos * 68 + 53; var cached = peg$resultsCache[key]; if (cached) { @@ -4455,7 +4493,7 @@ function peg$parse(input, options) { function peg$parserecordConstructor() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 53; + var key = peg$currPos * 68 + 54; var cached = peg$resultsCache[key]; if (cached) { @@ -4491,7 +4529,7 @@ function peg$parse(input, options) { } if (s5 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f35(s3); + s0 = peg$f36(s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4520,7 +4558,7 @@ function peg$parse(input, options) { function peg$parsearray_recordArguments() { var s0, s1, s2, s3, s4, s5, s6, s7; - var key = peg$currPos * 67 + 54; + var key = peg$currPos * 68 + 55; var cached = peg$resultsCache[key]; if (cached) { @@ -4599,7 +4637,7 @@ function peg$parse(input, options) { function peg$parsekeyValuePair() { var s0, s1, s2, s3, s4, s5; - var key = peg$currPos * 67 + 55; + var key = peg$currPos * 68 + 56; var cached = peg$resultsCache[key]; if (cached) { @@ -4626,7 +4664,7 @@ function peg$parse(input, options) { s5 = peg$parseexpression(); if (s5 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f36(s1, s5); + s0 = peg$f37(s1, s5); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -4648,7 +4686,7 @@ function peg$parse(input, options) { function peg$parse_() { var s0, s1; - var key = peg$currPos * 67 + 56; + var key = peg$currPos * 68 + 57; var cached = peg$resultsCache[key]; if (cached) { @@ -4678,7 +4716,7 @@ function peg$parse(input, options) { function peg$parse_nl() { var s0, s1; - var key = peg$currPos * 67 + 57; + var key = peg$currPos * 68 + 58; var cached = peg$resultsCache[key]; if (cached) { @@ -4714,7 +4752,7 @@ function peg$parse(input, options) { function peg$parse__() { var s0, s1; - var key = peg$currPos * 67 + 58; + var key = peg$currPos * 68 + 59; var cached = peg$resultsCache[key]; if (cached) { @@ -4750,7 +4788,7 @@ function peg$parse(input, options) { function peg$parse__nl() { var s0, s1; - var key = peg$currPos * 67 + 59; + var key = peg$currPos * 68 + 60; var cached = peg$resultsCache[key]; if (cached) { @@ -4792,7 +4830,7 @@ function peg$parse(input, options) { function peg$parsestatementSeparator() { var s0, s1, s2, s3; - var key = peg$currPos * 67 + 60; + var key = peg$currPos * 68 + 61; var cached = peg$resultsCache[key]; if (cached) { @@ -4860,7 +4898,7 @@ function peg$parse(input, options) { function peg$parsecommentOrNewLine() { var s0, s1, s2; - var key = peg$currPos * 67 + 61; + var key = peg$currPos * 68 + 62; var cached = peg$resultsCache[key]; if (cached) { @@ -4891,7 +4929,7 @@ function peg$parse(input, options) { function peg$parsefinalComment() { var s0, s1, s2, s3, s4; - var key = peg$currPos * 67 + 62; + var key = peg$currPos * 68 + 63; var cached = peg$resultsCache[key]; if (cached) { @@ -4967,7 +5005,7 @@ function peg$parse(input, options) { function peg$parsewhiteSpaceCharactersOrComment() { var s0; - var key = peg$currPos * 67 + 63; + var key = peg$currPos * 68 + 64; var cached = peg$resultsCache[key]; if (cached) { @@ -4989,7 +5027,7 @@ function peg$parse(input, options) { function peg$parsedelimitedComment() { var s0, s1, s2, s3; - var key = peg$currPos * 67 + 64; + var key = peg$currPos * 68 + 65; var cached = peg$resultsCache[key]; if (cached) { @@ -5067,7 +5105,7 @@ function peg$parse(input, options) { function peg$parsewhiteSpaceCharacters() { var s0; - var key = peg$currPos * 67 + 65; + var key = peg$currPos * 68 + 66; var cached = peg$resultsCache[key]; if (cached) { @@ -5094,7 +5132,7 @@ function peg$parse(input, options) { function peg$parsenewLine() { var s0, s1; - var key = peg$currPos * 67 + 66; + var key = peg$currPos * 68 + 67; var cached = peg$resultsCache[key]; if (cached) { diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy index 5d3392b3..15cc05a0 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy @@ -248,8 +248,7 @@ basicValue = valueConstructor / basicLiteral basicLiteral = string - / float - / integer + / number / boolean / dollarIdentifier @@ -263,6 +262,15 @@ string 'string' = characters:("'" @([^'])* "'") {return nodeString(characters.join(''))} / characters:('"' @([^"])* '"') {return nodeString(characters.join(''))} +number = number:(float / integer) unit:identifier? + { + if (unit === null) + { return number } + else + { return makeFunctionCall('fromUnit_'+unit.value, [number]) + } + } + integer 'integer' = d+ !"\." ![e]i { return nodeInteger(parseInt(text()))} From a386eee570994306f8f0458814a9137d76f5bbd6 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 23 May 2022 18:17:11 +0200 Subject: [PATCH 08/14] remove unit evaluation test We provide no implementation --- .../Reducer_Peggy_ToExpression_test.res | 4 ---- .../Reducer_Dispatch_BuiltIn.res | 18 ------------------ 2 files changed, 22 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res index fa6c58f9..81bafd97 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res @@ -217,8 +217,4 @@ describe("Peggy to Expression", () => { (), ) }) - - describe("unit", () => { - testToExpression("1m", "(:$$_block_$$ (:multiply 1 (:$valueOfUnit 'm')))", ~v="1", ()) - }) }) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res index 1ab8d559..141b4a37 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res @@ -129,23 +129,6 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce ) } - let doValueOfUnit = (aUnit: string) => - switch aUnit { - | "nm" => 0.000000001->EvNumber->Ok - | "um" => 0.000001->EvNumber->Ok - | "mm" => 0.001->EvNumber->Ok - | "cm" => 0.01->EvNumber->Ok - | "dm" => 0.1->EvNumber->Ok - | "m" => 1.->EvNumber->Ok - | "dam" => 10.->EvNumber->Ok - | "hm" => 100.->EvNumber->Ok - | "km" => 1000.->EvNumber->Ok - | "Mm" => 1000000.->EvNumber->Ok - | "Gm" => 1000000000.->EvNumber->Ok - | "Tm" => 1000000000000.->EvNumber->Ok - | _ => REUnitNotFound(aUnit)->Error - } - switch call { | ("$_atIndex_$", [EvArray(aValueArray), EvNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex) | ("$_atIndex_$", [EvRecord(dict), EvString(sIndex)]) => recordAtIndex(dict, sIndex) @@ -154,7 +137,6 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce | ("$_exportBindings_$", [EvRecord(externalBindings)]) => doExportBindings(externalBindings) | ("$_setBindings_$", [EvRecord(externalBindings), EvSymbol(symbol), value]) => doSetBindings(externalBindings, symbol, value) - | ("$valueOfUnit", [EvString(aUnit)]) => doValueOfUnit(aUnit) | ("inspect", [value, EvString(label)]) => inspectLabel(value, label) | ("inspect", [value]) => inspect(value) | ("keep", [EvArray(aValueArray), EvLambda(aLambdaValue)]) => From bb5af13ddc981ccac1a2fdcd66c87dcf2442d838 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Mon, 23 May 2022 13:44:41 -0400 Subject: [PATCH 09/14] Moved DateTime functionality into separate file --- .../ReducerInterface_DateTime.res | 48 +++++------ .../ReducerInterface_ExpressionValue.res | 4 +- .../src/rescript/Utility/DateTime.res | 79 ++++++++++++++++++ .../squiggle-lang/src/rescript/Utility/E.res | 82 +------------------ 4 files changed, 106 insertions(+), 107 deletions(-) create mode 100644 packages/squiggle-lang/src/rescript/Utility/DateTime.res diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res index a0059392..ee7b1a7c 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res @@ -5,22 +5,22 @@ let dateDispatch = (call: ExpressionValue.functionCall, env: DistributionOperati result, > => { switch call { - | ("toString", [EvDate(t)]) => EvString(E.Date.toString(t))->Ok->Some + | ("toString", [EvDate(t)]) => EvString(DateTime.Date.toString(t))->Ok->Some | ("makeDateFromYear", [EvNumber(year)]) => - switch E.Date.makeFromYear(year) { + switch DateTime.Date.makeFromYear(year) { | Ok(t) => EvDate(t)->Ok->Some | Error(e) => RETodo(e)->Error->Some } - | ("dateFromNumber", [EvNumber(f)]) => EvDate(E.Date.fromFloat(f))->Ok->Some - | ("toNumber", [EvDate(f)]) => EvNumber(E.Date.toFloat(f))->Ok->Some + | ("dateFromNumber", [EvNumber(f)]) => EvDate(DateTime.Date.fromFloat(f))->Ok->Some + | ("toNumber", [EvDate(f)]) => EvNumber(DateTime.Date.toFloat(f))->Ok->Some | ("subtract", [EvDate(d1), EvDate(d2)]) => - switch E.Date.subtract(d1, d2) { + switch DateTime.Date.subtract(d1, d2) { | Ok(d) => EvTimeDuration(d)->Ok | Error(e) => Error(RETodo(e)) }->Some | ("subtract", [EvDate(d1), EvTimeDuration(d2)]) => - EvDate(E.Date.subtractDuration(d1, d2))->Ok->Some - | ("add", [EvDate(d1), EvTimeDuration(d2)]) => EvDate(E.Date.addDuration(d1, d2))->Ok->Some + EvDate(DateTime.Date.subtractDuration(d1, d2))->Ok->Some + | ("add", [EvDate(d1), EvTimeDuration(d2)]) => EvDate(DateTime.Date.addDuration(d1, d2))->Ok->Some | _ => None } } @@ -29,23 +29,23 @@ let durationDispatch = (call: ExpressionValue.functionCall, _: DistributionOpera result, > => { switch call { - | ("toString", [EvTimeDuration(t)]) => EvString(E.Duration.toString(t))->Ok->Some - | ("hours", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromHours(f))->Ok->Some - | ("minutes", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromMinutes(f))->Ok->Some - | ("days", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromDays(f))->Ok->Some - | ("years", [EvNumber(f)]) => EvTimeDuration(E.Duration.fromYears(f))->Ok->Some - | ("toHours", [EvTimeDuration(f)]) => EvNumber(E.Duration.toHours(f))->Ok->Some - | ("toMinutes", [EvTimeDuration(f)]) => EvNumber(E.Duration.toMinutes(f))->Ok->Some - | ("toDays", [EvTimeDuration(f)]) => EvNumber(E.Duration.toDays(f))->Ok->Some - | ("toYears", [EvTimeDuration(f)]) => EvNumber(E.Duration.toYears(f))->Ok->Some - | ("add", [EvTimeDuration(d1), EvTimeDuration(d2)]) => - EvTimeDuration(E.Duration.add(d1, d2))->Ok->Some - | ("subtract", [EvTimeDuration(d1), EvTimeDuration(d2)]) => - EvTimeDuration(E.Duration.subtract(d1, d2))->Ok->Some - | ("multiply", [EvTimeDuration(d1), EvNumber(d2)]) => - EvTimeDuration(E.Duration.multiply(d1, d2))->Ok->Some - | ("divide", [EvTimeDuration(d1), EvNumber(d2)]) => - EvTimeDuration(E.Duration.divide(d1, d2))->Ok->Some + | ("toString", [EvTimeDuration(t)]) => EvString(DateTime.Duration.toString(t))->Ok->Some + | ("hours", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some + | ("minutes", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some + | ("days", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some + | ("years", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some + | ("toHours", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toHours(f))->Ok->Some + | ("toMinutes", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toMinutes(f))->Ok->Some + | ("toDays", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toDays(f))->Ok->Some + | ("toYears", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toYears(f))->Ok->Some + | ("add", [EvTimeDuration(d1), EvTimeDuration(d2)]) => + EvTimeDuration(DateTime.Duration.add(d1, d2))->Ok->Some + | ("subtract", [EvTimeDuration(d1), EvTimeDuration(d2)]) => + EvTimeDuration(DateTime.Duration.subtract(d1, d2))->Ok->Some + | ("multiply", [EvTimeDuration(d1), EvNumber(d2)]) => + EvTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some + | ("divide", [EvTimeDuration(d1), EvNumber(d2)]) => + EvTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some | _ => None } } diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res index 6da34db1..c9363606 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res @@ -53,8 +53,8 @@ let rec toString = aValue => | EvSymbol(aString) => `:${aString}` | EvRecord(aRecord) => aRecord->toStringRecord | EvDistribution(dist) => GenericDist.toString(dist) - | EvDate(date) => E.Date.toString(date) - | EvTimeDuration(t) => E.Duration.toString(t) + | EvDate(date) => DateTime.Date.toString(date) + | EvTimeDuration(t) => DateTime.Duration.toString(t) } and toStringRecord = aRecord => { let pairs = diff --git a/packages/squiggle-lang/src/rescript/Utility/DateTime.res b/packages/squiggle-lang/src/rescript/Utility/DateTime.res new file mode 100644 index 00000000..344c8760 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/Utility/DateTime.res @@ -0,0 +1,79 @@ +module Duration = { + //Stores in Unix milliseconds + type t = float + let minute = Belt.Float.fromInt(60 * 1000) + let hour = Belt.Float.fromInt(60 * 60 * 1000) + let day = Belt.Float.fromInt(24 * 60 * 60 * 1000) + let year = Belt.Float.fromInt(24 * 60 * 60 * 1000) *. 365.25 + let fromFloat = (f: float): t => f + let toFloat = (d: t): float => d + let fromMinutes = (h: float): t => h *. minute + let fromHours = (h: float): t => h *. hour + let fromDays = (d: float): t => d *. day + let fromYears = (y: float): t => y *. year + let toMinutes = (t: t): float => t /. minute + let toHours = (t: t): float => t /. hour + let toDays = (t: t): float => t /. day + let toYears = (t: t): float => t /. year + + let toString = (t: t): string => { + let shouldPluralize = f => f != 1.0 + let display = (f: float, s: string) => + `${E.Float.with3DigitsPrecision(f)} ${s}${shouldPluralize(f) ? "s" : ""}` + let abs = Js.Math.abs_float(t) + if abs >= year { + display(t /. year, "year") + } else if abs >= day { + display(t /. day, "day") + } else if abs >= hour { + display(t /. hour, "hour") + } else if abs >= minute { + display(t /. minute, "minute") + } else { + E.Float.toFixed(t) ++ "ms" + } + } + let add = (t1: t, t2: t): t => t1 +. t2 + let subtract = (t1: t, t2: t): t => t1 -. t2 + let multiply = (t1: t, t2: float): t => t1 *. t2 + let divide = (t1: t, t2: float): t => t1 /. t2 +} + +module Date = { + //The Rescript/JS implementation of Date is pretty mediocre. It would be good to improve upon later. + type t = Js.Date.t + let toFloat = Js.Date.getTime + let getFullYear = Js.Date.getFullYear + let toString = Js.Date.toDateString + let fromFloat = Js.Date.fromFloat + let fmap = (t: t, fn: float => float) => t->toFloat->fn->fromFloat + let subtract = (t1: t, t2: t) => { + let (f1, f2) = (toFloat(t1), toFloat(t2)) + let diff = f1 -. f2 + if diff < 0.0 { + Error("Cannot subtract a date by one that is in its future") + } else { + Ok(Duration.fromFloat(diff)) + } + } + let addDuration = (t: t, duration: Duration.t) => fmap(t, t => t +. duration) + let subtractDuration = (t: t, duration: Duration.t) => fmap(t, t => t -. duration) + //The Js.Date.makeWithYM function accepts a float, but only treats it as a whole number. + //Our version takes an integer to make this distinction clearer. + let makeWithYearInt = (y: int): result => { + if y < 100 { + Error("Year must be over 100") + } else if y > 200000 { + Error("Year must be less than 200000") + } else { + Ok(Js.Date.makeWithYM(~year=Belt.Float.fromInt(y), ~month=0.0, ())) + } + } + let makeFromYear = (year: float): result => { + let floor = year->Js.Math.floor_float + makeWithYearInt(Belt.Float.toInt(floor))->E.R2.fmap(earlyDate => { + let diff = year -. floor + earlyDate->addDuration(diff *. Duration.year) + }) + } +} diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index 46787134..77b5c5e4 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -832,84 +832,4 @@ module JsArray = { |> Js.Array.filter(O.isSome) |> Js.Array.map(O.toExn("Warning: This should not have happened")) let filter = Js.Array.filter -} - -module Duration = { - //Stores in Unix milliseconds - type t = float - let minute = Belt.Float.fromInt(60 * 1000) - let hour = Belt.Float.fromInt(60 * 60 * 1000) - let day = Belt.Float.fromInt(24 * 60 * 60 * 1000) - let year = Belt.Float.fromInt(24 * 60 * 60 * 1000) *. 365.25 - let fromFloat = (f: float): t => f - let toFloat = (d: t): float => d - let fromMinutes = (h: float): t => h *. minute - let fromHours = (h: float): t => h *. hour - let fromDays = (d: float): t => d *. day - let fromYears = (y: float): t => y *. year - let toMinutes = (t: t): float => t /. minute - let toHours = (t: t): float => t /. hour - let toDays = (t: t): float => t /. day - let toYears = (t: t): float => t /. year - - let toString = (t: t): string => { - let shouldPluralize = f => f != 1.0 - let display = (f: float, s: string) => - `${Float.with3DigitsPrecision(f)} ${s}${shouldPluralize(f) ? "s" : ""}` - let abs = Js.Math.abs_float(t) - if abs >= year { - display(t /. year, "year") - } else if abs >= day { - display(t /. day, "day") - } else if abs >= hour { - display(t /. hour, "hour") - } else if abs >= minute { - display(t /. minute, "minute") - } else { - Float.toFixed(t) ++ "ms" - } - } - let add = (t1: t, t2: t): t => t1 +. t2 - let subtract = (t1: t, t2: t): t => t1 -. t2 - let multiply = (t1: t, t2: float): t => t1 *. t2 - let divide = (t1: t, t2: float): t => t1 /. t2 -} - -module Date = { - //The Rescript/JS implementation of Date is pretty mediocre. It would be good to improve upon later. - type t = Js.Date.t - let toFloat = Js.Date.getTime - let getFullYear = Js.Date.getFullYear - let toString = Js.Date.toDateString - let fromFloat = Js.Date.fromFloat - let fmap = (t: t, fn: float => float) => t->toFloat->fn->fromFloat - let subtract = (t1: t, t2: t) => { - let (f1, f2) = (toFloat(t1), toFloat(t2)) - let diff = f1 -. f2 - if diff < 0.0 { - Error("Cannot subtract a date by one that is in its future") - } else { - Ok(Duration.fromFloat(diff)) - } - } - let addDuration = (t: t, duration: Duration.t) => fmap(t, t => t +. duration) - let subtractDuration = (t: t, duration: Duration.t) => fmap(t, t => t -. duration) - //The Js.Date.makeWithYM function accepts a float, but only treats it as a whole number. - //Our version takes an integer to make this distinction clearer. - let makeWithYearInt = (y: int): result => { - if y < 100 { - Error("Year must be over 100") - } else if y > 200000 { - Error("Year must be less than 200000") - } else { - Ok(Js.Date.makeWithYM(~year=Belt.Float.fromInt(y), ~month=0.0, ())) - } - } - let makeFromYear = (year: float): result => { - let floor = year->Js.Math.floor_float - makeWithYearInt(Belt.Float.toInt(floor))->R2.fmap(earlyDate => { - let diff = year -. floor - earlyDate->addDuration(diff *. Duration.year) - }) - } -} +} \ No newline at end of file From 5fd5c1c1f86fe863da751e47d4652482f082e5cc Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 24 May 2022 14:12:49 -0400 Subject: [PATCH 10/14] Formatted Code --- packages/squiggle-lang/src/js/rescript_interop.ts | 2 +- .../rescript/ReducerInterface/ReducerInterface_DateTime.res | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/squiggle-lang/src/js/rescript_interop.ts b/packages/squiggle-lang/src/js/rescript_interop.ts index 3bc7ccbb..7bb98b5d 100644 --- a/packages/squiggle-lang/src/js/rescript_interop.ts +++ b/packages/squiggle-lang/src/js/rescript_interop.ts @@ -96,7 +96,7 @@ export type squiggleExpression = | tagged<"number", number> | tagged<"date", Date> | tagged<"timeDuration", number> - | tagged<"record", { [key: string]: squiggleExpression }> + | tagged<"record", { [key: string]: squiggleExpression }>; export { lambdaValue }; diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res index ee7b1a7c..0fcd04e9 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res @@ -1,11 +1,11 @@ module ExpressionValue = ReducerInterface_ExpressionValue type expressionValue = ExpressionValue.expressionValue -let dateDispatch = (call: ExpressionValue.functionCall, env: DistributionOperation.env): option< +let dateDispatch = (call: ExpressionValue.functionCall, _: DistributionOperation.env): option< result, > => { switch call { - | ("toString", [EvDate(t)]) => EvString(DateTime.Date.toString(t))->Ok->Some + | ("toString", [EvDate(t)]) => ExpressionValue.EvString(DateTime.Date.toString(t))->Ok->Some | ("makeDateFromYear", [EvNumber(year)]) => switch DateTime.Date.makeFromYear(year) { | Ok(t) => EvDate(t)->Ok->Some From 1e4aecd4fcd8efe47e7ea10a4c4e96eecfb28dc0 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 24 May 2022 14:23:26 -0400 Subject: [PATCH 11/14] Delete Reducer_Peggy_GeneratedParser.js I'm pretty sure this should be in the gitignore. --- .../Reducer_Peggy_GeneratedParser.js | 4740 ----------------- 1 file changed, 4740 deletions(-) delete mode 100644 packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js deleted file mode 100644 index 239cc876..00000000 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js +++ /dev/null @@ -1,4740 +0,0 @@ -// Generated by Peggy 1.2.0. -// -// https://peggyjs.org/ - -"use strict"; - - - var toFunction = { - '-': 'subtract', - '->': 'pipe', - '!=': 'unequal', - '.-': 'dotSubtract', - '.*': 'dotMultiply', - './': 'dotDivide', - '.^': 'dotPow', - '.+': 'dotAdd', - '*': 'multiply', - '/': 'divide', - '&&': 'and', - '^': 'pow', // or xor - '+': 'add', - '<': 'smaller', - '<=': 'smallerEq', - '==': 'equal', - '>': 'larger', - '>=': 'largerEq', - '||': 'or', - 'to': 'credibleIntervalToDistribution', - } - - var unaryToFunction = { - '-': 'unaryMinus', - '!': 'not', - '.-': 'unaryDotMinus', - } - - var postOperatorToFunction = { - '.': '$_atIndex_$', - '()': '$$_applyAll_$$', - '[]': '$_atIndex_$', - } - - function nodeBlock(statements) {return{type: 'Block', statements: statements}} - function nodeBoolean(value) {return {type: 'Boolean', value: value}} - function nodeCallIndentifier(value) {return {type: 'CallIdentifier', value: value}} - function nodeExpression(args) {return {type: 'Expression', nodes: args}} - function nodeFloat(value) {return {type: 'Float', value: value}} - function makeFunctionCall(fn, args) { - if (fn === '$$_applyAll_$$') { - // Any list of values is applied from left to right anyway. - // Like in Haskell and Lisp. - // So we remove the redundant $$_applyAll_$$. - if (args[0].type === "Identifier") {args[0].type = "CallIdentifier"} - return nodeExpression(args) - } else { - return nodeExpression([nodeCallIndentifier(fn), ...args]) - } - } - function nodeIdentifier(value) {return {type: 'Identifier', value: value}} - function nodeInteger(value) {return {type: 'Integer', value: value}} - function nodeKeyValue(key, value) { - if (key.type === 'Identifier') {key.type = 'String'} - return {type: 'KeyValue', key: key, value: value}} - function nodeLambda(args, body) {return {type: 'Lambda', args: args, body: body}} - function nodeLetStatment(variable, value) {return {type: 'LetStatement', variable: variable, value: value}} - function nodeString(value) {return {type: 'String', value: value}} - function nodeTernary(condition, trueExpression, falseExpression) {return {type: 'Ternary', condition: condition, trueExpression: trueExpression, falseExpression: falseExpression}} - - -function peg$subclass(child, parent) { - function C() { this.constructor = child; } - C.prototype = parent.prototype; - child.prototype = new C(); -} - -function peg$SyntaxError(message, expected, found, location) { - var self = Error.call(this, message); - if (Object.setPrototypeOf) { - Object.setPrototypeOf(self, peg$SyntaxError.prototype); - } - self.expected = expected; - self.found = found; - self.location = location; - self.name = "SyntaxError"; - return self; -} - -peg$subclass(peg$SyntaxError, Error); - -function peg$padEnd(str, targetLength, padString) { - padString = padString || " "; - 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) { - var str = "Error: " + this.message; - if (this.location) { - var src = null; - var k; - for (k = 0; k < sources.length; k++) { - if (sources[k].source === this.location.source) { - src = sources[k].text.split(/\r\n|\n|\r/g); - break; - } - } - var s = this.location.start; - 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 line = src[s.line - 1]; - var last = s.line === e.line ? e.column : line.length + 1; - str += "\n --> " + loc + "\n" - + filler + " |\n" - + s.line + " | " + line + "\n" - + filler + " | " + peg$padEnd("", s.column - 1) - + peg$padEnd("", last - s.column, "^"); - } else { - str += "\n at " + loc; - } - } - return str; -}; - -peg$SyntaxError.buildMessage = function(expected, found) { - var DESCRIBE_EXPECTATION_FNS = { - literal: function(expectation) { - return "\"" + literalEscape(expectation.text) + "\""; - }, - - 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 + "]"; - }, - - any: function() { - return "any character"; - }, - - end: function() { - return "end of input"; - }, - - other: function(expectation) { - return expectation.description; - } - }; - - function hex(ch) { - return ch.charCodeAt(0).toString(16).toUpperCase(); - } - - function literalEscape(s) { - return s - .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); }); - } - - function classEscape(s) { - return s - .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); }); - } - - function describeExpectation(expectation) { - return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); - } - - function describeExpected(expected) { - var descriptions = expected.map(describeExpectation); - var i, j; - - descriptions.sort(); - - if (descriptions.length > 0) { - for (i = 1, j = 1; i < descriptions.length; i++) { - if (descriptions[i - 1] !== descriptions[i]) { - descriptions[j] = descriptions[i]; - j++; - } - } - descriptions.length = j; - } - - switch (descriptions.length) { - case 1: - return descriptions[0]; - - case 2: - return descriptions[0] + " or " + descriptions[1]; - - default: - return descriptions.slice(0, -1).join(", ") - + ", or " - + descriptions[descriptions.length - 1]; - } - } - - function describeFound(found) { - return found ? "\"" + literalEscape(found) + "\"" : "end of input"; - } - - return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; -}; - -function peg$parse(input, options) { - options = options !== undefined ? options : {}; - - var peg$FAILED = {}; - var peg$source = options.grammarSource; - - var peg$startRuleFunctions = { start: peg$parsestart }; - var peg$startRuleFunction = peg$parsestart; - - var peg$c0 = "{"; - var peg$c1 = "}"; - var peg$c2 = "("; - var peg$c3 = ")"; - var peg$c4 = "="; - var peg$c5 = ","; - var peg$c6 = "if"; - var peg$c7 = "then"; - var peg$c8 = "else"; - var peg$c9 = "?"; - var peg$c10 = ":"; - var peg$c11 = "||"; - var peg$c12 = "&&"; - var peg$c13 = "=="; - var peg$c14 = "!="; - var peg$c15 = "<="; - var peg$c16 = "<"; - var peg$c17 = ">="; - var peg$c18 = ">"; - var peg$c19 = "+"; - var peg$c20 = "-"; - var peg$c21 = ".+"; - var peg$c22 = ".-"; - var peg$c23 = "*"; - var peg$c24 = "/"; - var peg$c25 = ".*"; - var peg$c26 = "./"; - var peg$c27 = "^"; - var peg$c28 = ".^"; - var peg$c29 = "to"; - var peg$c30 = "->"; - var peg$c31 = "|>"; - var peg$c32 = "!"; - var peg$c33 = "["; - var peg$c34 = "."; - var peg$c35 = "]"; - var peg$c36 = "'"; - var peg$c37 = "\""; - var peg$c38 = "true"; - var peg$c39 = "false"; - var peg$c40 = "|"; - var peg$c41 = ";"; - var peg$c42 = "//"; - var peg$c43 = "#"; - var peg$c44 = "/*"; - var peg$c45 = "*/"; - - var peg$r0 = /^[_a-z]/; - var peg$r1 = /^[_a-z0-9]/i; - var peg$r2 = /^[$_a-z]/; - var peg$r3 = /^[$_a-z0-9]/i; - var peg$r4 = /^[^']/; - var peg$r5 = /^[^"]/; - var peg$r6 = /^[e]/i; - var peg$r7 = /^[0-9]/; - var peg$r8 = /^[^\r\n]/; - var peg$r9 = /^[^*]/; - var peg$r10 = /^[ \t]/; - var peg$r11 = /^[\n\r]/; - - var peg$e0 = peg$literalExpectation("{", false); - var peg$e1 = peg$literalExpectation("}", false); - var peg$e2 = peg$literalExpectation("(", false); - var peg$e3 = peg$literalExpectation(")", false); - var peg$e4 = peg$otherExpectation("assignment"); - var peg$e5 = peg$literalExpectation("=", false); - var peg$e6 = peg$literalExpectation(",", false); - var peg$e7 = peg$literalExpectation("if", false); - var peg$e8 = peg$literalExpectation("then", false); - var peg$e9 = peg$literalExpectation("else", false); - var peg$e10 = peg$literalExpectation("?", false); - var peg$e11 = peg$literalExpectation(":", false); - var peg$e12 = peg$otherExpectation("operator"); - var peg$e13 = peg$literalExpectation("||", false); - var peg$e14 = peg$literalExpectation("&&", false); - var peg$e15 = peg$literalExpectation("==", false); - var peg$e16 = peg$literalExpectation("!=", false); - var peg$e17 = peg$literalExpectation("<=", false); - var peg$e18 = peg$literalExpectation("<", false); - var peg$e19 = peg$literalExpectation(">=", false); - var peg$e20 = peg$literalExpectation(">", false); - var peg$e21 = peg$literalExpectation("+", false); - var peg$e22 = peg$literalExpectation("-", false); - var peg$e23 = peg$literalExpectation(".+", false); - var peg$e24 = peg$literalExpectation(".-", false); - var peg$e25 = peg$literalExpectation("*", false); - var peg$e26 = peg$literalExpectation("/", false); - var peg$e27 = peg$literalExpectation(".*", false); - var peg$e28 = peg$literalExpectation("./", false); - var peg$e29 = peg$literalExpectation("^", false); - var peg$e30 = peg$literalExpectation(".^", false); - var peg$e31 = peg$literalExpectation("to", false); - var peg$e32 = peg$literalExpectation("->", false); - var peg$e33 = peg$literalExpectation("|>", false); - var peg$e34 = peg$otherExpectation("unary operator"); - var peg$e35 = peg$literalExpectation("!", false); - var peg$e36 = peg$literalExpectation("[", false); - var peg$e37 = peg$literalExpectation(".", false); - var peg$e38 = peg$literalExpectation("]", false); - var peg$e39 = peg$otherExpectation("identifier"); - var peg$e40 = peg$classExpectation(["_", ["a", "z"]], false, false); - var peg$e41 = peg$classExpectation(["_", ["a", "z"], ["0", "9"]], false, true); - var peg$e42 = peg$otherExpectation("$identifier"); - var peg$e43 = peg$classExpectation(["$", "_", ["a", "z"]], false, false); - var peg$e44 = peg$classExpectation(["$", "_", ["a", "z"], ["0", "9"]], false, true); - var peg$e45 = peg$otherExpectation("string"); - var peg$e46 = peg$literalExpectation("'", false); - var peg$e47 = peg$classExpectation(["'"], true, false); - var peg$e48 = peg$literalExpectation("\"", false); - var peg$e49 = peg$classExpectation(["\""], true, false); - var peg$e50 = peg$otherExpectation("integer"); - var peg$e51 = peg$classExpectation(["e"], false, true); - var peg$e52 = peg$otherExpectation("float"); - var peg$e53 = peg$classExpectation([["0", "9"]], false, false); - var peg$e54 = peg$otherExpectation("boolean"); - var peg$e55 = peg$literalExpectation("true", false); - var peg$e56 = peg$literalExpectation("false", false); - var peg$e57 = peg$literalExpectation("|", false); - var peg$e58 = peg$otherExpectation("array"); - var peg$e59 = peg$otherExpectation("record"); - var peg$e60 = peg$otherExpectation("whitespace"); - var peg$e61 = peg$otherExpectation("optional whitespace or newline"); - var peg$e62 = peg$otherExpectation("whitespace or newline"); - var peg$e63 = peg$otherExpectation("statement separator"); - var peg$e64 = peg$literalExpectation(";", false); - var peg$e65 = peg$otherExpectation("line comment"); - var peg$e66 = peg$literalExpectation("//", false); - var peg$e67 = peg$literalExpectation("#", false); - var peg$e68 = peg$classExpectation(["\r", "\n"], true, false); - var peg$e69 = peg$otherExpectation("comment"); - var peg$e70 = peg$literalExpectation("/*", false); - var peg$e71 = peg$classExpectation(["*"], true, false); - var peg$e72 = peg$literalExpectation("*/", false); - var peg$e73 = peg$classExpectation([" ", "\t"], false, false); - var peg$e74 = peg$otherExpectation("newline"); - var peg$e75 = peg$classExpectation(["\n", "\r"], false, false); - - var peg$f0 = function(start) {return start}; - var peg$f1 = function(statements, finalExpression) { if (finalExpression != null) { statements.push(finalExpression) } - return nodeBlock(statements) }; - var peg$f2 = function(finalExpression) { return nodeBlock([finalExpression])}; - var peg$f3 = function(statements, finalExpression) { statements.push(finalExpression) - return nodeBlock(statements) }; - var peg$f4 = function(finalExpression) { return nodeBlock([finalExpression]) }; - var peg$f5 = function(head, tail) { return [head, ...tail] }; - var peg$f6 = function(head) { return [head] }; - var peg$f7 = function(variable, value) { return nodeLetStatment(variable, value) }; - var peg$f8 = function(variable, args, body) { var value = nodeLambda(args, body) - return nodeLetStatment(variable, value) }; - var peg$f9 = function(head, tail) { return [head, ...tail]; }; - var peg$f10 = function(condition, trueExpression, falseExpression) { return nodeTernary(condition, trueExpression, falseExpression) }; - var peg$f11 = function(head, operator, arg) {return {operator: operator, right: arg}}; - var peg$f12 = function(head, tail) { return tail.reduce(function(result, element) { - return makeFunctionCall(toFunction[element.operator], [result, element.right]) - }, head)}; - var peg$f13 = function(left, operator, right) { return makeFunctionCall(toFunction[operator], [left, right])}; - var peg$f14 = function(head, chained) {return chained}; - var peg$f15 = function(head, tail) { return tail.reduce(function(result, element) { - return makeFunctionCall(element.fnName, [result, ...element.args]) - }, head)}; - var peg$f16 = function(fn, args) { return {fnName: fn.value, args: args}}; - var peg$f17 = function(fn) { return {fnName: fn.value, args: []}}; - var peg$f18 = function(unaryOperator, right) { return makeFunctionCall(unaryToFunction[unaryOperator], [right])}; - var peg$f19 = function(head, arg) {return {fn: postOperatorToFunction['[]'], args: [arg]}}; - var peg$f20 = function(head, args) {return {fn: postOperatorToFunction['()'], args: args}}; - var peg$f21 = function(head, arg) {return {fn: postOperatorToFunction['[]'], args: [nodeString(arg)]}}; - var peg$f22 = function(head, tail) { return tail.reduce(function(result, element) { - return makeFunctionCall(element.fn, [result, ...element.args]) - }, head)}; - var peg$f23 = function(head, arg) {return {fn: postOperatorToFunction['.'], args: [nodeString(arg)]}}; - var peg$f24 = function(head, tail) { return tail.reduce(function(result, element) { - return makeFunctionCall(element.fn, [result, ...element.args]) - }, head)}; - var peg$f25 = function(expression) {return expression}; - var peg$f26 = function() {return nodeIdentifier(text())}; - var peg$f27 = function(characters) {return nodeString(characters.join(''))}; - var peg$f28 = function(number, unit) { - if (unit === null) - { return number } - else - { return makeFunctionCall('fromUnit_'+unit.value, [number]) - } - }; - var peg$f29 = function() { return nodeInteger(parseInt(text()))}; - var peg$f30 = function() { return nodeFloat(parseFloat(text()))}; - var peg$f31 = function() { return nodeBoolean(text() === 'true')}; - var peg$f32 = function(args, statements, finalExpression) { statements.push(finalExpression) - return nodeLambda(args, nodeBlock(statements)) }; - var peg$f33 = function(args, finalExpression) { return nodeLambda(args, nodeBlock([finalExpression])) }; - var peg$f34 = function() { return makeFunctionCall('$_constructArray_$', [nodeExpression([])])}; - var peg$f35 = function(args) { return makeFunctionCall('$_constructArray_$', [nodeExpression(args)])}; - var peg$f36 = function(args) { return makeFunctionCall('$_constructRecord_$', [nodeExpression(args)])}; - var peg$f37 = function(key, value) { return nodeKeyValue(key, value)}; - - var peg$currPos = 0; - var peg$savedPos = 0; - var peg$posDetailsCache = [{ line: 1, column: 1 }]; - var peg$maxFailPos = 0; - var peg$maxFailExpected = []; - var peg$silentFails = 0; - - var peg$resultsCache = {}; - - var peg$result; - - if ("startRule" in options) { - if (!(options.startRule in peg$startRuleFunctions)) { - throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); - } - - peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; - } - - function text() { - return input.substring(peg$savedPos, peg$currPos); - } - - function offset() { - return peg$savedPos; - } - - function range() { - return { - source: peg$source, - start: peg$savedPos, - end: peg$currPos - }; - } - - function location() { - return peg$computeLocation(peg$savedPos, peg$currPos); - } - - function expected(description, location) { - location = location !== undefined - ? location - : peg$computeLocation(peg$savedPos, peg$currPos); - - throw peg$buildStructuredError( - [peg$otherExpectation(description)], - input.substring(peg$savedPos, peg$currPos), - location - ); - } - - function error(message, location) { - location = location !== undefined - ? location - : peg$computeLocation(peg$savedPos, peg$currPos); - - throw peg$buildSimpleError(message, location); - } - - function peg$literalExpectation(text, ignoreCase) { - return { type: "literal", text: text, ignoreCase: ignoreCase }; - } - - function peg$classExpectation(parts, inverted, ignoreCase) { - return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; - } - - function peg$anyExpectation() { - return { type: "any" }; - } - - function peg$endExpectation() { - return { type: "end" }; - } - - function peg$otherExpectation(description) { - return { type: "other", description: description }; - } - - function peg$computePosDetails(pos) { - var details = peg$posDetailsCache[pos]; - var p; - - if (details) { - return details; - } else { - p = pos - 1; - while (!peg$posDetailsCache[p]) { - p--; - } - - details = peg$posDetailsCache[p]; - details = { - line: details.line, - column: details.column - }; - - while (p < pos) { - if (input.charCodeAt(p) === 10) { - details.line++; - details.column = 1; - } else { - details.column++; - } - - p++; - } - - peg$posDetailsCache[pos] = details; - - return details; - } - } - - function peg$computeLocation(startPos, endPos) { - var startPosDetails = peg$computePosDetails(startPos); - var endPosDetails = peg$computePosDetails(endPos); - - return { - source: peg$source, - start: { - offset: startPos, - line: startPosDetails.line, - column: startPosDetails.column - }, - end: { - offset: endPos, - line: endPosDetails.line, - column: endPosDetails.column - } - }; - } - - function peg$fail(expected) { - if (peg$currPos < peg$maxFailPos) { return; } - - if (peg$currPos > peg$maxFailPos) { - peg$maxFailPos = peg$currPos; - peg$maxFailExpected = []; - } - - peg$maxFailExpected.push(expected); - } - - function peg$buildSimpleError(message, location) { - return new peg$SyntaxError(message, null, null, location); - } - - function peg$buildStructuredError(expected, found, location) { - return new peg$SyntaxError( - peg$SyntaxError.buildMessage(expected, found), - expected, - found, - location - ); - } - - function peg$parsestart() { - var s0, s1, s2, s3, s4; - - var key = peg$currPos * 68 + 0; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parse_nl(); - s2 = peg$parseouterBlock(); - if (s2 !== peg$FAILED) { - s3 = peg$parse_nl(); - s4 = peg$parsefinalComment(); - if (s4 === peg$FAILED) { - s4 = null; - } - peg$savedPos = s0; - s0 = peg$f0(s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsezeroOMoreArgumentsBlockOrExpression() { - var s0; - - var key = peg$currPos * 68 + 1; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$parseinnerBlockOrExpression(); - if (s0 === peg$FAILED) { - s0 = peg$parselambda(); - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseouterBlock() { - var s0, s1, s2, s3, s4; - - var key = peg$currPos * 68 + 2; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsearray_statements(); - if (s1 !== peg$FAILED) { - s2 = peg$currPos; - s3 = peg$parsestatementSeparator(); - if (s3 !== peg$FAILED) { - s4 = peg$parseexpression(); - if (s4 !== peg$FAILED) { - s2 = s4; - } else { - peg$currPos = s2; - s2 = peg$FAILED; - } - } else { - peg$currPos = s2; - s2 = peg$FAILED; - } - if (s2 === peg$FAILED) { - s2 = null; - } - peg$savedPos = s0; - s0 = peg$f1(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parseexpression(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f2(s1); - } - s0 = s1; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseinnerBlockOrExpression() { - var s0, s1; - - var key = peg$currPos * 68 + 3; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$parsequotedInnerBlock(); - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parseexpression(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f2(s1); - } - s0 = s1; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsequotedInnerBlock() { - var s0, s1, s2, s3, s4, s5, s6; - - var key = peg$currPos * 68 + 4; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 123) { - s1 = peg$c0; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e0); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse_nl(); - s3 = peg$parsearray_statements(); - if (s3 !== peg$FAILED) { - s4 = peg$currPos; - s5 = peg$parsestatementSeparator(); - if (s5 !== peg$FAILED) { - s6 = peg$parseexpression(); - if (s6 !== peg$FAILED) { - s4 = s6; - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - if (s4 !== peg$FAILED) { - s5 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 125) { - s6 = peg$c1; - peg$currPos++; - } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } - } - if (s6 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f3(s3, s4); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 123) { - s1 = peg$c0; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e0); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse_nl(); - s3 = peg$parseexpression(); - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 125) { - s5 = peg$c1; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } - } - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f4(s3); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsearray_statements() { - var s0, s1, s2, s3, s4; - - var key = peg$currPos * 68 + 5; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsestatement(); - if (s1 !== peg$FAILED) { - s2 = peg$currPos; - s3 = peg$parsestatementSeparator(); - if (s3 !== peg$FAILED) { - s4 = peg$parsearray_statements(); - if (s4 !== peg$FAILED) { - s2 = s4; - } else { - peg$currPos = s2; - s2 = peg$FAILED; - } - } else { - peg$currPos = s2; - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f5(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parsestatement(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f6(s1); - } - s0 = s1; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsestatement() { - var s0; - - var key = peg$currPos * 68 + 6; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$parseletStatement(); - if (s0 === peg$FAILED) { - s0 = peg$parsedefunStatement(); - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseletStatement() { - var s0, s1, s2, s3, s4, s5; - - var key = peg$currPos * 68 + 7; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parseidentifier(); - if (s1 !== peg$FAILED) { - s2 = peg$parse_(); - s3 = peg$parseassignmentOp(); - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - s5 = peg$parsezeroOMoreArgumentsBlockOrExpression(); - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f7(s1, s5); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsedefunStatement() { - var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - - var key = peg$currPos * 68 + 8; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parseidentifier(); - if (s1 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 40) { - s2 = peg$c2; - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } - } - if (s2 !== peg$FAILED) { - s3 = peg$parse_nl(); - s4 = peg$parsearray_parameters(); - if (s4 !== peg$FAILED) { - s5 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 41) { - s6 = peg$c3; - peg$currPos++; - } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } - } - if (s6 !== peg$FAILED) { - s7 = peg$parse_(); - s8 = peg$parseassignmentOp(); - if (s8 !== peg$FAILED) { - s9 = peg$parse_nl(); - s10 = peg$parseinnerBlockOrExpression(); - if (s10 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f8(s1, s4, s10); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseassignmentOp() { - var s0, s1; - - var key = peg$currPos * 68 + 9; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (input.charCodeAt(peg$currPos) === 61) { - s0 = peg$c4; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e5); } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e4); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsearray_parameters() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 10; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsedollarIdentifier(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 44) { - s5 = peg$c5; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsedollarIdentifier(); - if (s7 !== peg$FAILED) { - s3 = s7; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 44) { - s5 = peg$c5; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsedollarIdentifier(); - if (s7 !== peg$FAILED) { - s3 = s7; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f9(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseexpression() { - var s0; - - var key = peg$currPos * 68 + 11; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$parseifthenelse(); - if (s0 === peg$FAILED) { - s0 = peg$parseternary(); - if (s0 === peg$FAILED) { - s0 = peg$parselogicalAdditive(); - } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseifthenelse() { - var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11; - - var key = peg$currPos * 68 + 12; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c6) { - s1 = peg$c6; - peg$currPos += 2; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e7); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__nl(); - if (s2 !== peg$FAILED) { - s3 = peg$parselogicalAdditive(); - if (s3 !== peg$FAILED) { - s4 = peg$parse__nl(); - if (s4 !== peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c7) { - s5 = peg$c7; - peg$currPos += 4; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e8); } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse__nl(); - if (s6 !== peg$FAILED) { - s7 = peg$parseinnerBlockOrExpression(); - if (s7 !== peg$FAILED) { - s8 = peg$parse__nl(); - if (s8 !== peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c8) { - s9 = peg$c8; - peg$currPos += 4; - } else { - s9 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e9); } - } - if (s9 !== peg$FAILED) { - s10 = peg$parse__nl(); - if (s10 !== peg$FAILED) { - s11 = peg$parseifthenelse(); - if (s11 === peg$FAILED) { - s11 = peg$parseinnerBlockOrExpression(); - } - if (s11 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f10(s3, s7, s11); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseternary() { - var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; - - var key = peg$currPos * 68 + 13; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parselogicalAdditive(); - if (s1 !== peg$FAILED) { - s2 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 63) { - s3 = peg$c9; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e10); } - } - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - s5 = peg$parselogicalAdditive(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 58) { - s7 = peg$c10; - peg$currPos++; - } else { - s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e11); } - } - if (s7 !== peg$FAILED) { - s8 = peg$parse_nl(); - s9 = peg$parseternary(); - if (s9 === peg$FAILED) { - s9 = peg$parselogicalAdditive(); - } - if (s9 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f10(s1, s5, s9); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parselogicalAdditive() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 14; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parselogicalMultiplicative(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse_(); - s5 = peg$parselogicalAdditiveOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parselogicalMultiplicative(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse_(); - s5 = peg$parselogicalAdditiveOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parselogicalMultiplicative(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f12(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parselogicalAdditiveOp() { - var s0, s1; - - var key = peg$currPos * 68 + 15; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (input.substr(peg$currPos, 2) === peg$c11) { - s0 = peg$c11; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - 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); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parselogicalMultiplicative() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 16; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parseequality(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse_(); - s5 = peg$parselogicalMultiplicativeOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parseequality(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse_(); - s5 = peg$parselogicalMultiplicativeOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parseequality(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f12(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parselogicalMultiplicativeOp() { - var s0, s1; - - var key = peg$currPos * 68 + 17; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (input.substr(peg$currPos, 2) === peg$c12) { - s0 = peg$c12; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseequality() { - var s0, s1, s2, s3, s4, s5; - - var key = peg$currPos * 68 + 18; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parserelational(); - if (s1 !== peg$FAILED) { - s2 = peg$parse_(); - s3 = peg$parseequalityOp(); - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - s5 = peg$parserelational(); - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f13(s1, s3, s5); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$parserelational(); - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseequalityOp() { - var s0, s1; - - var key = peg$currPos * 68 + 19; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (input.substr(peg$currPos, 2) === peg$c13) { - s0 = peg$c13; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c14) { - s0 = peg$c14; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e16); } - } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parserelational() { - var s0, s1, s2, s3, s4, s5; - - var key = peg$currPos * 68 + 20; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parseadditive(); - if (s1 !== peg$FAILED) { - s2 = peg$parse_(); - s3 = peg$parserelationalOp(); - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - s5 = peg$parseadditive(); - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f13(s1, s3, s5); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$parseadditive(); - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parserelationalOp() { - var s0, s1; - - var key = peg$currPos * 68 + 21; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (input.substr(peg$currPos, 2) === peg$c15) { - s0 = peg$c15; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e17); } - } - if (s0 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 60) { - s0 = peg$c16; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e18); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c17) { - s0 = peg$c17; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e19); } - } - if (s0 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 62) { - s0 = peg$c18; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e20); } - } - } - } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseadditive() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 22; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsemultiplicative(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse_(); - s5 = peg$parseadditiveOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsemultiplicative(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse_(); - s5 = peg$parseadditiveOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsemultiplicative(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f12(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseadditiveOp() { - var s0, s1; - - var key = peg$currPos * 68 + 23; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (input.charCodeAt(peg$currPos) === 43) { - s0 = peg$c19; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e21); } - } - if (s0 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 45) { - s0 = peg$c20; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c21) { - s0 = peg$c21; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e23); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c22) { - s0 = peg$c22; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } - } - } - } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsemultiplicative() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 24; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsepower(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse_(); - s5 = peg$parsemultiplicativeOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsepower(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse_(); - s5 = peg$parsemultiplicativeOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsepower(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f12(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsemultiplicativeOp() { - var s0, s1; - - var key = peg$currPos * 68 + 25; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (input.charCodeAt(peg$currPos) === 42) { - s0 = peg$c23; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e25); } - } - if (s0 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 47) { - s0 = peg$c24; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e26); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c25) { - s0 = peg$c25; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e27); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c26) { - s0 = peg$c26; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e28); } - } - } - } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsepower() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 26; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsecredibleInterval(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse_(); - s5 = peg$parsepowerOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsecredibleInterval(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse_(); - s5 = peg$parsepowerOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsecredibleInterval(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f12(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsepowerOp() { - var s0, s1; - - var key = peg$currPos * 68 + 27; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (input.charCodeAt(peg$currPos) === 94) { - s0 = peg$c27; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e29); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c28) { - s0 = peg$c28; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e30); } - } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsecredibleInterval() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 28; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsechainFunctionCall(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse__(); - if (s4 !== peg$FAILED) { - s5 = peg$parsecredibleIntervalOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse__nl(); - if (s6 !== peg$FAILED) { - s7 = peg$parsechainFunctionCall(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse__(); - if (s4 !== peg$FAILED) { - s5 = peg$parsecredibleIntervalOp(); - if (s5 !== peg$FAILED) { - s6 = peg$parse__nl(); - if (s6 !== peg$FAILED) { - s7 = peg$parsechainFunctionCall(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f12(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsecredibleIntervalOp() { - var s0, s1; - - var key = peg$currPos * 68 + 29; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (input.substr(peg$currPos, 2) === peg$c29) { - s0 = peg$c29; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e31); } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsechainFunctionCall() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 30; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parseunary(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse_(); - if (input.substr(peg$currPos, 2) === peg$c30) { - s5 = peg$c30; - peg$currPos += 2; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e32); } - } - if (s5 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c31) { - s5 = peg$c31; - peg$currPos += 2; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e33); } - } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsechainedFunction(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f14(s1, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse_(); - if (input.substr(peg$currPos, 2) === peg$c30) { - s5 = peg$c30; - peg$currPos += 2; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e32); } - } - if (s5 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c31) { - s5 = peg$c31; - peg$currPos += 2; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e33); } - } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsechainedFunction(); - if (s7 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f14(s1, s7); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f15(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsechainedFunction() { - var s0, s1, s2, s3, s4, s5, s6; - - var key = peg$currPos * 68 + 31; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsedollarIdentifier(); - if (s1 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 40) { - s2 = peg$c2; - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } - } - if (s2 !== peg$FAILED) { - s3 = peg$parse_nl(); - s4 = peg$parsearray_functionArguments(); - if (s4 !== peg$FAILED) { - s5 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 41) { - s6 = peg$c3; - peg$currPos++; - } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } - } - if (s6 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f16(s1, s4); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parsedollarIdentifier(); - if (s1 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 40) { - s2 = peg$c2; - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } - } - if (s2 !== peg$FAILED) { - s3 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 41) { - s4 = peg$c3; - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } - } - if (s4 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f17(s1); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parsedollarIdentifier(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f17(s1); - } - s0 = s1; - } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseunary() { - var s0, s1, s2, s3; - - var key = peg$currPos * 68 + 32; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parseunaryOperator(); - if (s1 !== peg$FAILED) { - s2 = peg$parse_nl(); - s3 = peg$parseunary(); - if (s3 === peg$FAILED) { - s3 = peg$parseindexedValue(); - } - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f18(s1, s3); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$parseindexedValue(); - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseunaryOperator() { - var s0, s1; - - var key = peg$currPos * 68 + 33; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (input.charCodeAt(peg$currPos) === 45) { - s0 = peg$c20; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c22) { - s0 = peg$c22; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } - } - if (s0 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 33) { - s0 = peg$c32; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e35); } - } - } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e34); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseindexedValue() { - var s0; - - var key = peg$currPos * 68 + 34; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$parsecollectionElement(); - if (s0 === peg$FAILED) { - s0 = peg$parserecordElement(); - if (s0 === peg$FAILED) { - s0 = peg$parseatom(); - } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsecollectionElement() { - var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - - var key = peg$currPos * 68 + 35; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parseatom(); - if (s1 !== peg$FAILED) { - s2 = peg$currPos; - peg$silentFails++; - if (input.charCodeAt(peg$currPos) === 91) { - s3 = peg$c33; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e36); } - } - if (s3 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 40) { - s3 = peg$c2; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } - } - if (s3 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 46) { - s3 = peg$c34; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } - } - } - } - peg$silentFails--; - if (s3 !== peg$FAILED) { - peg$currPos = s2; - s2 = undefined; - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - s3 = []; - s4 = peg$currPos; - s5 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 91) { - s6 = peg$c33; - peg$currPos++; - } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e36); } - } - if (s6 !== peg$FAILED) { - s7 = peg$parse_nl(); - s8 = peg$parseexpression(); - if (s8 !== peg$FAILED) { - s9 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 93) { - s10 = peg$c35; - peg$currPos++; - } else { - s10 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e38); } - } - if (s10 !== peg$FAILED) { - peg$savedPos = s4; - s4 = peg$f19(s1, s8); - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - if (s4 === peg$FAILED) { - s4 = peg$currPos; - s5 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 40) { - s6 = peg$c2; - peg$currPos++; - } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } - } - if (s6 !== peg$FAILED) { - s7 = peg$parse_nl(); - s8 = peg$parsearray_functionArguments(); - if (s8 !== peg$FAILED) { - s9 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 41) { - s10 = peg$c3; - peg$currPos++; - } else { - s10 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } - } - if (s10 !== peg$FAILED) { - peg$savedPos = s4; - s4 = peg$f20(s1, s8); - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - if (s4 === peg$FAILED) { - s4 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 46) { - s5 = peg$c34; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } - } - if (s5 !== peg$FAILED) { - s6 = peg$currPos; - s7 = peg$parsedollarIdentifier(); - if (s7 !== peg$FAILED) { - s6 = input.substring(s6, peg$currPos); - } else { - s6 = s7; - } - if (s6 !== peg$FAILED) { - peg$savedPos = s4; - s4 = peg$f21(s1, s6); - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } - } - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$currPos; - s5 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 91) { - s6 = peg$c33; - peg$currPos++; - } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e36); } - } - if (s6 !== peg$FAILED) { - s7 = peg$parse_nl(); - s8 = peg$parseexpression(); - if (s8 !== peg$FAILED) { - s9 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 93) { - s10 = peg$c35; - peg$currPos++; - } else { - s10 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e38); } - } - if (s10 !== peg$FAILED) { - peg$savedPos = s4; - s4 = peg$f19(s1, s8); - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - if (s4 === peg$FAILED) { - s4 = peg$currPos; - s5 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 40) { - s6 = peg$c2; - peg$currPos++; - } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } - } - if (s6 !== peg$FAILED) { - s7 = peg$parse_nl(); - s8 = peg$parsearray_functionArguments(); - if (s8 !== peg$FAILED) { - s9 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 41) { - s10 = peg$c3; - peg$currPos++; - } else { - s10 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } - } - if (s10 !== peg$FAILED) { - peg$savedPos = s4; - s4 = peg$f20(s1, s8); - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - if (s4 === peg$FAILED) { - s4 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 46) { - s5 = peg$c34; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } - } - if (s5 !== peg$FAILED) { - s6 = peg$currPos; - s7 = peg$parsedollarIdentifier(); - if (s7 !== peg$FAILED) { - s6 = input.substring(s6, peg$currPos); - } else { - s6 = s7; - } - if (s6 !== peg$FAILED) { - peg$savedPos = s4; - s4 = peg$f21(s1, s6); - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } - } - } - peg$savedPos = s0; - s0 = peg$f22(s1, s3); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsearray_functionArguments() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 36; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parseexpression(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 44) { - s5 = peg$c5; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parseexpression(); - if (s7 !== peg$FAILED) { - s3 = s7; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 44) { - s5 = peg$c5; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parseexpression(); - if (s7 !== peg$FAILED) { - s3 = s7; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f9(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parserecordElement() { - var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; - - var key = peg$currPos * 68 + 37; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsedollarIdentifier(); - if (s1 !== peg$FAILED) { - s2 = peg$currPos; - peg$silentFails++; - if (input.charCodeAt(peg$currPos) === 46) { - s3 = peg$c34; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } - } - peg$silentFails--; - if (s3 !== peg$FAILED) { - peg$currPos = s2; - s2 = undefined; - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - s3 = []; - s4 = peg$currPos; - s5 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 46) { - s6 = peg$c34; - peg$currPos++; - } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } - } - if (s6 !== peg$FAILED) { - s7 = peg$parse_nl(); - s8 = peg$currPos; - s9 = peg$parsedollarIdentifier(); - if (s9 !== peg$FAILED) { - s8 = input.substring(s8, peg$currPos); - } else { - s8 = s9; - } - if (s8 !== peg$FAILED) { - peg$savedPos = s4; - s4 = peg$f23(s1, s8); - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$currPos; - s5 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 46) { - s6 = peg$c34; - peg$currPos++; - } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } - } - if (s6 !== peg$FAILED) { - s7 = peg$parse_nl(); - s8 = peg$currPos; - s9 = peg$parsedollarIdentifier(); - if (s9 !== peg$FAILED) { - s8 = input.substring(s8, peg$currPos); - } else { - s8 = s9; - } - if (s8 !== peg$FAILED) { - peg$savedPos = s4; - s4 = peg$f23(s1, s8); - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } else { - peg$currPos = s4; - s4 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f24(s1, s3); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseatom() { - var s0, s1, s2, s3, s4, s5; - - var key = peg$currPos * 68 + 38; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 40) { - s1 = peg$c2; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse_nl(); - s3 = peg$parseexpression(); - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 41) { - s5 = peg$c3; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } - } - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f25(s3); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$parsebasicValue(); - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsebasicValue() { - var s0; - - var key = peg$currPos * 68 + 39; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$parsevalueConstructor(); - if (s0 === peg$FAILED) { - s0 = peg$parsebasicLiteral(); - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsebasicLiteral() { - var s0; - - var key = peg$currPos * 68 + 40; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$parsestring(); - if (s0 === peg$FAILED) { - s0 = peg$parsenumber(); - if (s0 === peg$FAILED) { - s0 = peg$parseboolean(); - if (s0 === peg$FAILED) { - s0 = peg$parsedollarIdentifier(); - } - } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseidentifier() { - var s0, s1, s2, s3, s4; - - var key = peg$currPos * 68 + 41; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - s1 = peg$currPos; - s2 = []; - if (peg$r0.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e40); } - } - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - if (peg$r0.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e40); } - } - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - s3 = []; - if (peg$r1.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e41); } - } - while (s4 !== peg$FAILED) { - s3.push(s4); - if (peg$r1.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e41); } - } - } - s2 = [s2, s3]; - s1 = s2; - } else { - peg$currPos = s1; - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f26(); - } - s0 = s1; - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e39); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsedollarIdentifier() { - var s0, s1, s2, s3, s4; - - var key = peg$currPos * 68 + 42; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - s1 = peg$currPos; - s2 = []; - if (peg$r2.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e43); } - } - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - if (peg$r2.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e43); } - } - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - s3 = []; - if (peg$r3.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e44); } - } - while (s4 !== peg$FAILED) { - s3.push(s4); - if (peg$r3.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e44); } - } - } - s2 = [s2, s3]; - s1 = s2; - } else { - peg$currPos = s1; - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f26(); - } - s0 = s1; - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e42); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsestring() { - var s0, s1, s2, s3, s4; - - var key = peg$currPos * 68 + 43; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - s1 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 39) { - s2 = peg$c36; - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e46); } - } - if (s2 !== peg$FAILED) { - s3 = []; - if (peg$r4.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e47); } - } - while (s4 !== peg$FAILED) { - s3.push(s4); - if (peg$r4.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e47); } - } - } - if (input.charCodeAt(peg$currPos) === 39) { - s4 = peg$c36; - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e46); } - } - if (s4 !== peg$FAILED) { - s1 = s3; - } else { - peg$currPos = s1; - s1 = peg$FAILED; - } - } else { - peg$currPos = s1; - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f27(s1); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 34) { - s2 = peg$c37; - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e48); } - } - if (s2 !== peg$FAILED) { - s3 = []; - if (peg$r5.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e49); } - } - while (s4 !== peg$FAILED) { - s3.push(s4); - if (peg$r5.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e49); } - } - } - if (input.charCodeAt(peg$currPos) === 34) { - s4 = peg$c37; - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e48); } - } - if (s4 !== peg$FAILED) { - s1 = s3; - } else { - peg$currPos = s1; - s1 = peg$FAILED; - } - } else { - peg$currPos = s1; - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f27(s1); - } - s0 = s1; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e45); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsenumber() { - var s0, s1, s2; - - var key = peg$currPos * 68 + 44; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsefloat(); - if (s1 === peg$FAILED) { - s1 = peg$parseinteger(); - } - if (s1 !== peg$FAILED) { - s2 = peg$parseidentifier(); - if (s2 === peg$FAILED) { - s2 = null; - } - peg$savedPos = s0; - s0 = peg$f28(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseinteger() { - var s0, s1, s2, s3, s4; - - var key = peg$currPos * 68 + 45; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - s1 = []; - s2 = peg$parsed(); - if (s2 !== peg$FAILED) { - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parsed(); - } - } else { - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - s2 = peg$currPos; - peg$silentFails++; - if (input.charCodeAt(peg$currPos) === 46) { - s3 = peg$c34; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } - } - peg$silentFails--; - if (s3 === peg$FAILED) { - s2 = undefined; - } else { - peg$currPos = s2; - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - s3 = peg$currPos; - peg$silentFails++; - if (peg$r6.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e51); } - } - peg$silentFails--; - if (s4 === peg$FAILED) { - s3 = undefined; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f29(); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e50); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsefloat() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 46; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - s1 = peg$currPos; - s2 = peg$currPos; - s3 = peg$currPos; - s4 = []; - s5 = peg$parsed(); - if (s5 !== peg$FAILED) { - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$parsed(); - } - } else { - s4 = peg$FAILED; - } - if (s4 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 46) { - s5 = peg$c34; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } - } - if (s5 !== peg$FAILED) { - s6 = []; - s7 = peg$parsed(); - while (s7 !== peg$FAILED) { - s6.push(s7); - s7 = peg$parsed(); - } - s4 = [s4, s5, s6]; - s3 = s4; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - if (s3 === peg$FAILED) { - s3 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 46) { - s4 = peg$c34; - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } - } - if (s4 !== peg$FAILED) { - s5 = []; - s6 = peg$parsed(); - if (s6 !== peg$FAILED) { - while (s6 !== peg$FAILED) { - s5.push(s6); - s6 = peg$parsed(); - } - } else { - s5 = peg$FAILED; - } - if (s5 !== peg$FAILED) { - s4 = [s4, s5]; - s3 = s4; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - if (s3 !== peg$FAILED) { - s4 = peg$parsefloatExponent(); - if (s4 === peg$FAILED) { - s4 = null; - } - s3 = [s3, s4]; - s2 = s3; - } else { - peg$currPos = s2; - s2 = peg$FAILED; - } - if (s2 === peg$FAILED) { - s2 = peg$currPos; - s3 = []; - s4 = peg$parsed(); - if (s4 !== peg$FAILED) { - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$parsed(); - } - } else { - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - s4 = peg$parsefloatExponent(); - if (s4 !== peg$FAILED) { - s3 = [s3, s4]; - s2 = s3; - } else { - peg$currPos = s2; - s2 = peg$FAILED; - } - } else { - peg$currPos = s2; - s2 = peg$FAILED; - } - } - if (s2 !== peg$FAILED) { - s1 = input.substring(s1, peg$currPos); - } else { - s1 = s2; - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f30(); - } - s0 = s1; - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e52); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsefloatExponent() { - var s0, s1, s2, s3, s4; - - var key = peg$currPos * 68 + 47; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - if (peg$r6.test(input.charAt(peg$currPos))) { - s1 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e51); } - } - if (s1 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 45) { - s2 = peg$c20; - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } - } - if (s2 === peg$FAILED) { - s2 = null; - } - s3 = []; - s4 = peg$parsed(); - if (s4 !== peg$FAILED) { - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$parsed(); - } - } else { - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - s1 = [s1, s2, s3]; - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsed() { - var s0; - - var key = peg$currPos * 68 + 48; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - if (peg$r7.test(input.charAt(peg$currPos))) { - s0 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e53); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parseboolean() { - var s0, s1; - - var key = peg$currPos * 68 + 49; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c38) { - s1 = peg$c38; - peg$currPos += 4; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e55); } - } - if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 5) === peg$c39) { - s1 = peg$c39; - peg$currPos += 5; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e56); } - } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f31(); - } - s0 = s1; - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e54); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsevalueConstructor() { - var s0; - - var key = peg$currPos * 68 + 50; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$parserecordConstructor(); - if (s0 === peg$FAILED) { - s0 = peg$parsearrayConstructor(); - if (s0 === peg$FAILED) { - s0 = peg$parselambda(); - if (s0 === peg$FAILED) { - s0 = peg$parsequotedInnerBlock(); - } - } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parselambda() { - var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12; - - var key = peg$currPos * 68 + 51; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 123) { - s1 = peg$c0; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e0); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 124) { - s3 = peg$c40; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e57); } - } - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - s5 = peg$parsearray_parameters(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 124) { - s7 = peg$c40; - peg$currPos++; - } else { - s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e57); } - } - if (s7 !== peg$FAILED) { - s8 = peg$parse_nl(); - s9 = peg$parsearray_statements(); - if (s9 !== peg$FAILED) { - s10 = peg$currPos; - s11 = peg$parsestatementSeparator(); - if (s11 !== peg$FAILED) { - s12 = peg$parseexpression(); - if (s12 !== peg$FAILED) { - s10 = s12; - } else { - peg$currPos = s10; - s10 = peg$FAILED; - } - } else { - peg$currPos = s10; - s10 = peg$FAILED; - } - if (s10 !== peg$FAILED) { - s11 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 125) { - s12 = peg$c1; - peg$currPos++; - } else { - s12 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } - } - if (s12 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f32(s5, s9, s10); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 123) { - s1 = peg$c0; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e0); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 124) { - s3 = peg$c40; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e57); } - } - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - s5 = peg$parsearray_parameters(); - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 124) { - s7 = peg$c40; - peg$currPos++; - } else { - s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e57); } - } - if (s7 !== peg$FAILED) { - s8 = peg$parse_nl(); - s9 = peg$parseexpression(); - if (s9 !== peg$FAILED) { - s10 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 125) { - s11 = peg$c1; - peg$currPos++; - } else { - s11 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } - } - if (s11 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f33(s5, s9); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsearrayConstructor() { - var s0, s1, s2, s3, s4, s5; - - var key = peg$currPos * 68 + 52; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 91) { - s1 = peg$c33; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e36); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 93) { - s3 = peg$c35; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e38); } - } - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f34(); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 91) { - s1 = peg$c33; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e36); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse_nl(); - s3 = peg$parsearray_elements(); - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 93) { - s5 = peg$c35; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e38); } - } - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f35(s3); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e58); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsearray_elements() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 53; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parseexpression(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 44) { - s5 = peg$c5; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parseexpression(); - if (s7 !== peg$FAILED) { - s3 = s7; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 44) { - s5 = peg$c5; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parseexpression(); - if (s7 !== peg$FAILED) { - s3 = s7; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f9(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parserecordConstructor() { - var s0, s1, s2, s3, s4, s5; - - var key = peg$currPos * 68 + 54; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 123) { - s1 = peg$c0; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e0); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse_nl(); - s3 = peg$parsearray_recordArguments(); - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - if (input.charCodeAt(peg$currPos) === 125) { - s5 = peg$c1; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } - } - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f36(s3); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e59); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsearray_recordArguments() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - var key = peg$currPos * 68 + 55; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsekeyValuePair(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 44) { - s5 = peg$c5; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsekeyValuePair(); - if (s7 !== peg$FAILED) { - s3 = s7; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 44) { - s5 = peg$c5; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } - } - if (s5 !== peg$FAILED) { - s6 = peg$parse_nl(); - s7 = peg$parsekeyValuePair(); - if (s7 !== peg$FAILED) { - s3 = s7; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - peg$savedPos = s0; - s0 = peg$f9(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsekeyValuePair() { - var s0, s1, s2, s3, s4, s5; - - var key = peg$currPos * 68 + 56; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parseexpression(); - if (s1 !== peg$FAILED) { - s2 = peg$parse_(); - if (input.charCodeAt(peg$currPos) === 58) { - s3 = peg$c10; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e11); } - } - if (s3 !== peg$FAILED) { - s4 = peg$parse_nl(); - s5 = peg$parseexpression(); - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f37(s1, s5); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parse_() { - var s0, s1; - - var key = peg$currPos * 68 + 57; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = []; - s1 = peg$parsewhiteSpaceCharactersOrComment(); - while (s1 !== peg$FAILED) { - s0.push(s1); - s1 = peg$parsewhiteSpaceCharactersOrComment(); - } - peg$silentFails--; - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e60); } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parse_nl() { - var s0, s1; - - var key = peg$currPos * 68 + 58; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = []; - s1 = peg$parsewhiteSpaceCharactersOrComment(); - if (s1 === peg$FAILED) { - s1 = peg$parsecommentOrNewLine(); - } - while (s1 !== peg$FAILED) { - s0.push(s1); - s1 = peg$parsewhiteSpaceCharactersOrComment(); - if (s1 === peg$FAILED) { - s1 = peg$parsecommentOrNewLine(); - } - } - peg$silentFails--; - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e61); } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parse__() { - var s0, s1; - - var key = peg$currPos * 68 + 59; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = []; - s1 = peg$parsewhiteSpaceCharactersOrComment(); - if (s1 !== peg$FAILED) { - while (s1 !== peg$FAILED) { - s0.push(s1); - s1 = peg$parsewhiteSpaceCharactersOrComment(); - } - } else { - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e60); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parse__nl() { - var s0, s1; - - var key = peg$currPos * 68 + 60; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = []; - s1 = peg$parsewhiteSpaceCharactersOrComment(); - if (s1 === peg$FAILED) { - s1 = peg$parsecommentOrNewLine(); - } - if (s1 !== peg$FAILED) { - while (s1 !== peg$FAILED) { - s0.push(s1); - s1 = peg$parsewhiteSpaceCharactersOrComment(); - if (s1 === peg$FAILED) { - s1 = peg$parsecommentOrNewLine(); - } - } - } else { - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e62); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsestatementSeparator() { - var s0, s1, s2, s3; - - var key = peg$currPos * 68 + 61; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - s1 = peg$parse_(); - s2 = []; - if (input.charCodeAt(peg$currPos) === 59) { - s3 = peg$c41; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e64); } - } - if (s3 === peg$FAILED) { - s3 = peg$parsecommentOrNewLine(); - } - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - if (input.charCodeAt(peg$currPos) === 59) { - s3 = peg$c41; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e64); } - } - if (s3 === peg$FAILED) { - s3 = peg$parsecommentOrNewLine(); - } - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - s3 = peg$parse_nl(); - s1 = [s1, s2, s3]; - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e63); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsecommentOrNewLine() { - var s0, s1, s2; - - var key = peg$currPos * 68 + 62; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$currPos; - s1 = peg$parsefinalComment(); - if (s1 === peg$FAILED) { - s1 = null; - } - s2 = peg$parsenewLine(); - if (s2 !== peg$FAILED) { - s1 = [s1, s2]; - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsefinalComment() { - var s0, s1, s2, s3, s4; - - var key = peg$currPos * 68 + 63; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - s1 = peg$parse_(); - if (input.substr(peg$currPos, 2) === peg$c42) { - s2 = peg$c42; - peg$currPos += 2; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e66); } - } - if (s2 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 35) { - s2 = peg$c43; - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e67); } - } - } - if (s2 !== peg$FAILED) { - s3 = []; - if (peg$r8.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e68); } - } - while (s4 !== peg$FAILED) { - s3.push(s4); - if (peg$r8.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e68); } - } - } - s0 = s3; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e65); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsewhiteSpaceCharactersOrComment() { - var s0; - - var key = peg$currPos * 68 + 64; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - s0 = peg$parsewhiteSpaceCharacters(); - if (s0 === peg$FAILED) { - s0 = peg$parsedelimitedComment(); - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsedelimitedComment() { - var s0, s1, s2, s3; - - var key = peg$currPos * 68 + 65; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c44) { - s1 = peg$c44; - peg$currPos += 2; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e70); } - } - if (s1 !== peg$FAILED) { - s2 = []; - if (peg$r9.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e71); } - } - while (s3 !== peg$FAILED) { - s2.push(s3); - if (peg$r9.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e71); } - } - } - if (input.substr(peg$currPos, 2) === peg$c45) { - s3 = peg$c45; - peg$currPos += 2; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e72); } - } - if (s3 !== peg$FAILED) { - s0 = s2; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e69); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsewhiteSpaceCharacters() { - var s0; - - var key = peg$currPos * 68 + 66; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - if (peg$r10.test(input.charAt(peg$currPos))) { - s0 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e73); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - function peg$parsenewLine() { - var s0, s1; - - var key = peg$currPos * 68 + 67; - var cached = peg$resultsCache[key]; - - if (cached) { - peg$currPos = cached.nextPos; - - return cached.result; - } - - peg$silentFails++; - if (peg$r11.test(input.charAt(peg$currPos))) { - s0 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e75); } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e74); } - } - - peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; - - return s0; - } - - peg$result = peg$startRuleFunction(); - - if (peg$result !== peg$FAILED && peg$currPos === input.length) { - return peg$result; - } else { - if (peg$result !== peg$FAILED && peg$currPos < input.length) { - peg$fail(peg$endExpectation()); - } - - throw peg$buildStructuredError( - peg$maxFailExpected, - peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, - peg$maxFailPos < input.length - ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) - : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) - ); - } -} - -module.exports = { - SyntaxError: peg$SyntaxError, - parse: peg$parse -}; From 8757448900527b1c4c0719394123eefca98ea46a Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 24 May 2022 14:28:02 -0400 Subject: [PATCH 12/14] Trying to appease the CI tests, which are failing here for some reason. --- .../rescript/ReducerInterface/ReducerInterface_DateTime.res | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res index 0fcd04e9..17ea5a75 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res @@ -4,8 +4,9 @@ type expressionValue = ExpressionValue.expressionValue let dateDispatch = (call: ExpressionValue.functionCall, _: DistributionOperation.env): option< result, > => { + open ExpressionValue switch call { - | ("toString", [EvDate(t)]) => ExpressionValue.EvString(DateTime.Date.toString(t))->Ok->Some + | ("toString", [EvDate(t)]) => EvString(DateTime.Date.toString(t))->Ok->Some | ("makeDateFromYear", [EvNumber(year)]) => switch DateTime.Date.makeFromYear(year) { | Ok(t) => EvDate(t)->Ok->Some From 628cb0c807a7944c850dfdd79dd37be6f98f5f70 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 24 May 2022 14:49:04 -0400 Subject: [PATCH 13/14] Minor additions to datetime units --- .../ReducerInterface/ReducerInterface_DateTime.res | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res index 17ea5a75..08c96309 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res @@ -4,13 +4,12 @@ type expressionValue = ExpressionValue.expressionValue let dateDispatch = (call: ExpressionValue.functionCall, _: DistributionOperation.env): option< result, > => { - open ExpressionValue switch call { | ("toString", [EvDate(t)]) => EvString(DateTime.Date.toString(t))->Ok->Some | ("makeDateFromYear", [EvNumber(year)]) => switch DateTime.Date.makeFromYear(year) { | Ok(t) => EvDate(t)->Ok->Some - | Error(e) => RETodo(e)->Error->Some + | Error(e) => Reducer_ErrorValue.RETodo(e)->Error->Some } | ("dateFromNumber", [EvNumber(f)]) => EvDate(DateTime.Date.fromFloat(f))->Ok->Some | ("toNumber", [EvDate(f)]) => EvNumber(DateTime.Date.toFloat(f))->Ok->Some @@ -31,10 +30,14 @@ let durationDispatch = (call: ExpressionValue.functionCall, _: DistributionOpera > => { switch call { | ("toString", [EvTimeDuration(t)]) => EvString(DateTime.Duration.toString(t))->Ok->Some - | ("hours", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some | ("minutes", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some + | ("fromUnit_minutes", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some + | ("hours", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some + | ("fromUnit_hours", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some | ("days", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some + | ("fromUnit_days", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some | ("years", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some + | ("fromUnit_years", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some | ("toHours", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toHours(f))->Ok->Some | ("toMinutes", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toMinutes(f))->Ok->Some | ("toDays", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toDays(f))->Ok->Some From f5fcd4f9ae6ab9f080d1dcc6547042642d871b31 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 24 May 2022 15:51:22 -0400 Subject: [PATCH 14/14] Added type to appease bisect --- .../ReducerInterface_DateTime.res | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res index 08c96309..fe30b0f8 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DateTime.res @@ -1,60 +1,62 @@ -module ExpressionValue = ReducerInterface_ExpressionValue -type expressionValue = ExpressionValue.expressionValue +module EV = ReducerInterface_ExpressionValue +type expressionValue = EV.expressionValue -let dateDispatch = (call: ExpressionValue.functionCall, _: DistributionOperation.env): option< +let dateDispatch = (call: EV.functionCall, _: DistributionOperation.env): option< result, > => { switch call { - | ("toString", [EvDate(t)]) => EvString(DateTime.Date.toString(t))->Ok->Some + | ("toString", [EvDate(t)]) => EV.EvString(DateTime.Date.toString(t))->Ok->Some | ("makeDateFromYear", [EvNumber(year)]) => switch DateTime.Date.makeFromYear(year) { - | Ok(t) => EvDate(t)->Ok->Some + | Ok(t) => EV.EvDate(t)->Ok->Some | Error(e) => Reducer_ErrorValue.RETodo(e)->Error->Some } - | ("dateFromNumber", [EvNumber(f)]) => EvDate(DateTime.Date.fromFloat(f))->Ok->Some - | ("toNumber", [EvDate(f)]) => EvNumber(DateTime.Date.toFloat(f))->Ok->Some + | ("dateFromNumber", [EvNumber(f)]) => EV.EvDate(DateTime.Date.fromFloat(f))->Ok->Some + | ("toNumber", [EvDate(f)]) => EV.EvNumber(DateTime.Date.toFloat(f))->Ok->Some | ("subtract", [EvDate(d1), EvDate(d2)]) => switch DateTime.Date.subtract(d1, d2) { - | Ok(d) => EvTimeDuration(d)->Ok + | Ok(d) => EV.EvTimeDuration(d)->Ok | Error(e) => Error(RETodo(e)) }->Some | ("subtract", [EvDate(d1), EvTimeDuration(d2)]) => - EvDate(DateTime.Date.subtractDuration(d1, d2))->Ok->Some - | ("add", [EvDate(d1), EvTimeDuration(d2)]) => EvDate(DateTime.Date.addDuration(d1, d2))->Ok->Some + EV.EvDate(DateTime.Date.subtractDuration(d1, d2))->Ok->Some + | ("add", [EvDate(d1), EvTimeDuration(d2)]) => + EV.EvDate(DateTime.Date.addDuration(d1, d2))->Ok->Some | _ => None } } -let durationDispatch = (call: ExpressionValue.functionCall, _: DistributionOperation.env): option< +let durationDispatch = (call: EV.functionCall, _: DistributionOperation.env): option< result, > => { switch call { - | ("toString", [EvTimeDuration(t)]) => EvString(DateTime.Duration.toString(t))->Ok->Some - | ("minutes", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some - | ("fromUnit_minutes", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some - | ("hours", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some - | ("fromUnit_hours", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some - | ("days", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some - | ("fromUnit_days", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some - | ("years", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some - | ("fromUnit_years", [EvNumber(f)]) => EvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some - | ("toHours", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toHours(f))->Ok->Some - | ("toMinutes", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toMinutes(f))->Ok->Some - | ("toDays", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toDays(f))->Ok->Some - | ("toYears", [EvTimeDuration(f)]) => EvNumber(DateTime.Duration.toYears(f))->Ok->Some + | ("toString", [EvTimeDuration(t)]) => EV.EvString(DateTime.Duration.toString(t))->Ok->Some + | ("minutes", [EvNumber(f)]) => EV.EvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some + | ("fromUnit_minutes", [EvNumber(f)]) => + EV.EvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some + | ("hours", [EvNumber(f)]) => EV.EvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some + | ("fromUnit_hours", [EvNumber(f)]) => EV.EvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some + | ("days", [EvNumber(f)]) => EV.EvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some + | ("fromUnit_days", [EvNumber(f)]) => EV.EvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some + | ("years", [EvNumber(f)]) => EV.EvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some + | ("fromUnit_years", [EvNumber(f)]) => EV.EvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some + | ("toHours", [EvTimeDuration(f)]) => EV.EvNumber(DateTime.Duration.toHours(f))->Ok->Some + | ("toMinutes", [EvTimeDuration(f)]) => EV.EvNumber(DateTime.Duration.toMinutes(f))->Ok->Some + | ("toDays", [EvTimeDuration(f)]) => EV.EvNumber(DateTime.Duration.toDays(f))->Ok->Some + | ("toYears", [EvTimeDuration(f)]) => EV.EvNumber(DateTime.Duration.toYears(f))->Ok->Some | ("add", [EvTimeDuration(d1), EvTimeDuration(d2)]) => - EvTimeDuration(DateTime.Duration.add(d1, d2))->Ok->Some + EV.EvTimeDuration(DateTime.Duration.add(d1, d2))->Ok->Some | ("subtract", [EvTimeDuration(d1), EvTimeDuration(d2)]) => - EvTimeDuration(DateTime.Duration.subtract(d1, d2))->Ok->Some + EV.EvTimeDuration(DateTime.Duration.subtract(d1, d2))->Ok->Some | ("multiply", [EvTimeDuration(d1), EvNumber(d2)]) => - EvTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some + EV.EvTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some | ("divide", [EvTimeDuration(d1), EvNumber(d2)]) => - EvTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some + EV.EvTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some | _ => None } } -let dispatch = (call: ExpressionValue.functionCall, env: DistributionOperation.env): option< +let dispatch = (call: EV.functionCall, env: DistributionOperation.env): option< result, > => { switch dateDispatch(call, env) {