示例#1
0
    def attach_identifier_attributes(self, ast):
        """ Attach 5 flags to the AST.

        - is dynamic: True if the identifier name can be determined by static analysis.
        - is member: True if the identifier is a member of a subscription/dot/slice node.
        - is declaring: True if the identifier is used to declare.
        - is autoload: True if the identifier is declared with autoload.
        - is function: True if the identifier is a function. Vim distinguish
            between function identifiers and variable identifiers.
        - is declarative paramter: True if the identifier is a declarative
            parameter. For example, the identifier "param" in Func(param) is a
            declarative paramter.
        - is on string expression context: True if the variable is on the
            string expression context. The string expression context is the
            string content on the 2nd argument of the map or filter function.
        """
        redir_assignment_parser = RedirAssignmentParser()
        ast_with_parsed_redir = redir_assignment_parser.process(ast)

        map_and_filter_parser = MapAndFilterParser()
        ast_with_parse_map_and_filter_and_redir = \
            map_and_filter_parser.process(ast_with_parsed_redir)

        traverse(ast_with_parse_map_and_filter_and_redir,
                 on_enter=self._enter_handler)
        return ast
示例#2
0
    def attach_identifier_attributes(self, ast): # type: (Dict[str, Any]) -> Dict[str, Any]
        """ Attach 5 flags to the AST.

        - is dynamic: True if the identifier name can be determined by static analysis.
        - is member: True if the identifier is a member of a subscription/dot/slice node.
        - is declaring: True if the identifier is used to declare.
        - is autoload: True if the identifier is declared with autoload.
        - is function: True if the identifier is a function. Vim distinguish
            between function identifiers and variable identifiers.
        - is declarative parameter: True if the identifier is a declarative
            parameter. For example, the identifier "param" in Func(param) is a
            declarative parameter.
        - is on string expression context: True if the variable is on the
            string expression context. The string expression context is the
            string content on the 2nd argument of the map or filter function.
        - is lambda argument: True if the identifier is a lambda argument.
        """
        redir_assignment_parser = RedirAssignmentParser()
        ast_with_parsed_redir = redir_assignment_parser.process(ast)

        map_and_filter_parser = CallNodeParser()
        ast_with_parse_map_and_filter_and_redir = \
            map_and_filter_parser.process(ast_with_parsed_redir)

        traverse(
            ast_with_parse_map_and_filter_and_redir,
            on_enter=lambda node: self._enter_handler(
                node,
                is_on_lambda_str=None,
                is_on_lambda_body=None,
            )
        )
        return ast
    def test_process(self):
        ast = self.create_ast(Fixtures.REDIR_VARIABLE)
        parser = RedirAssignmentParser()
        got_ast = parser.process(ast)

        got_identifier = get_redir_content(got_ast['body'][0])
        self.assertEqual('g:var', got_identifier.get('value'))
    def test_process(self):
        ast = self.create_ast(Fixtures.REDIR_VARIABLE)
        parser = RedirAssignmentParser()
        got_ast = parser.process(ast)

        got_identifier = get_redir_content(got_ast['body'][0])
        self.assertEqual('g:var', got_identifier.get('value'))
    def test_traverse(self):
        ast = self.create_ast(Fixtures.REDIR_VARIABLE)
        parser = RedirAssignmentParser()
        got_ast = parser.process(ast)

        is_redir_content_visited = {
            'g:var': False,
        }

        def enter_handler(node):
            if NodeType(node['type']) is not NodeType.IDENTIFIER:
                return

            is_redir_content_visited[node['value']] = True

        traverse(got_ast, on_enter=enter_handler)

        self.assertTrue(all(is_redir_content_visited.values()))
    def test_traverse(self):
        ast = self.create_ast(Fixtures.REDIR_VARIABLE)
        parser = RedirAssignmentParser()
        got_ast = parser.process(ast)

        is_redir_content_visited = {
            'g:var': False,
        }

        def enter_handler(node):
            if NodeType(node['type']) is not NodeType.IDENTIFIER:
                return

            is_redir_content_visited[node['value']] = True

        traverse(got_ast, on_enter=enter_handler)

        self.assertTrue(all(is_redir_content_visited.values()))