class Phlex::Compiler

def call

def call
	Visitors::File.new(self).visit(tree)
end

def file

def file
	location[0]
end

def initialize(view)

def initialize(view)
	@view = view
end

def inspect

def inspect
	"#{self.class.name} for #{@view.name} view class"
end

def line

def line
	location[1]
end

def location

def location
	::Module.const_source_location(@view.name)
end

def redefine(method, line:)

def redefine(method, line:)
	patch = scope + method + unscope
	eval(patch, Kernel.binding, file, (line - 1))
end

def redefined?(method_name)

def redefined?(method_name)
	prototype = @view.allocate
	@view.instance_method(method_name).bind(prototype) !=
		Phlex::HTML.instance_method(method_name).bind(prototype)
end

def scope

def scope
	@scope.map do |scope|
		case scope
			in SyntaxTree::ModuleDeclaration then "module #{scope.constant.constant.value};"
			in SyntaxTree::ClassDeclaration then "class #{scope.constant.constant.value};"
		end
	end.join + "\n"
end

def source

def source
	SyntaxTree.read(file)
end

def tag_method?(method_name)

def tag_method?(method_name)
	(HTML::STANDARD_ELEMENTS.key?(method_name) || HTML::VOID_ELEMENTS.key?(method_name)) && !redefined?(method_name)
end

def tree

def tree
	@tree ||= SyntaxTree.parse(source)
end

def unscope

def unscope
	"; end" * @scope.size
end