class Sass::Engine

def parse_directive(parent, line, root)

def parse_directive(parent, line, root)
  directive, whitespace, value = line.text[1..-1].split(/(\s+)/, 2)
  offset = directive.size + whitespace.size + 1 if whitespace
  # If value begins with url( or ",
  # it's a CSS @import rule and we don't want to touch it.
  if directive == "import"
    raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath import directives.",
      :line => @line + 1) unless line.children.empty?
    if (match = value.match(Sass::SCSS::RX::STRING) || value.match(Sass::SCSS::RX::URI)) &&
        !match.post_match.strip.empty? && match.post_match.strip[0] != ?,
      return Tree::DirectiveNode.new("@import #{value}")
    end
    value.split(/,\s*/).map do |f|
      f = $1 || $2 || $3 if f =~ Sass::SCSS::RX::STRING || f =~ Sass::SCSS::RX::URI
      Tree::ImportNode.new(f)
    end
  elsif directive == "mixin"
    parse_mixin_definition(line)
  elsif directive == "include"
    parse_mixin_include(line, root)
  elsif directive == "for"
    parse_for(line, root, value)
  elsif directive == "else"
    parse_else(parent, line, value)
  elsif directive == "while"
    raise SyntaxError.new("Invalid while directive '@while': expected expression.") unless value
    Tree::WhileNode.new(parse_script(value, :offset => offset))
  elsif directive == "if"
    raise SyntaxError.new("Invalid if directive '@if': expected expression.") unless value
    Tree::IfNode.new(parse_script(value, :offset => offset))
  elsif directive == "debug"
    raise SyntaxError.new("Invalid debug directive '@debug': expected expression.") unless value
    raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath debug directives.",
      :line => @line + 1) unless line.children.empty?
    offset = line.offset + line.text.index(value).to_i
    Tree::DebugNode.new(parse_script(value, :offset => offset))
  elsif directive == "extend"
    raise SyntaxError.new("Invalid extend directive '@extend': expected expression.") unless value
    raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath extend directives.",
      :line => @line + 1) unless line.children.empty?
    offset = line.offset + line.text.index(value).to_i
    Tree::ExtendNode.new(parse_interp(value, offset))
  elsif directive == "warn"
    raise SyntaxError.new("Invalid warn directive '@warn': expected expression.") unless value
    raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath warn directives.",
      :line => @line + 1) unless line.children.empty?
    offset = line.offset + line.text.index(value).to_i
    Tree::WarnNode.new(parse_script(value, :offset => offset))
  else
    Tree::DirectiveNode.new(line.text)
  end
end