From c496ae5cddbc2fe50a526a9d55c9957b851cdfeb Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Thu, 19 May 2022 18:19:09 +0200 Subject: [PATCH] multi-line tests --- .../Reducer_Peggy_Parse_test.res | 30 ++++- .../Reducer_Peggy_GeneratedParser.js | 106 ++---------------- .../Reducer_Peggy_GeneratedParser.pegjs | 10 +- 3 files changed, 39 insertions(+), 107 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 dea5e98d..6422882d 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 @@ -224,11 +224,37 @@ describe("parsing new line", ()=>{ y=2 y } x`, "{:x = {:y = {2}; :y}; :x}") - MySkip.testParse(` + testParse(` x={ y=2 y } - x`, "{:x = {:y = {2}; :y}; :x}") //FIXME: Bracket after new line is not parsed + x`, "{:x = {:y = {2}; :y}; :x}") + testParse(` + x=1 + y=2 + z=3 + `, "{:x = {1}; :y = {2}; :z = {3}}") + testParse(` + f={ + x=1 + y=2 + z=3 + x+y+z + } + `, "{:f = {:x = {1}; :y = {2}; :z = {3}; (::add (::add :x :y) :z)}}") + testParse(` + a |> + b |> + c |> + d + `, "{(::d (::c (::b :a)))}") + testParse(` + a |> + b |> + c |> + d + + e + `, "{(::add (::d (::c (::b :a))) :e)}") }) 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 54367909..e6d5d0f6 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 @@ -676,7 +676,7 @@ function peg$parse(input, options) { } function peg$parseinnerBlockOrExpression() { - var s0, s1, s2, s3, s4, s5, s6; + var s0, s1; var key = peg$currPos * 56 + 3; var cached = peg$resultsCache[key]; @@ -687,105 +687,15 @@ function peg$parse(input, options) { 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_(); - 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; - } + s0 = peg$parsequotedInnerBlock(); 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); } - } + s1 = peg$parseexpression(); if (s1 !== peg$FAILED) { - s2 = peg$parse_nl(); - s3 = peg$parseexpression(); - if (s3 !== peg$FAILED) { - s4 = peg$parse_(); - 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; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parseexpression(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f2(s1); - } - s0 = s1; + peg$savedPos = s0; + s1 = peg$f2(s1); } + s0 = s1; } peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; @@ -832,7 +742,7 @@ function peg$parse(input, options) { s4 = peg$FAILED; } if (s4 !== peg$FAILED) { - s5 = peg$parse_(); + s5 = peg$parse_nl(); if (input.charCodeAt(peg$currPos) === 125) { s6 = peg$c1; peg$currPos++; @@ -872,7 +782,7 @@ function peg$parse(input, options) { s2 = peg$parse_nl(); s3 = peg$parseexpression(); if (s3 !== peg$FAILED) { - s4 = peg$parse_(); + s4 = peg$parse_nl(); if (input.charCodeAt(peg$currPos) === 125) { s5 = peg$c1; peg$currPos++; diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.pegjs b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.pegjs index 5ad59be8..07a04191 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.pegjs +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.pegjs @@ -76,19 +76,15 @@ outerBlock { return nodeBlock([finalExpression])} innerBlockOrExpression - = '{' _nl statements:array_statements finalExpression: (statementSeparator @expression) _ '}' - { statements.push(finalExpression) - return nodeBlock(statements) } - / '{' _nl finalExpression: expression _ '}' - { return nodeBlock([finalExpression]) } + = quotedInnerBlock / finalExpression: expression { return nodeBlock([finalExpression])} quotedInnerBlock - = '{' _nl statements:array_statements finalExpression: (statementSeparator @expression) _ '}' + = '{' _nl statements:array_statements finalExpression: (statementSeparator @expression) _nl '}' { statements.push(finalExpression) return nodeBlock(statements) } - / '{' _nl finalExpression: expression _ '}' + / '{' _nl finalExpression: expression _nl '}' { return nodeBlock([finalExpression]) } array_statements