diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-08-29 14:19:16 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-08-29 14:20:18 -0700 |
| commit | e64632be1aa938c865d06acfcf6641b75ecb42ac (patch) | |
| tree | 9d9dfd28c032748fa4bb4ce2be600158fef3c2f7 /core | |
| parent | 436982c6ba5cbdebfaa28b455b5d0695067de146 (diff) | |
Switched "as_lua_id" to not add an underscore by default, and just add
it manually to variables and A_ as a prefix to actions. Now, by default,
classes and method calls don't use the A_ prefix, which means nomsu can
more easily play nice with regular Lua objects.
Diffstat (limited to 'core')
| -rw-r--r-- | core/metaprogramming.nom | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom index a8e2f7c..2392097 100644 --- a/core/metaprogramming.nom +++ b/core/metaprogramming.nom @@ -94,13 +94,13 @@ test: assume ((foo 1) == "outer") compile [local action %actions %body] to: lua> ".." - local fn_name = "A"..string.as_lua_id(\%actions[1].stub) + local fn_name = "A_"..string.as_lua_id(\%actions[1].stub) local \%args = table.map(\%actions[1]:get_args(), function(a) return tostring(nomsu:compile(a)) end) local lua = LuaCode(tree.source, fn_name, " = ", \(compile as (%args -> %body))) lua:add_free_vars({fn_name}) for i=2,#\%actions do local alias = \%actions[i] - local alias_name = "A"..string.as_lua_id(alias.stub) + local alias_name = "A_"..string.as_lua_id(alias.stub) lua:add_free_vars({alias_name}) local \%alias_args = table.map(alias:get_args(), function(a) return tostring(nomsu:compile(a)) end) lua:append("\\n", alias_name, " = ") @@ -125,7 +125,7 @@ test: compile [action %actions %body] to (..) lua> ".." local lua = \(compile as (local action %actions %body)) - lua:remove_free_vars(table.map(\%actions, function(a) return "A"..string.as_lua_id(a.stub) end)) + lua:remove_free_vars(table.map(\%actions, function(a) return "A_"..string.as_lua_id(a.stub) end)) return lua test: @@ -209,7 +209,7 @@ compile [%tree as lua return] to (..) Lua value "nomsu:compile(\(%tree as lua expr)):as_statements('return ')" compile [remove action %action] to (..) - Lua "A\(=lua "string.as_lua_id(\(%action.stub))") = nil" + Lua "A_\(=lua "string.as_lua_id(\(%action.stub))") = nil" test: assume ("\(\(foo \%x) as nomsu)" == "foo %x") or barf ".." @@ -223,8 +223,8 @@ compile [%tree as inline nomsu] to (..) action [%var as lua identifier, %var as lua id] (..) lua> ".." if type(\%var) == 'string' then return string.as_lua_id(\%var) - elseif \%var.type == 'Var' then return string.as_lua_id(\%var[1]) - elseif \%var.type == 'Action' then return "A"..string.as_lua_id(\%var.stub) + elseif \%var.type == 'Var' then return "_"..string.as_lua_id(\%var[1]) + elseif \%var.type == 'Action' then return "A_"..string.as_lua_id(\%var.stub) end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
