diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-25 16:30:49 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-25 16:31:09 -0700 |
| commit | 5d59d510cd6fdc8553250e5ec10f19a285e8878c (patch) | |
| tree | 69d9a2646ed59746500fc9c62a04294a1019d381 /lib | |
| parent | 50a092e4b5cb82131c0c8f6f46c7d21a42198858 (diff) | |
Removing end-of-line ":" and "(..)" for blocks (they just use
indentation now).
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/file_hash.nom | 6 | ||||
| -rw-r--r-- | lib/object.nom | 14 | ||||
| -rw-r--r-- | lib/object2.nom | 18 | ||||
| -rw-r--r-- | lib/training_wheels.nom | 30 |
4 files changed, 34 insertions, 34 deletions
diff --git a/lib/file_hash.nom b/lib/file_hash.nom index 4d99e39..0d7e523 100644 --- a/lib/file_hash.nom +++ b/lib/file_hash.nom @@ -28,15 +28,15 @@ lua> ".." end attrdir("."); -action [sha1 %]: +action [sha1 %] lua> "return sha1(\%);" -action [file with hash %hash]: +action [file with hash %hash] %file <- (%hash in %hash_to_filename) assume %file or barf "File with SHA1 hash \%hash not found!" return %file -action [hash of file %filename]: +action [hash of file %filename] lua> ".." local f = io.open(\%filename); local hash = sha1(f:read("*a")); diff --git a/lib/object.nom b/lib/object.nom index ca664b5..0bb2538 100644 --- a/lib/object.nom +++ b/lib/object.nom @@ -1,6 +1,6 @@ use "core" -compile [@%var] to: +compile [@%var] to lua> ".." local key_lua = repr(\%var.value); local key_attr = (key_lua:match("'([a-zA-Z][a-zA-Z0-9]*)'") @@ -12,7 +12,7 @@ compile [@%var] to: end return {expr="_me["..key_lua.."]"}; -compile [@%var <- %val] to: +compile [@%var <- %val] to lua> ".." local val_lua = \(%val as lua expr); local key_lua = repr(\%var.value); @@ -25,12 +25,12 @@ compile [@%var <- %val] to: end return {statements="_me["..key_lua.."] = "..val_lua..";"}; -compile [define object %classname %class_body] to: +compile [define object %classname %class_body] to %class_identifier <- (=lua "nomsu:var_to_lua_identifier(\(%classname as value)):sub(2,-1)") if: %class_identifier is "" %class_identifier <- "class" %methods <- [] - for %line in (%class_body's "value"): + for %line in (%class_body's "value") if: (%line's "type") is "Comment" do next %line assume (((%line's "type") == "FunctionCall") and ((%line's stub) == "action % %")) @@ -86,7 +86,7 @@ compile [define object %classname %class_body] to: return {..} statements:".." do -- \%class_identifier - -- Create the class object: + -- Create the class object local \%class_identifier = setmetatable({ name=\(%classname as lua expr), instances=setmetatable({}, {__mode="k"}), }, { @@ -104,10 +104,10 @@ compile [define object %classname %class_body] to: }); \%class_identifier.class = \%class_identifier; - -- Define the methods: + -- Define the methods \(%methods joined with "\n") - -- Define class methods for instantiating and accessing instances: + -- Define class methods for instantiating and accessing instances \%class_identifier.instance_metatable = { __index=\%class_identifier, __tostring=\%class_identifier['% as text'] or function(inst) diff --git a/lib/object2.nom b/lib/object2.nom index 762ab4d..863ee2a 100644 --- a/lib/object2.nom +++ b/lib/object2.nom @@ -2,7 +2,7 @@ use "core" compile [@] to: Lua value "self" -compile [@%var] to: +compile [@%var] to lua> ".." local key_lua = repr(\%var.value); local key_attr = (key_lua:match("'([a-zA-Z][a-zA-Z0-9]*)'") @@ -14,7 +14,7 @@ compile [@%var] to: end return Lua.Value(tree.source, "self["..key_lua.."]"); -compile [@%var <- %val] to: +compile [@%var <- %val] to lua> ".." local val_lua = \(%val as lua expr); local key_lua = repr(\%var.value); @@ -27,7 +27,7 @@ compile [@%var <- %val] to: end return Lua(tree.source, "self[", key_lua, "] = ", val_lua, ";"); -compile [as %instance %body] to: +compile [as %instance %body] to %body_lua <- (%body as lua) lua> "\%body_lua:convert_to_statements();" return @@ -43,21 +43,21 @@ compile [as %instance %body] to: \%body_lua end -compile [define object %classname %class_body] to: +compile [define object %classname %class_body] to %class_identifier <- (=lua "nomsu:var_to_lua_identifier(\(%classname as value)):sub(2,-1)") if: %class_identifier is "" %class_identifier <- "class" %methods <- [] %__index <- %class_identifier %__newindex <- "nil" - for %line in (%class_body's "value"): + for %line in (%class_body's "value") if: (%line's "type") is "Comment" do next %line if: ((%line's "type") is "FunctionCall") and ((%line's stub) is "slots %") %slot_index_clauses <- [] %slot_newindex_clauses <- [] %slots <- %line.value.2.value - for %slot_index = %slot_var in %slots: + for %slot_index = %slot_var in %slots to %slot_index_clauses add ".." if key == \(repr (%slot_var's "value")) or key == \(repr (%slot_var as lua expr)) then return rawget(self, \%slot_index); @@ -115,7 +115,7 @@ compile [define object %classname %class_body] to: return Lua ".." do -- \%class_identifier - -- Create the class object: + -- Create the class object local \%class_identifier = setmetatable({ name=\(%classname as lua expr), instances=setmetatable({}, {__mode="k"}), }, { @@ -132,10 +132,10 @@ compile [define object %classname %class_body] to: }); \%class_identifier.class = \%class_identifier; - -- Define the methods: + -- Define the methods \(%methods joined with "\n") - -- Define class methods for instantiating and accessing instances: + -- Define class methods for instantiating and accessing instances \%class_identifier.instance_metatable = { __index=\%__index, __newindex=\%__newindex, diff --git a/lib/training_wheels.nom b/lib/training_wheels.nom index e5c02fb..1f524da 100644 --- a/lib/training_wheels.nom +++ b/lib/training_wheels.nom @@ -26,19 +26,19 @@ parse [error!, panic!, fail!, abort!] as: barf! parse [error %, panic %, fail %, abort %] as: barf % parse [assert %condition %message] as: assume %condition or barf %message parse [%cond ? %if_true %if_false] as: %if_true if %cond else %if_false -compile [function %args %body, lambda %args %body] to: - %body_lua <- (%body as lua) - %statements <- ((%body_lua's "statements") or "return \(%body_lua's "expr");") - %locals <- (% for all ((%body_lua's "locals") or [])) - for all (%args's "value"): - lua> "utils.remove_from_list(\%locals, \(% as lua expr));" - if: (size of %locals) > 0 - %statements <- "local \(%locals joined with ", ");\n\%statements" - - return {..} - expr: ".." - (function(\(((% as lua expr) for all (%args's "value")) joined with ", ")) - \%statements - end) +compile [function %args %body, lambda %args %body] to + %lua <-: Lua value "(function(" + for %i = %arg in %args.value + if: %i > 1 + to %lua write ", " + to %lua write: %arg as lua expr + to %lua write ")\n " + %body <-: %body as lua + lua> "\%body:convert_to_statements('return ');" + for all %args.value: lua> "\%body:remove_free_vars(\%);" + to %lua write %body + to %lua write "\nend)" + return %lua parse [function %name %args %body] as: %name <- (function %args %body) -compile [call %fn %args] to {expr:"\(%fn as lua expr)(unpack(\(%args as lua expr)))"} +compile [call %fn %args] to + Lua value "\(%fn as lua expr)(unpack(\(%args as lua expr)))" |
