コード例 #1
0
ファイル: __init__.py プロジェクト: ABob/vim
    def __init__(self, source, namespaces, **kwds):
        """
        Parse `source` and mixin interpreted Python objects from `namespaces`.

        :type source: str
        :arg  source: Code to parse.
        :type namespaces: list of dict
        :arg  namespaces: a list of namespace dictionaries such as the one
                          returned by :func:`locals`.

        Other optional arguments are same as the ones for :class:`Script`.
        If `line` and `column` are None, they are assumed be at the end of
        `source`.
        """
        if type(namespaces) is not list or len(namespaces) == 0 or \
           any([type(x) is not dict for x in namespaces]):
            raise TypeError("namespaces must be a non-empty list of dict")

        super(Interpreter, self).__init__(source, **kwds)
        self.namespaces = namespaces

        # Don't use the fast parser, because it does crazy stuff that we don't
        # need in our very simple and small code here (that is always
        # changing).
        self._parser = UserContextParser(self._grammar, self.source,
                                         self._orig_path, self._pos,
                                         self._user_context, self._parsed_callback,
                                         use_fast_parser=False)
        interpreter.add_namespaces_to_parser(self._evaluator, namespaces,
                                             self._parser.module())
コード例 #2
0
ファイル: __init__.py プロジェクト: meteor5118/myvim
    def __init__(self, source, namespaces, **kwds):
        """
        Parse `source` and mixin interpreted Python objects from `namespaces`.

        :type source: str
        :arg  source: Code to parse.
        :type namespaces: list of dict
        :arg  namespaces: a list of namespace dictionaries such as the one
                          returned by :func:`locals`.

        Other optional arguments are same as the ones for :class:`Script`.
        If `line` and `column` are None, they are assumed be at the end of
        `source`.
        """
        if type(namespaces) is not list or len(namespaces) == 0 or \
           any([type(x) is not dict for x in namespaces]):
            raise TypeError("namespaces must be a non-empty list of dict")

        super(Interpreter, self).__init__(source, **kwds)
        self.namespaces = namespaces

        # Don't use the fast parser, because it does crazy stuff that we don't
        # need in our very simple and small code here (that is always
        # changing).
        self._parser = UserContextParser(self._grammar,
                                         self.source,
                                         self._orig_path,
                                         self._pos,
                                         self._user_context,
                                         self._parsed_callback,
                                         use_fast_parser=False)
        interpreter.add_namespaces_to_parser(self._evaluator, namespaces,
                                             self._parser.module())