Failed Conditions
Pull Request — master (#1127)
by Mischa
01:56
created

replace_tabs_with_spaces()   B

Complexity

Conditions 4

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 27
rs 8.5806
1
import os
2
3
from coalib.bearlib.abstractions.SectionCreatable import SectionCreatable
4
from coalib.misc.Constants import Constants
5
from coalib.parsing.ConfParser import ConfParser
6
7
8
class LanguageDefinition(SectionCreatable):
9
    def __init__(self, language_family: str, language: str):
10
        """
11
        Creates a new LanguageDefinition object from file.
12
13
        A Language Definition holds constants which may help parsing the
14
        language. If you want to write a bear you'll probably want to use those
15
        definitions to keep your bear independent of the semantics of each
16
        language.
17
18
        :param language_family:    The language family. E.g. C for C++ and C
19
                                   and C# and so on.
20
        :param language:           The actual language (e.g. C++).
21
        :raises FileNotFoundError: Raised when no definition is available for
22
                                   the given family. This is a compatability
23
                                   exception from module
24
                                   `coalib.misc.Compatability`.
25
        :raises KeyError:          Raised when no definition is available for
26
                                   the given language.
27
        """
28
        SectionCreatable.__init__(self)
29
        self.language = language.lower()
30
        filename = os.path.join(Constants.language_definitions,
31
                                language_family.lower() + ".coalang")
32
        self.lang_dict = ConfParser().parse(filename)[language.lower()]
33
34
    def __getitem__(self, item):
35
        return self.lang_dict[item]
36