import codecs
import ast


def parse_source_file(filename):
    """Parse source file into AST node.

    Parameters
    ----------
    filename : str
        File path

    Returns
    -------
    node : AST node
    content : utf-8 encoded string
    """
    with codecs.open(filename, 'r', 'utf-8') as fid:
        content = fid.read()
    # change from Windows format to UNIX for uniformity
    content = content.replace('\r\n', '\n')

    try:
        node = ast.parse(content)
        return node, content
    except SyntaxError:
        return None, content