Beispiel #1
0
    def __init__(self, tab_width: int=DEFAULT_TAB_WIDTH):
        """
        Creates a helper object for spacing operations.

        :param tab_width: The number of spaces which visually equals a tab.
        """
        SectionCreatable.__init__(self)
        if not isinstance(tab_width, int):
            raise TypeError("The 'tab_width' parameter should be an integer.")

        self.tab_width = tab_width
Beispiel #2
0
    def __init__(self, tab_width: int = DEFAULT_TAB_WIDTH):
        """
        Creates a helper object for spacing operations.

        :param tab_width: The number of spaces which visually equals a tab.
        """
        SectionCreatable.__init__(self)
        if not isinstance(tab_width, int):
            raise TypeError("The 'tab_width' parameter should be an integer.")

        self.tab_width = tab_width
    def __init__(self,
                 setting_one: int,
                 raw_setting,
                 setting_two: bool=False,
                 setting_three: list=[1, 2],
                 opt_raw_set=5):
        SectionCreatable.__init__(self)
        assert isinstance(setting_one, int)
        assert isinstance(raw_setting, Setting)
        assert isinstance(setting_two, bool)
        assert isinstance(setting_three, list)
        assert isinstance(opt_raw_set, Setting) or isinstance(opt_raw_set, int)

        self.setting_one = setting_one
        self.raw_setting = raw_setting
        self.setting_two = setting_two
        self.setting_three = setting_three
        self.opt_raw_set = opt_raw_set
Beispiel #4
0
    def __init__(self,
                 setting_one: int,
                 raw_setting,
                 setting_two: bool = False,
                 setting_three: list = [1, 2],
                 opt_raw_set=5):
        SectionCreatable.__init__(self)
        assert isinstance(setting_one, int)
        assert isinstance(raw_setting, Setting)
        assert isinstance(setting_two, bool)
        assert isinstance(setting_three, list)
        assert isinstance(opt_raw_set, Setting) or isinstance(opt_raw_set, int)

        self.setting_one = setting_one
        self.raw_setting = raw_setting
        self.setting_two = setting_two
        self.setting_three = setting_three
        self.opt_raw_set = opt_raw_set
    def __init__(self, language: str, coalang_dir=None):
        """
        Creates a new LanguageDefinition object from file.

        A Language Definition holds constants which may help parsing the
        language. If you want to write a bear you'll probably want to use those
        definitions to keep your bear independent of the semantics of each
        language.

        You can easily get your language definition by just creating it with
        the name of the language desired:

        >>> list(LanguageDefinition("cpp")['extensions'])
        ['.c', '.cpp', '.h', '.hpp']

        For some languages aliases exist, the name is case insensitive:

        >>> list(LanguageDefinition("C++")['extensions'])
        ['.c', '.cpp', '.h', '.hpp']

        If no language exists, you will get a ``FileNotFoundError``:

        >>> LanguageDefinition("BULLSHIT!")  # +ELLIPSIS
        Traceback (most recent call last):
         ...
        FileNotFoundError: ...

        :param language:           The actual language (e.g. C++).
        :param coalang_dir:        Path to directory with coalang language
                                   definition files. This replaces the default
                                   path if given.
        :raises FileNotFoundError: Raised when no definition is available for
                                   the given language.
        """
        SectionCreatable.__init__(self)
        self.language = language.lower()
        if self.language in LANGUAGE_DICT:
            self.language = LANGUAGE_DICT[self.language]

        coalang_file = os.path.join(
            coalang_dir or Constants.language_definitions,
            self.language + ".coalang")

        self.lang_dict = ConfParser().parse(coalang_file)["default"]
Beispiel #6
0
    def __init__(self, language: str, coalang_dir=None):
        """
        Creates a new LanguageDefinition object from file.

        A Language Definition holds constants which may help parsing the
        language. If you want to write a bear you'll probably want to use those
        definitions to keep your bear independent of the semantics of each
        language.

        You can easily get your language definition by just creating it with
        the name of the language desired:

        >>> list(LanguageDefinition("cpp")['extensions'])
        ['.c', '.cpp', '.h', '.hpp']

        For some languages aliases exist, the name is case insensitive:

        >>> list(LanguageDefinition("C++")['extensions'])
        ['.c', '.cpp', '.h', '.hpp']

        If no language exists, you will get a ``FileNotFoundError``:

        >>> LanguageDefinition("BULLSHIT!")  # +ELLIPSIS
        Traceback (most recent call last):
         ...
        FileNotFoundError: ...

        :param language:           The actual language (e.g. C++).
        :param coalang_dir:        Path to directory with coalang language
                                   definition files. This replaces the default
                                   path if given.
        :raises FileNotFoundError: Raised when no definition is available for
                                   the given language.
        """
        SectionCreatable.__init__(self)
        self.language = language.lower()
        if self.language in LANGUAGE_DICT:
            self.language = LANGUAGE_DICT[self.language]

        coalang_file = os.path.join(
            coalang_dir or Constants.language_definitions,
            self.language + ".coalang")

        self.lang_dict = ConfParser().parse(coalang_file)["default"]
