From 2aa3a5ac484f592e76e3d2bb2ae571ad25325c9b Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Fri, 22 Apr 2022 00:02:27 +0200 Subject: [PATCH] format --- .../Reducer/Reducer_externalBindings_test.res | 51 +++++-------------- .../Reducer_Dispatch/Reducer_Dispatch.res | 2 +- .../Reducer_Expression/Reducer_Expression.res | 15 ++++-- .../Reducer_MathJs_ToExpression.res | 10 ++-- 4 files changed, 28 insertions(+), 50 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res index a1c78d8c..5fb7b9f5 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res @@ -2,55 +2,37 @@ open Jest open Reducer_TestHelpers describe("Parse for Bindings", () => { - testParseOuterToBe( - "x", - "Ok((:$$bindExpression (:$$bindings) :x))", - ) - testParseOuterToBe( - "x+1", - "Ok((:$$bindExpression (:$$bindings) (:add :x 1)))", - ) + testParseOuterToBe("x", "Ok((:$$bindExpression (:$$bindings) :x))") + testParseOuterToBe("x+1", "Ok((:$$bindExpression (:$$bindings) (:add :x 1)))") testParseOuterToBe( "y = x+1; y", "Ok((:$$bindExpression (:$$bindStatement (:$$bindings) (:$let :y (:add :x 1))) :y))", - ) + ) }) describe("Parse for Bindings", () => { testParsePartialToBe( "x", "Ok((:$$bindExpression (:$$bindStatement (:$$bindings) :x) (:$exportVariablesExpression)))", - ) + ) testParsePartialToBe( "y=x", "Ok((:$$bindExpression (:$$bindStatement (:$$bindings) (:$let :y :x)) (:$exportVariablesExpression)))", - ) + ) testParsePartialToBe( "y=x+1", "Ok((:$$bindExpression (:$$bindStatement (:$$bindings) (:$let :y (:add :x 1))) (:$exportVariablesExpression)))", - ) + ) testParsePartialToBe( "y = x+1; z = y", "Ok((:$$bindExpression (:$$bindStatement (:$$bindStatement (:$$bindings) (:$let :y (:add :x 1))) (:$let :z :y)) (:$exportVariablesExpression)))", - ) + ) }) describe("Eval with Bindings", () => { - testEvalBindingsToBe( - "x", - list{("x", ExpressionValue.EvNumber(1.))}, - "Ok(1)", - ) - testEvalBindingsToBe( - "x+1", - list{("x", ExpressionValue.EvNumber(1.))}, - "Ok(2)", - ) - testEvalBindingsToBe( - "y = x+1; y", - list{("x", ExpressionValue.EvNumber(1.))}, - "Ok(2)", - ) + testEvalBindingsToBe("x", list{("x", ExpressionValue.EvNumber(1.))}, "Ok(1)") + testEvalBindingsToBe("x+1", list{("x", ExpressionValue.EvNumber(1.))}, "Ok(2)") + testEvalBindingsToBe("y = x+1; y", list{("x", ExpressionValue.EvNumber(1.))}, "Ok(2)") }) /* @@ -63,21 +45,16 @@ Only.describe("Eval Partial", () => { "x", list{("x", ExpressionValue.EvNumber(1.))}, "Error(Assignment expected)", - ) - testEvalPartialBindingsToBe( - "y=x", - list{("x", ExpressionValue.EvNumber(1.))}, - "Ok({x: 1, y: 1})", - ) + ) + testEvalPartialBindingsToBe("y=x", list{("x", ExpressionValue.EvNumber(1.))}, "Ok({x: 1, y: 1})") testEvalPartialBindingsToBe( "y=x+1", list{("x", ExpressionValue.EvNumber(1.))}, "Ok({x: 1, y: 2})", - ) + ) MyOnly.testEvalPartialBindingsToBe( "y = x+1; z = y", list{("x", ExpressionValue.EvNumber(1.))}, "Ok({x: 1, y: 2, z: 2})", - ) + ) }) - diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch.res index ac74f121..83d3eca2 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch.res @@ -1,2 +1,2 @@ module Builtin = Reducer_Dispatch_BuiltIn -module BuiltinMacros = Reducer_Dispatch_BuiltInMacros \ No newline at end of file +module BuiltinMacros = Reducer_Dispatch_BuiltInMacros diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res index c47ee191..627588d2 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res @@ -161,7 +161,7 @@ let externalBindingsToBindings = (externalBindings: externalBindings): T.binding Evaluates code with external bindings. External bindings are a record of expression values. */ let evalWBindings = (code: string, externalBindings: externalBindings) => { - let bindings = externalBindings -> externalBindingsToBindings + let bindings = externalBindings->externalBindingsToBindings evalOuterWBindings_(code, bindings) } @@ -169,11 +169,16 @@ let evalWBindings = (code: string, externalBindings: externalBindings) => { Evaluates code with external bindings. External bindings are a record of expression values. The code is a partial code as if it is cut from a larger code. Therefore all statments are assignments. */ -let evalPartialWBindings = (code: string, externalBindings: externalBindings): result => { - let bindings = externalBindings -> externalBindingsToBindings +let evalPartialWBindings = (code: string, externalBindings: externalBindings): result< + externalBindings, + 'e, +> => { + let bindings = externalBindings->externalBindingsToBindings let answer = evalPartialWBindings_(code, bindings) - answer->Result.flatMap(answer => switch answer { + answer->Result.flatMap(answer => + switch answer { | EvRecord(aRecord) => Ok(aRecord) | _ => RETodo("TODO: External bindings must be returned")->Error - }) + } + ) } diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_MathJs/Reducer_MathJs_ToExpression.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_MathJs/Reducer_MathJs_ToExpression.res index c05fb6c2..a8b7b39a 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_MathJs/Reducer_MathJs_ToExpression.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_MathJs/Reducer_MathJs_ToExpression.res @@ -155,17 +155,13 @@ let fromPartialNode = (mathJsNode: Parse.node): result = Parse.castNodeType(mathJsNode)->Result.flatMap(typedMathJsNode => { let casePartialBlockNode = (bNode: Parse.blockNode) => { let blocksOrTags = bNode["blocks"]->Belt.Array.map(toTagOrNode) - let completed = Js.Array2.concat( - blocksOrTags, - [BlockTag(ExportVariablesExpression)] - ) + let completed = Js.Array2.concat(blocksOrTags, [BlockTag(ExportVariablesExpression)]) completed->caseTagOrNodes } let casePartialExpression = (node: Parse.node) => { - let completed = - [BlockNode(node), BlockTag(ExportVariablesExpression)] - + let completed = [BlockNode(node), BlockTag(ExportVariablesExpression)] + completed->caseTagOrNodes }