diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-07 18:45:27 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-07 18:45:27 -0800 |
| commit | 568a44ef191e1f4072d379700e3b6f599150a92b (patch) | |
| tree | c58e74b5f7539a0055d72d8ff40ef6f499aef9ea /lib/utils2.nom | |
| parent | c92e5fbc81e57ada43f2c17792e500da5b708bee (diff) | |
Reworking some stuff so that functions only allow expressions to be
return values with either an explicit "return" statement or if they're
the only line in the function, and the line is an expression.
Diffstat (limited to 'lib/utils2.nom')
| -rw-r--r-- | lib/utils2.nom | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/lib/utils2.nom b/lib/utils2.nom index 89a0767..2fa29f7 100644 --- a/lib/utils2.nom +++ b/lib/utils2.nom @@ -6,16 +6,12 @@ require "lib/collections.nom" compile [say %str] to: - if ((%str's "type") == "String"): - "nomsu:writeln(\(%str as lua))" - ..else: - "nomsu:writeln(nomsu:stringify(\(%str as lua)))" + "nomsu:writeln(\(%str as lua))" if ((%str's "type") == "String") + ..else "nomsu:writeln(nomsu:stringify(\(%str as lua)))" compile [do %action] to code: - if ((%action's "type") == "Thunk"): - %action as lua statements - ..else: - "(\(%action as lua))(nomsu, vars);" + (%action as lua statements) if ((%action's "type") == "Thunk") + ..else "(\(%action as lua))(nomsu, vars);" # With statement compile [with %assignments %action] to code: @@ -33,7 +29,7 @@ compile [with %assignments %action] to code: "local old_value\(%->"i") = \((%->"var") as lua); \((%->"var") as lua) = \((%->"value") as lua);" ..for all %data ..with glue "\n " - ".." + return ".." do \%setup local fell_through = false; @@ -51,26 +47,17 @@ parse [with %thing = %value %action] as: with [%thing = %value] %action # Any/all/none compile [all of %items, all %items] to: - if (%items' "type") == "List": - "(\(join ((% as lua) for all (%items' "value")) with glue " and "))" - ..else: - "nomsu.utils.all(\(%items as lua))" + "(\(join ((% as lua) for all (%items' "value")) with glue " and "))" + ..if (%items' "type") == "List" else "nomsu.utils.all(\(%items as lua))" parse [not all of %items, not all %items] as: not (all of %items) compile [any of %items, any %items] to: - if (%items' "type") == "List": - "(\(join ((% as lua) for all (%items' "value")) with glue " or "))" - ..else: - "nomsu.utils.any(\(%items as lua))" + "(\(join ((% as lua) for all (%items' "value")) with glue " or "))" + ..if (%items' "type") == "List" else "nomsu.utils.any(\(%items as lua))" parse [none of %items, none %items] as: not (any of %items) - compile [sum of %items, sum %items] to: - if (%items' "type") == "List": - "(\(join ((% as lua) for all (%items' "value")) with glue " + "))" - ..else: - "nomsu.utils.sum(\(%items as lua))" + "(\(join ((% as lua) for all (%items' "value")) with glue " + "))" + ..if (%items' "type") == "List" else "nomsu.utils.sum(\(%items as lua))" compile [product of %items, product %items] to: - if (%items' "type") == "List": - "(\(join ((% as lua) for all (%items' "value")) with glue " * "))" - ..else: - "nomsu.utils.product(\(%items as lua))" + "(\(join ((% as lua) for all (%items' "value")) with glue " * "))" + ..if (%items' "type") == "List" else "nomsu.utils.product(\(%items as lua))" |
