diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-11 03:32:12 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-11 03:32:12 -0800 |
| commit | 9d8c7014416b6cffae66497b1c923f862fe6aa1a (patch) | |
| tree | 27e0c27cf673ebbf0d926a8f2c89de5624965369 /lib/operators.nom | |
| parent | bfe66a70e6fb4ac20253f6d5fb85946ef14ecbc6 (diff) | |
Added "%'s id" to use UUIDs and changed "% = %" to "set % = %" and some
other misc.
Diffstat (limited to 'lib/operators.nom')
| -rw-r--r-- | lib/operators.nom | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/operators.nom b/lib/operators.nom index 95441ea..f576e40 100644 --- a/lib/operators.nom +++ b/lib/operators.nom @@ -57,7 +57,7 @@ compile [%str |%start|] to: "\(%str as lua):sub(\(%start as lua), \(%start as lu compile [%str |%start - %stop|] to: "\(%str as lua):sub(\(%start as lua), \(%stop as lua))" # Variable assignment operator, and += type versions -compile [%var = %val] to code: +compile [set %var = %val] to code: lua> ".." if \%var.type == 'List' and \%val.type == 'List' then local lhs = {}; @@ -92,11 +92,26 @@ compile [%x > %y] to: "(\(%x as lua) > \(%y as lua))" compile [%x <= %y] to: "(\(%x as lua) <= \(%y as lua))" compile [%x >= %y] to: "(\(%x as lua) >= \(%y as lua))" # == and != do equivalence checking, rather than identity checking -compile [%a == %b] to: "nomsu.utils.equivalent(\(%a as lua), \(%b as lua))" -compile [%a != %b] to: "(not nomsu.utils.equivalent(\(%a as lua), \(%b as lua)))" -# For strict identity checking: -compile [%x === %y] to: "(\(%x as lua) == \(%y as lua))" -compile [%x !== %y] to: "(\(%x as lua) ~= \(%y as lua))" +compile [%a is %b, %a = %b, %a == %b] to: + lua> ".." + local safe = {Text=true, Number=true}; + local a_lua, b_lua = nomsu:tree_to_lua(\%a).expr, nomsu:tree_to_lua(\%b).expr; + if safe[\%a.type] or safe[\%b.type] then + return "("..a_lua.." == "..b_lua..")"; + else + return "nomsu.utils.equivalent("..a_lua..", "..b_lua..")"; + end +compile [%a isn't %b, %a is not %b, %a != %b] to: + lua> ".." + local safe = {Text=true, Number=true}; + local a_lua, b_lua = nomsu:tree_to_lua(\%a).expr, nomsu:tree_to_lua(\%b).expr; + if safe[\%a.type] or safe[\%b.type] then + return "("..a_lua.." ~= "..b_lua..")"; + else + return "(not nomsu.utils.equivalent("..a_lua..", "..b_lua.."))"; + end +# For strict identity checking, use (%x's id) is (%y's id) +compile [%'s id, id of %] to: "nomsu.ids[\(% as lua)]" # 3-part chained comparisons # (uses a lambda to avoid re-evaluating middle value, while still being an expression) |
