class Sass::Engine
def build_tree(index)
def build_tree(index) line, tabs = @lines[index] index += 1 @line = index node = parse_line(line) has_children = has_children?(index, tabs) # Node is a symbol if it's non-outputting, like a constant assignment unless node.is_a? Tree::Node if has_children if node == :constant raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath constants.", @line + 1) elsif node.is_a? Array # arrays can either be full of import statements # or attributes from mixin includes # in either case they shouldn't have children. # Need to peek into the array in order to give meaningful errors directive_type = (node.first.is_a?(Tree::DirectiveNode) ? "import" : "mixin") raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath #{directive_type} directives.", @line + 1) end end index = @line if node == :mixin return node, index end node.line = @line if node.is_a? Tree::CommentNode while has_children line, index = raw_next_line(index) node << line has_children = has_children?(index, tabs) end return node, index end # Resolve multiline rules if node.is_a?(Tree::RuleNode) if node.continued? child, index = build_tree(index) if @lines[old_index = index] if @lines[old_index].nil? || has_children?(old_index, tabs) || !child.is_a?(Tree::RuleNode) raise SyntaxError.new("Rules can't end in commas.", @line) end node.add_rules child end node.children = child.children if child end while has_children child, index = build_tree(index) validate_and_append_child(node, child) has_children = has_children?(index, tabs) end return node, index end