diff --git a/anselme/ast/Block.lua b/anselme/ast/Block.lua index aa7db0a..a7f46d5 100644 --- a/anselme/ast/Block.lua +++ b/anselme/ast/Block.lua @@ -8,20 +8,21 @@ local Block = ast.abstract.Node { expressions = {}, - init = function(self) - self.expressions = {} + init = function(self, ...) + self.expressions = {...} end, add = function(self, expression) -- only for construction table.insert(self.expressions, expression) end, - _format = function(self, state, prio, ...) + _format = function(self, state, prio, indentation, ...) local l = {} + local indent = ("\t"):rep(indentation) for _, e in ipairs(self.expressions) do if Flush:is(e) then - table.insert(l, (e:format(state, 0, ...):gsub("\n$", ""))) + table.insert(l, indent..(e:format(state, 0, indentation, ...):gsub("\n$", ""))) else - table.insert(l, e:format(state, 0, ...)) + table.insert(l, indent..e:format(state, 0, indentation, ...)) end end return table.concat(l, "\n") diff --git a/anselme/ast/PartialScope.lua b/anselme/ast/PartialScope.lua index 3b8d9b6..0e93d22 100644 --- a/anselme/ast/PartialScope.lua +++ b/anselme/ast/PartialScope.lua @@ -27,11 +27,11 @@ PartialScope = ast.abstract.Node { end, _format = function(self, state, priority, indentation, ...) - if self.definitions[attached_block_symbol] then + if self.definitions[attached_block_symbol] and not Undefined:is(self.definitions[attached_block_symbol]) then local block = self.definitions[attached_block_symbol] local exp = self.expression:format(state, priority, indentation, ...) if exp:sub(-2) == " _" then exp = exp:sub(1, -3) end - return exp.."\n\t"..block:format(state, priority, indentation + 1, ...) + return exp.."\n"..block:format(state, priority, indentation + 1, ...) -- block is a Block and will indent itself like a good boy else return self.expression:format(state, priority, indentation, ...) end diff --git a/anselme/ast/abstract/Node.lua b/anselme/ast/abstract/Node.lua index 67bb490..1b510bf 100644 --- a/anselme/ast/abstract/Node.lua +++ b/anselme/ast/abstract/Node.lua @@ -14,7 +14,7 @@ local unpack = table.unpack or unpack local uuid = require("anselme.common").uuid -local Call, Identifier, ArgumentTuple, Struct, Tuple, String, Pair +local Call, Identifier, Struct, Tuple, String, Pair local resume_manager local custom_call_identifier @@ -336,9 +336,6 @@ Node = class { end end - local indentation = ("\t"):rep(indentation_level) - s = s:gsub("\n", "\n"..indentation) - return s end, -- same as :format, but should be called only for nodes right of the current operator @@ -427,7 +424,7 @@ Node = class { -- Thus, any require here that may require other Nodes shall be done here. This method is called in anselme.lua after everything else is required. _i_hate_cycles = function(self) local ast = require("anselme.ast") - Call, Identifier, ArgumentTuple, Struct, Tuple, String, Pair = ast.Call, ast.Identifier, ast.ArgumentTuple, ast.Struct, ast.Tuple, ast.String, ast.Pair + Call, Identifier, Struct, Tuple, String, Pair = ast.Call, ast.Identifier, ast.Struct, ast.Tuple, ast.String, ast.Pair custom_call_identifier = Identifier:new("_!") resume_manager = require("anselme.state.resume_manager")