Beispiel #7
0
    def __init__(self, language: str):
        """
        Creates a new LanguageDefinition object from file.

        A Language Definition holds constants which may help parsing the
        language. If you want to write a bear you'll probably want to use those
        definitions to keep your bear independent of the semantics of each
        language.

        :param language:           The actual language (e.g. C++).
        :raises FileNotFoundError: Raised when no definition is available for
                                   the given family.
        :raises KeyError:          Raised when no definition is available for
                                   the given language.
        """
        SectionCreatable.__init__(self)
        self.language = language.lower()
        filename = os.path.join(Constants.language_definitions,
                                language.lower() + ".coalang")
        self.lang_dict = ConfParser().parse(filename)["default"]
Beispiel #8
0
    def __init__(self, language: str):
        """
        Creates a new LanguageDefinition object from file.

        A Language Definition holds constants which may help parsing the
        language. If you want to write a bear you'll probably want to use those
        definitions to keep your bear independent of the semantics of each
        language.

        :param language:           The actual language (e.g. C++).
        :raises FileNotFoundError: Raised when no definition is available for
                                   the given family.
        :raises KeyError:          Raised when no definition is available for
                                   the given language.
        """
        SectionCreatable.__init__(self)
        self.language = language.lower()
        filename = os.path.join(Constants.language_definitions,
                                language.lower() + ".coalang")
        self.lang_dict = ConfParser().parse(filename)["default"]
Beispiel #9
0
    def __init__(self, language: str, coalang_dir=None):
        """
        Creates a new LanguageDefinition object from file.

        A Language Definition holds constants which may help parsing the
        language. If you want to write a bear you'll probably want to use those
        definitions to keep your bear independent of the semantics of each
        language.

        :param language:           The actual language (e.g. C++).
        :param coalang_dir:        Path to directory with coalang language
                                   definition files. This replaces the default
                                   path if given.
        :raises FileNotFoundError: Raised when no definition is available for
                                   the given language.
        """
        SectionCreatable.__init__(self)
        self.language = language.lower()

        coalang_file = os.path.join(coalang_dir or Constants.language_definitions, self.language + ".coalang")

        self.lang_dict = ConfParser().parse(coalang_file)["default"]
Beispiel #10
0
    def __init__(self, language: str, coalang_dir=None):
        """
        Creates a new LanguageDefinition object from file.

        A Language Definition holds constants which may help parsing the
        language. If you want to write a bear you'll probably want to use those
        definitions to keep your bear independent of the semantics of each
        language.

        :param language:           The actual language (e.g. C++).
        :param coalang_dir:        Path to directory with coalang language
                                   definition files. This replaces the default
                                   path if given.
        :raises FileNotFoundError: Raised when no definition is available for
                                   the given language.
        """
        SectionCreatable.__init__(self)
        self.language = language.lower()

        coalang_file = os.path.join(
            coalang_dir or Constants.language_definitions,
            self.language + ".coalang")

        self.lang_dict = ConfParser().parse(coalang_file)["default"]
 def test_api(self):
     uut = SectionCreatable()
     self.assertRaises(TypeError, uut.from_section, 5)
     self.assertEqual(uut.get_non_optional_settings(), {})
     self.assertEqual(uut.get_optional_settings(), {})
 def test_api(self):
     uut = SectionCreatable()
     self.assertEqual(uut.get_non_optional_settings(), {})
     self.assertEqual(uut.get_optional_settings(), {})
Beispiel #13
0
 def test_api(self):
     uut = SectionCreatable()
     self.assertRaises(TypeError, uut.from_section, 5)
     self.assertEqual(uut.get_non_optional_settings(), {})
     self.assertEqual(uut.get_optional_settings(), {})
Beispiel #14
0
 def __init__(self, log_printer=ConsolePrinter()):
     SectionCreatable.__init__(self)
     self.log_printer = log_printer
     self.file_diff_dict = {}
     self.current_section = None
Beispiel #15
0
 def test_api(self):
     uut = SectionCreatable()
     self.assertEqual(uut.get_non_optional_settings(), {})
     self.assertEqual(uut.get_optional_settings(), {})
Beispiel #16
0
 def __init__(self, log_printer=ConsolePrinter()):
     SectionCreatable.__init__(self)
     self.log_printer = log_printer
     self.file_diff_dict = {}
     self.current_section = None