From 54cbcea5d6b196562a21fc34e611c819463bb8a5 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 3 Oct 2022 16:16:00 +0200 Subject: [PATCH 1/2] to operator priority higher than logical operators, lower than all other operators --- .../Reducer_Peggy_GeneratedParser.peggy | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 4d8cc135..5f0a5a25 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 @@ -98,12 +98,20 @@ equality equalityOp "operator" = '=='/'!=' relational - = left:additive _ operator:relationalOp _nl right:additive + = left:credibleInterval _ operator:relationalOp _nl right:credibleInterval { return h.makeFunctionCall(h.toFunction[operator], [left, right])} - / additive + / credibleInterval relationalOp "operator" = '<='/'<'/'>='/'>' +credibleInterval + = head:additive tail:(__ operator:credibleIntervalOp __nl arg:additive {return {operator: operator, right: arg}})* + { return tail.reduce(function(result, element) { + return h.makeFunctionCall(h.toFunction[element.operator], [result, element.right]) + }, head)} + + credibleIntervalOp "operator" = 'to' + additive = head:multiplicative tail:(_ operator:additiveOp _nl arg:multiplicative {return {operator: operator, right: arg}})* { return tail.reduce(function(result, element) { @@ -121,21 +129,13 @@ multiplicative multiplicativeOp "operator" = '*' / '/' / '.*' / './' power - = head:credibleInterval tail:(_ operator:powerOp _nl arg:credibleInterval {return {operator: operator, right: arg}})* + = head:chainFunctionCall tail:(_ operator:powerOp _nl arg:chainFunctionCall {return {operator: operator, right: arg}})* { return tail.reduce(function(result, element) { return h.makeFunctionCall(h.toFunction[element.operator], [result, element.right]) }, head)} powerOp "operator" = '^' / '.^' -credibleInterval - = head:chainFunctionCall tail:(__ operator:credibleIntervalOp __nl arg:chainFunctionCall {return {operator: operator, right: arg}})* - { return tail.reduce(function(result, element) { - return h.makeFunctionCall(h.toFunction[element.operator], [result, element.right]) - }, head)} - - credibleIntervalOp "operator" = 'to' - chainFunctionCall = head:unary tail:(_ ('->'/'|>') _nl chained:chainedFunction {return chained})* { return tail.reduce(function(result, element) { From 39cc4a32ca74abc152d782a8dc7d25f3c8841511 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Tue, 4 Oct 2022 13:04:57 +0200 Subject: [PATCH 2/2] to operator priority test --- .../Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6c60c187..be6444fd 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 @@ -182,7 +182,7 @@ describe("Peggy parse", () => { "a.p1 to a.p2", "{(:credibleIntervalToDistribution (:$_atIndex_$ :a 'p1') (:$_atIndex_$ :a 'p2'))}", ) // lower than post - testParse("1 to 2 + 3", "{(:add (:credibleIntervalToDistribution 1 2) 3)}") // higher than binary operators + testParse("1 to 2 + 3", "{(:credibleIntervalToDistribution 1 (:add 2 3))}") testParse( "1->add(2) to 3->add(4) -> add(4)", "{(:credibleIntervalToDistribution (:add 1 2) (:add (:add 3 4) 4))}",