Exemplo n.º 1
0
def shellExtractor(file):
    """
    Extract comments from Shell file.
    :param file: File to scan
    :type file: string
    :return: Scan output
    :rtype: ScanOutput
    """
    result = CommentSyntax()
    single_line_comment = result.hash(file)
    cont_single_line_comment = contSingleLines(single_line_comment)
    file = file.split("/")
    output = ScanOutput()
    output.filename = file[-1]
    output.lang = "Shell"
    output.total_lines = single_line_comment[1]
    output.total_lines_of_comments = single_line_comment[3]
    output.blank_lines = single_line_comment[2]

    if cont_single_line_comment:
        single_line_comment = cont_single_line_comment[0]

    for i in single_line_comment[0]:
        output.single_line_comment.append(SingleLine(i[0], i[1]))

    for idx, _ in enumerate(cont_single_line_comment[1]):
        output.cont_single_line_comment.append(
            MultiLine(
                cont_single_line_comment[1][idx],
                cont_single_line_comment[2][idx],
                cont_single_line_comment[3][idx],
            ))

    return output
Exemplo n.º 2
0
def cssExtractor(file):
    """
    Extract comments from CSS file.
    :param file: File to scan
    :type file: string
    :return: Scan output
    :rtype: ScanOutput
    """
    result = CommentSyntax()
    multiline_comment = result.slashStar(file)
    file = file.split("/")
    output = ScanOutput()
    output.filename = file[-1]
    output.lang = "CSS"
    output.total_lines = multiline_comment[4]
    output.total_lines_of_comments = multiline_comment[3]
    output.blank_lines = multiline_comment[5]

    try:
        for idx, _ in enumerate(multiline_comment[0]):
            output.multi_line_comment.append(
                MultiLine(
                    multiline_comment[0][idx],
                    multiline_comment[1][idx],
                    multiline_comment[2][idx],
                ))
    except BaseException:
        pass

    return output
Exemplo n.º 3
0
def cExtractor(file):
    """
    Extract comments from C file.
    :param file: File to scan
    :type file: string
    :return: Scan output
    :rtype: ScanOutput
    """
    result = CommentSyntax()
    single_line_comment = result.doubleSlash(file)
    multiline_comment = result.slashStar(file)
    cont_single_line_comment = contSingleLines(single_line_comment)
    file = file.split("/")
    output = ScanOutput()
    output.filename = file[-1]
    output.lang = "C"
    output.total_lines = single_line_comment[1]
    output.total_lines_of_comments = single_line_comment[
        3] + multiline_comment[3]
    output.blank_lines = single_line_comment[2]

    if cont_single_line_comment:
        single_line_comment = cont_single_line_comment[0]

    for i in single_line_comment[0]:
        output.single_line_comment.append(SingleLine(i[0], i[1]))

    for idx, _ in enumerate(cont_single_line_comment[1]):
        output.cont_single_line_comment.append(
            MultiLine(
                cont_single_line_comment[1][idx],
                cont_single_line_comment[2][idx],
                cont_single_line_comment[3][idx],
            ))

    try:
        for idx, _ in enumerate(multiline_comment[0]):
            output.multi_line_comment.append(
                MultiLine(
                    multiline_comment[0][idx],
                    multiline_comment[1][idx],
                    multiline_comment[2][idx],
                ))
    except BaseException:
        pass

    return output
Exemplo n.º 4
0
def matlabExtractor(file):
    """
    Extract comments from MATLAB file.
    :param file: File to scan
    :type file: string
    :return: Scan output
    :rtype: ScanOutput
    """
    result = CommentSyntax()
    single_line_comment = result.percentage(file)
    multiline_comment = result.percentageCurlybraces(file)
    cont_single_line_comment = contSingleLines(single_line_comment)
    file = file.split("/")
    output = ScanOutput()
    output.filename = file[-1]
    output.lang = "MATLAB"
    output.total_lines = single_line_comment[1]
    output.total_lines_of_comments = single_line_comment[3] + multiline_comment[3]
    output.blank_lines = single_line_comment[2]

    if cont_single_line_comment:
        single_line_comment = cont_single_line_comment[0]

    for i in single_line_comment[0]:
        output.single_line_comment.append(SingleLine(i[0], i[1]))

    for idx, _ in enumerate(cont_single_line_comment[1]):
        output.cont_single_line_comment.append(
            MultiLine(
                cont_single_line_comment[1][idx],
                cont_single_line_comment[2][idx],
                cont_single_line_comment[3][idx],
            )
        )

    for idx, _ in enumerate(multiline_comment[0]):
        output.multi_line_comment.append(
            MultiLine(
                multiline_comment[0][idx],
                multiline_comment[1][idx],
                multiline_comment[2][idx],
            )
        )

    return output
Exemplo n.º 5
0
def rExtractor(file):
    """
    Extract comments from R file.
    :param file: File to scan
    :type file: string
    :return: Scan output
    :rtype: ScanOutput
    """
    result = CommentSyntax()
    single_line_comment = result.hash(file)
    file = file.split("/")
    output = ScanOutput()
    output.filename = file[-1]
    output.lang = "R"
    output.total_lines = single_line_comment[1]
    output.total_lines_of_comments = single_line_comment[3]
    output.blank_lines = single_line_comment[2]

    for i in single_line_comment[0]:
        output.single_line_comment.append(SingleLine(i[0], i[1]))

    return output