From 5f2db8da0e99fca282265b232330f3f432b94373 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 21 Sep 2017 02:33:04 -0700 Subject: Everything fixed up and some reduced lua codespew too! --- lib/utils.nom | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'lib/utils.nom') diff --git a/lib/utils.nom b/lib/utils.nom index 57b8dfc..ec35c15 100644 --- a/lib/utils.nom +++ b/lib/utils.nom @@ -6,16 +6,16 @@ rule [error!, panic!, fail!, abort!] =: rule [error %msg] =: compiler "error"[%msg] macro block [assert %condition] =: ".." - |if not (\%condition as lua expr\) then + |if not (\%condition as lua\) then | compiler:error() |end macro block [assert %condition %msg] =: ".." - |if not (\%condition as lua expr\) then - | compiler:error(\%msg as lua expr\) + |if not (\%condition as lua\) then + | compiler:error(\%msg as lua\) |end macro block [show generated lua %block] =: ".." - |compiler:writeln(\lua expr "compiler.utils.repr(compiler:tree_to_lua(vars.block.value, 'Statement'))"\) + |compiler:writeln(\lua expr "compiler.utils.repr(compiler:tree_to_lua(vars.block.value))"\) # String functions @@ -32,54 +32,54 @@ rule [join %strs with glue %glue] =: |return table.concat(str_bits, vars.glue) macro [capitalize %str, %str capitalized] =: ".." - |(\%str as lua expr\):gsub("%l", string.upper, 1) + |(\%str as lua\):gsub("%l", string.upper, 1) macro [repr %obj] =: - ".."|compiler.utils.repr(\%obj as lua expr\) + ".."|compiler.utils.repr(\%obj as lua\) macro [%obj as string] =: - ".."|compiler.utils.repr_if_not_string(\%obj as lua expr\) + ".."|compiler.utils.repr_if_not_string(\%obj as lua\) macro [say %str] =: - ".."|compiler:writeln(compiler.utils.repr_if_not_string(\%str as lua expr\)) + ".."|compiler:writeln(compiler.utils.repr_if_not_string(\%str as lua\)) # Number ranges macro [%start up to %stop] =: ".." - |compiler.utils.range(\%start as lua expr\, \%stop as lua expr\-1) + |compiler.utils.range(\%start as lua\, \%stop as lua\-1) macro [%start thru %stop, %start through %stop] =: ".." - |compiler.utils.range(\%start as lua expr\, \%stop as lua expr\) + |compiler.utils.range(\%start as lua\, \%stop as lua\) macro [%start down to %stop] =: ".." - |compiler.utils.range(\%start as lua expr\, \%stop as lua expr\+1,-1) + |compiler.utils.range(\%start as lua\, \%stop as lua\+1,-1) macro [%start down thru %stop, %start down through %stop] =: ".." - |compiler.utils.range(\%start as lua expr\, \%stop as lua expr\,-1) + |compiler.utils.range(\%start as lua\, \%stop as lua\,-1) macro [%start up to %stop via %step] =: ".." - |compiler.utils.range(\%start as lua expr\,\%stop as lua expr\-1,vars.step) + |compiler.utils.range(\%start as lua\,\%stop as lua\-1,vars.step) macro [%start thru %stop via %step, %start through %stop via %step] =: ".." - |compiler.utils.range(\%start as lua expr\,\%stop as lua expr\,vars.step) + |compiler.utils.range(\%start as lua\,\%stop as lua\,vars.step) macro [%start down to %stop via %step] =: ".." - |compiler.utils.range(\%start as lua expr\,\%stop as lua expr\+1,-vars.step) + |compiler.utils.range(\%start as lua\,\%stop as lua\+1,-vars.step) macro [%start down thru %stop via %step, %start down through %stop via %step] =: ".." - |compiler.utils.range(\%start as lua expr\,\%stop as lua expr\,-vars.step) + |compiler.utils.range(\%start as lua\,\%stop as lua\,-vars.step) # Common utility functions macro [random number, random, rand] =: "math.random()" -macro [random int %n, random integer %n, randint %n] =: ".."|math.random(\%n as lua expr\) +macro [random int %n, random integer %n, randint %n] =: ".."|math.random(\%n as lua\) macro [random from %low to %high, random number from %low to %high, rand %low %high] =: ".." - |math.random(\%low as lua expr\, \%high as lua expr\) + |math.random(\%low as lua\, \%high as lua\) rule [random choice from %elements, random choice %elements, random %elements] =: lua expr ".."|vars.elements[math.random(#vars.elements)] -macro [sum of %items, sum %items] =: ".."|compiler.utils.sum(\%items as lua expr\) -macro [product of %items, product %items] =: ".."|compiler.utils.product(\%items as lua expr\) -macro [all of %items] =: ".."|compiler.utils.all(\%items as lua expr\) -macro [any of %items] =: ".."|compiler.utils.any(\%items as lua expr\) +macro [sum of %items, sum %items] =: ".."|compiler.utils.sum(\%items as lua\) +macro [product of %items, product %items] =: ".."|compiler.utils.product(\%items as lua\) +macro [all of %items] =: ".."|compiler.utils.all(\%items as lua\) +macro [any of %items] =: ".."|compiler.utils.any(\%items as lua\) # This is a rule, not a macro so we can use vars.items twice without running it twice. rule [avg of %items, average of %items] =: lua expr ".."|(compiler.utils.sum(vars.items)/#vars.items) macro [min of %items, smallest of %items, lowest of %items] =: - ".."|compiler.utils.min(\%items as lua expr\) + ".."|compiler.utils.min(\%items as lua\) macro [max of %items, biggest of %items, largest of %items, highest of %items] =: - ".."|compiler.utils.min(\%items as lua expr\) + ".."|compiler.utils.min(\%items as lua\) macro [min of %items with respect to %keys] =: - ".."|compiler.utils.min(\%items as lua expr\, \%keys as lua expr\) + ".."|compiler.utils.min(\%items as lua\, \%keys as lua\) macro [max of %items with respect to %keys] =: - ".."|compiler.utils.max(\%items as lua expr\, \%keys as lua expr\) + ".."|compiler.utils.max(\%items as lua\, \%keys as lua\) -- cgit v1.2.3