|
19 | 19 | --- Transform a node using the registered handler. |
20 | 20 | -- @tparam table node |
21 | 21 | function compiler:transform(node, ...) |
22 | | - assert(node.type, ("Bad node: %s"):format(tostring(node))) |
| 22 | + if type(node) ~= "table" then |
| 23 | + error(("Bad node type for (%s): %s"):format(node, type(node))) |
| 24 | + elseif not node.type then |
| 25 | + local out = {} |
| 26 | + for k, v in pairs(node) do |
| 27 | + out[#out + 1] = ("%s %s: %s"):format(type(v), k, v) |
| 28 | + end |
| 29 | + error("Bad node:\n" .. table.concat(out, "\n")) |
| 30 | + end |
23 | 31 | assert(handlers[node.type], ("Can't find node handler for (%s)"):format(node.type)) |
24 | 32 | self.last_node = node |
25 | 33 | return handlers[node.type](self, node, ...) |
@@ -543,37 +551,25 @@ handlers['assignment'] = function(self, node) |
543 | 551 | end |
544 | 552 |
|
545 | 553 | handlers['function_call'] = function(self, node) |
546 | | - if node.generator then |
547 | | - return self:transform { |
548 | | - node.generator[1]; |
549 | | - {type = "function_call"; |
550 | | - node[1]; |
551 | | - has_self = node.has_self; |
552 | | - index_class = node.index_class; |
553 | | - expression_list = node.generator.expression_list or |
554 | | - node.generator.variable_list; |
555 | | - }; |
556 | | - type = "iterative_for_loop"; -- `in` without `for` only 1 var V |
557 | | - variable_list = node.generator.variable_list |
558 | | - } |
559 | | - else |
| 554 | + local calls = {} |
| 555 | + for _, call in ipairs(node) do |
560 | 556 | local name |
561 | | - if node.has_self then |
562 | | - if node.index_class then |
563 | | - node.expression_list = node.expression_list or {} |
564 | | - table.insert(node.expression_list, 1, node[1]) |
565 | | - node[1] = {type = "variable", node.index_class} |
566 | | - name = self:transform(node[1]) .. "." .. node.has_self |
567 | | - else |
568 | | - name = self:transform(node[1]) .. ":" .. node.has_self |
569 | | - end |
570 | | - elseif #node[1] == 2 and node.is_method then |
571 | | - name = node[1][1] .. ":" .. node[1][2] |
| 557 | + if _ ~= 1 and call[1] then |
| 558 | + calls[#calls + 1] = "." |
| 559 | + end |
| 560 | + if call.has_self and not call[1] then |
| 561 | + name = ":" .. call.has_self |
| 562 | + elseif call.has_self then |
| 563 | + name = self:transform(call[1]) .. ":" .. call.has_self |
| 564 | + elseif #call[1] == 2 and node.is_self and _ == 1 then |
| 565 | + name = call[1][1] .. ":" .. call[1][2] -- hack in for @method(); |
572 | 566 | else |
573 | | - name = self:transform(node[1]) |
| 567 | + name = self:transform(call[1]) |
574 | 568 | end |
575 | | - return name .. "(" .. self:transform_expression_list(node) .. ")" |
| 569 | + calls[#calls + 1] = name .. "(" .. |
| 570 | + self:transform_expression_list(call) .. ")" |
576 | 571 | end |
| 572 | + return table.concat(calls) |
577 | 573 | end |
578 | 574 |
|
579 | 575 | handlers['variable'] = function(self, node) |
|
0 commit comments