aboutsummaryrefslogtreecommitdiff
path: root/lib/control_flow.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-08 18:53:57 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-08 18:53:57 -0800
commitf97ab858edae5495f8ebfef46656e86150665888 (patch)
treeed47620eba2365192ba54950647d6307223cac29 /lib/control_flow.nom
parent568a44ef191e1f4072d379700e3b6f599150a92b (diff)
Modernized the codebase a bit to include "immediately:" for immediately
running code before further parsing takes place. That means that in the default case, whole files can be run at once, which makes all but the weirdest edge cases make a lot more sense and operate smoothly.
Diffstat (limited to 'lib/control_flow.nom')
-rw-r--r--lib/control_flow.nom40
1 files changed, 22 insertions, 18 deletions
diff --git a/lib/control_flow.nom b/lib/control_flow.nom
index 33f72ab..5169ac2 100644
--- a/lib/control_flow.nom
+++ b/lib/control_flow.nom
@@ -43,7 +43,7 @@ rule [tree %tree has function call %call] =:
return true;
end
end
- do return false; end
+ return false;
# While loops
compile [do next repeat-loop] to code: "goto continue_repeat;"
@@ -100,12 +100,14 @@ compile [..]
%stop_labels join= "\n::stop_for::;"
if (tree %body has function call (tree \(stop %) with {""=%var})):
%stop_labels join= "\n::stop_\(nomsu "var_to_lua_identifier" [%var])::;"
- if (%stop_labels != ""): ".."
- do --for-loop label scope
- \%code\
- ..\%stop_labels
- end --for-loop label scope
- ..else: %code
+ return (..)
+ ".."
+ do --for-loop label scope
+ \%code\
+ ..\%stop_labels
+ end --for-loop label scope
+ ..if %stop_labels != "" else %code
+
parse [for %var from %start to %stop %body] as: for %var from %start to %stop via 1 %body
parse [..]
for all %start to %stop by %step %body
@@ -131,11 +133,12 @@ compile [for %var in %iterable %body] to code:
%stop_labels join= "\n::stop_for::;"
if (tree %body has function call (tree \(stop %) with {""=%var})):
%stop_labels join= "\n::stop_\(nomsu "var_to_lua_identifier" [%var])::;"
- if (%stop_labels != ""): ".."
- do --for-loop label scope
- \%code\%stop_labels
- end --for-loop label scope
- ..else: %code
+ return (..)
+ ".."
+ do --for-loop label scope
+ \%code\%stop_labels
+ end --for-loop label scope
+ ..if %stop_labels != "" else %code
parse [for all %iterable %body] as: for % in %iterable %body
# Dict iteration (lua's "pairs()")
@@ -161,12 +164,13 @@ compile [for %key = %value in %iterable %body] to code:
%stop_labels join= "\n::stop_\(nomsu "var_to_lua_identifier" [%key])::;"
if (tree %body has function call (tree \(stop %) with {""=%value})):
%stop_labels join= "\n::stop_\(nomsu "var_to_lua_identifier" [%value])::;"
- if (%stop_labels != ""): ".."
- do --for-loop label scope
- \%code\
- ..\%stop_labels
- end --for-loop label scope
- ..else: %code
+ return (..)
+ ".."
+ do --for-loop label scope
+ \%code\
+ ..\%stop_labels
+ end --for-loop label scope
+ ..if %stop_labels != "" else %code
# Switch statement/multi-branch if
compile [when %body] to code: