def index_file(file_name, file_content=None):
        log_file.write("Parsing " + file_name + "\n")
        if not file_content:
            file_content = open(file_name).read()

        visitor_handler = JSFileVisitorHandler(file_content)
        visitor = EntitiesVisitor()
        visitor_handler.add_visitor(visitor)
        try:
            visitor_handler.visit()
            update_file_model(file_name, visitor.functions + visitor.variables)
        except Exception as parsing_error:
            log_file.write(parsing_error.message + " " + str(parsing_error.args) + "\n")
예제 #2
0
def get_file_data_from_content(src_file_name, src_file_content):
	"""Use this to gather data for file, given its content.
	Will raise a jsparser.ParsingError if the syntax is incorrect"""

	visitor_handler = JSFileVisitorHandler(src_file_content)

	line_parser = LineParser()
	visitor_handler.add_visitor(line_parser)

	function_parser = FunctionParser()
	visitor_handler.add_visitor(function_parser)

	variable_parser = VariableParser()
	visitor_handler.add_visitor(variable_parser)
	
	class_property_parser = ClassPropertyParser()
	visitor_handler.add_visitor(class_property_parser)

	visitor_handler.visit()
	
	src_file_functions = function_parser.functions
	src_file_variables = variable_parser.variables
	src_file_class_properties = class_property_parser.properties
	src_file_lines = line_parser.file_lines

	# Trick to give the right FileLines to each function
	# The thing is now we only parse lines once, not once for the file and then once per function
	# So, we have to give the total lines to each function to make it simple for reviewers then to
	# get lines for a function.
	# Therefore, the FileLines can accept an "start/stop" argument to know where to look in the lines
	# FIXME: this shouldn't be handled here though
	for function in src_file_functions:
		function.lines = FileLines(src_file_lines.all_lines, function.start_pos, function.end_pos)

	return FileData(src_file_name, src_file_content, src_file_lines, src_file_functions, src_file_variables, src_file_class_properties)
예제 #3
0
def get_file_data_from_content(src_file_name, src_file_content):
    """Use this to gather data for file, given its content.
	Will raise a jsparser.ParsingError if the syntax is incorrect"""

    visitor_handler = JSFileVisitorHandler(src_file_content)

    line_parser = LineParser()
    visitor_handler.add_visitor(line_parser)

    function_parser = FunctionParser()
    visitor_handler.add_visitor(function_parser)

    variable_parser = VariableParser()
    visitor_handler.add_visitor(variable_parser)

    class_property_parser = ClassPropertyParser()
    visitor_handler.add_visitor(class_property_parser)

    visitor_handler.visit()

    src_file_functions = function_parser.functions
    src_file_variables = variable_parser.variables
    src_file_class_properties = class_property_parser.properties
    src_file_lines = line_parser.file_lines

    # Trick to give the right FileLines to each function
    # The thing is now we only parse lines once, not once for the file and then once per function
    # So, we have to give the total lines to each function to make it simple for reviewers then to
    # get lines for a function.
    # Therefore, the FileLines can accept an "start/stop" argument to know where to look in the lines
    # FIXME: this shouldn't be handled here though
    for function in src_file_functions:
        function.lines = FileLines(src_file_lines.all_lines,
                                   function.start_pos, function.end_pos)

    return FileData(src_file_name, src_file_content, src_file_lines,
                    src_file_functions, src_file_variables,
                    src_file_class_properties)