multi-line tests

This commit is contained in:
Umur Ozkul 2022-05-19 18:19:09 +02:00
parent 638548c37b
commit c496ae5cdd
3 changed files with 39 additions and 107 deletions

View File

@ -224,11 +224,37 @@ describe("parsing new line", ()=>{
y=2 y=2
y } y }
x`, "{:x = {:y = {2}; :y}; :x}") x`, "{:x = {:y = {2}; :y}; :x}")
MySkip.testParse(` testParse(`
x={ x={
y=2 y=2
y 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)}")
}) })

View File

@ -676,7 +676,7 @@ function peg$parse(input, options) {
} }
function peg$parseinnerBlockOrExpression() { function peg$parseinnerBlockOrExpression() {
var s0, s1, s2, s3, s4, s5, s6; var s0, s1;
var key = peg$currPos * 56 + 3; var key = peg$currPos * 56 + 3;
var cached = peg$resultsCache[key]; var cached = peg$resultsCache[key];
@ -687,105 +687,15 @@ function peg$parse(input, options) {
return cached.result; return cached.result;
} }
s0 = peg$currPos; s0 = peg$parsequotedInnerBlock();
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;
}
if (s0 === peg$FAILED) { if (s0 === peg$FAILED) {
s0 = peg$currPos; s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 123) { s1 = peg$parseexpression();
s1 = peg$c0;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e0); }
}
if (s1 !== peg$FAILED) { if (s1 !== peg$FAILED) {
s2 = peg$parse_nl(); peg$savedPos = s0;
s3 = peg$parseexpression(); s1 = peg$f2(s1);
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;
} }
s0 = s1;
} }
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -832,7 +742,7 @@ function peg$parse(input, options) {
s4 = peg$FAILED; s4 = peg$FAILED;
} }
if (s4 !== peg$FAILED) { if (s4 !== peg$FAILED) {
s5 = peg$parse_(); s5 = peg$parse_nl();
if (input.charCodeAt(peg$currPos) === 125) { if (input.charCodeAt(peg$currPos) === 125) {
s6 = peg$c1; s6 = peg$c1;
peg$currPos++; peg$currPos++;
@ -872,7 +782,7 @@ function peg$parse(input, options) {
s2 = peg$parse_nl(); s2 = peg$parse_nl();
s3 = peg$parseexpression(); s3 = peg$parseexpression();
if (s3 !== peg$FAILED) { if (s3 !== peg$FAILED) {
s4 = peg$parse_(); s4 = peg$parse_nl();
if (input.charCodeAt(peg$currPos) === 125) { if (input.charCodeAt(peg$currPos) === 125) {
s5 = peg$c1; s5 = peg$c1;
peg$currPos++; peg$currPos++;

View File

@ -76,19 +76,15 @@ outerBlock
{ return nodeBlock([finalExpression])} { return nodeBlock([finalExpression])}
innerBlockOrExpression innerBlockOrExpression
= '{' _nl statements:array_statements finalExpression: (statementSeparator @expression) _ '}' = quotedInnerBlock
{ statements.push(finalExpression)
return nodeBlock(statements) }
/ '{' _nl finalExpression: expression _ '}'
{ return nodeBlock([finalExpression]) }
/ finalExpression: expression / finalExpression: expression
{ return nodeBlock([finalExpression])} { return nodeBlock([finalExpression])}
quotedInnerBlock quotedInnerBlock
= '{' _nl statements:array_statements finalExpression: (statementSeparator @expression) _ '}' = '{' _nl statements:array_statements finalExpression: (statementSeparator @expression) _nl '}'
{ statements.push(finalExpression) { statements.push(finalExpression)
return nodeBlock(statements) } return nodeBlock(statements) }
/ '{' _nl finalExpression: expression _ '}' / '{' _nl finalExpression: expression _nl '}'
{ return nodeBlock([finalExpression]) } { return nodeBlock([finalExpression]) }
array_statements array_statements