diff --git a/lib/std b/lib/std index 4f2e195e..87a9c371 160000 --- a/lib/std +++ b/lib/std @@ -1 +1 @@ -Subproject commit 4f2e195e72c1adb13d06d0a817e3a03dea903d6f +Subproject commit 87a9c371b39390036d6165646edd244f367ba922 diff --git a/src/arkscript/Formatter.cpp b/src/arkscript/Formatter.cpp index 8a2d4524..4b863803 100644 --- a/src/arkscript/Formatter.cpp +++ b/src/arkscript/Formatter.cpp @@ -359,7 +359,7 @@ std::string Formatter::formatCondition(const Node& node, const std::size_t inden const Node then_node = node.constList()[2]; bool cond_on_newline = false; - std::string formatted_cond = format(cond_node, indent + 1, false); + const std::string formatted_cond = format(cond_node, indent + 1, false); if (formatted_cond.find('\n') != std::string::npos) cond_on_newline = true; @@ -367,7 +367,7 @@ std::string Formatter::formatCondition(const Node& node, const std::size_t inden "({}if{}{}", is_macro ? "$" : "", cond_on_newline ? "\n" : " ", - formatted_cond); + cond_on_newline ? format(cond_node, indent + 1, true) : formatted_cond); const bool split_then_newline = shouldSplitOnNewline(then_node) || isBeginBlock(then_node); diff --git a/tests/unittests/resources/FormatterSuite/codeSamples/permutations.ark b/tests/unittests/resources/FormatterSuite/codeSamples/permutations.ark new file mode 100644 index 00000000..364fcfee --- /dev/null +++ b/tests/unittests/resources/FormatterSuite/codeSamples/permutations.ark @@ -0,0 +1,26 @@ +(let permutations (fun ((ref _L) _r _f) { + (let _len (len _L)) + (if (and (<= _r _len) (> _r 0)) + { + (mut _indices (iota 0 _r)) + (if (!= stopIteration (_f (select _L _indices))) + { + (mut _continue true) + (let _reversed_indices (reverse _indices)) + (while _continue { + (mut _i nil) + (if + (forEach + _reversed_indices + (fun (_val) { + (set _i _val) + (if (!= (@ _indices _i) (+ _i _len (* -1 _r))) stopIteration) })) + { + (@= _indices _i (+ 1 (@ _indices _i))) + (mut _j (+ 1 _i)) + (while (< _j _r) { + (@= _indices _j (+ 1 (@ _indices (- _j 1)))) + (set _j (+ 1 _j)) }) + (if (= stopIteration (_f (select _L _indices))) + (set _continue false)) } + (set _continue false)) }) }) }) })) diff --git a/tests/unittests/resources/FormatterSuite/codeSamples/permutations.expected b/tests/unittests/resources/FormatterSuite/codeSamples/permutations.expected new file mode 100644 index 00000000..364fcfee --- /dev/null +++ b/tests/unittests/resources/FormatterSuite/codeSamples/permutations.expected @@ -0,0 +1,26 @@ +(let permutations (fun ((ref _L) _r _f) { + (let _len (len _L)) + (if (and (<= _r _len) (> _r 0)) + { + (mut _indices (iota 0 _r)) + (if (!= stopIteration (_f (select _L _indices))) + { + (mut _continue true) + (let _reversed_indices (reverse _indices)) + (while _continue { + (mut _i nil) + (if + (forEach + _reversed_indices + (fun (_val) { + (set _i _val) + (if (!= (@ _indices _i) (+ _i _len (* -1 _r))) stopIteration) })) + { + (@= _indices _i (+ 1 (@ _indices _i))) + (mut _j (+ 1 _i)) + (while (< _j _r) { + (@= _indices _j (+ 1 (@ _indices (- _j 1)))) + (set _j (+ 1 _j)) }) + (if (= stopIteration (_f (select _L _indices))) + (set _continue false)) } + (set _continue false)) }) }) }) })) diff --git a/tools/ark_format b/tools/ark_format new file mode 100755 index 00000000..1e418ef7 --- /dev/null +++ b/tools/ark_format @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +for f in *.ark; do + arkscript -f "$f" + if [[ $? == 1 ]]; then + echo "Formatted $f" + fi +done + +echo "All files in $(pwd) are correctly formatted!"