From 0750d642624b2262afdb4dd17b275a16e96971b5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 20 Sep 2017 05:02:53 -0700 Subject: Updated all the code to work with the latest nomsu. --- lib/core.nom | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'lib') diff --git a/lib/core.nom b/lib/core.nom index c1bd663..f0cad0d 100644 --- a/lib/core.nom +++ b/lib/core.nom @@ -356,22 +356,19 @@ macro block [when %body] =: for %statement in (lua expr "vars.body.value.value"): %func-call =: lua expr "vars.statement.value" if ((lua expr "vars['func-call'].type") != "FunctionCall"): - error "Invalid format for 'when' statement" + error "Invalid format for 'when' statement. Only '?' blocks are allowed." %tokens =: lua expr "vars['func-call'].value" %q =: lua expr "vars.tokens[1]" if (((lua expr "vars.q.type") != "Word") or ((lua expr "vars.q.value") != "?")): - error "Invalid format for 'when' statement" + error "Invalid format for 'when' statement. Lines must begin with '?'" %thunk =: lua expr "vars.tokens[#vars.tokens]" if ((lua expr "vars.thunk.type") != "Thunk"): - error "Invalid format for 'when' statement" + error "Invalid format for 'when' statement. Lines must have a body." %condition_bits =: [] for %i in (2 up to (lua expr "#vars.tokens")): lua block "table.insert(vars['condition_bits'], vars.tokens[vars.i])" - %condition =: dict [..] - ["type",lua expr "vars['func-call'].type"] - ["src",lua expr "vars['func-call'].src"] - ["value", %condition_bits] - if ((lua expr "#vars.condition.value") == 0): + + if (lua expr "#vars.condition_bits == 0"): %result concat=: ".." | |do @@ -380,6 +377,13 @@ macro block [when %body] =: | return ret |end ..else: + if (lua expr "#vars.condition_bits == 1 and vars.condition_bits[1].type ~= 'Word'"): + %condition =: lua expr "vars.condition_bits[1]" + ..else: + %condition =: dict [..] + ["type",lua expr "vars['func-call'].type"] + ["src",lua expr "vars['func-call'].src"] + ["value", %condition_bits] %result concat=: ".." | |if \%condition as lua expr\ then @@ -387,6 +391,7 @@ macro block [when %body] =: | \(lua expr "vars.thunk.value") as lua block\ | return ret |end + %result # Switch statement @@ -395,14 +400,14 @@ macro block [when %branch-value %body] =: for %statement in (lua expr "vars.body.value.value"): %func-call =: lua expr "vars.statement.value" if ((lua expr "vars['func-call'].type") != "FunctionCall"): - error "Invalid format for 'when' statement" + error "Invalid format for 'when' statement. Only == blocks are allowed." %tokens =: lua expr "vars['func-call'].value" %eq =: lua expr "vars.tokens[1]" if (((lua expr "vars.eq.type") != "Word") or ((lua expr "vars.eq.value") != "==")): - error "Invalid format for 'when' statement" + error "Invalid format for 'when' statement. Lines must begin with '=='" %thunk =: lua expr "vars.tokens[#vars.tokens]" if ((lua expr "vars.thunk.type") != "Thunk"): - error "Invalid format for 'when' statement" + error "Invalid format for 'when' statement. Lines must have a body." %condition_bits =: [] for %i in (2 up to (lua expr "#vars.tokens")): lua block "table.insert(vars.condition_bits, vars.tokens[vars.i])" @@ -416,25 +421,19 @@ macro block [when %branch-value %body] =: |end ..else: if (lua expr "#vars.condition_bits == 1 and vars.condition_bits[1].type ~= 'Word'"): - %result concat=: ".." - | - |if compiler.utils.equivalent(branch_value, \(lua expr "vars.condition_bits[1]") as lua expr\) then - | local ret - | \(lua expr "vars.thunk.value") as lua block\ - | return ret - |end + %condition =: (lua expr "vars.condition_bits[1]") ..else: %condition =: dict [..] ["type",lua expr "vars['func-call'].type"] ["src",lua expr "vars['func-call'].src"] ["value", %condition_bits] - %result concat=: ".." - | - |if compiler.utils.equivalent(branch_value, \%condition as lua expr\) then - | local ret - | \(lua expr "vars.thunk.value") as lua block\ - | return ret - |end + %result concat=: ".." + | + |if compiler.utils.equivalent(branch_condition, \%condition as lua expr\) then + | local ret + | \(lua expr "vars.thunk.value") as lua block\ + | return ret + |end %result # List Comprehension -- cgit v1.2.3