Completed
Push — master ( ffbd85...1e6578 )
by P.R.
01:48
created

SDoc1Interpreter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 21 2
A __init__() 0 11 1
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9
import os
10
11
import antlr4
12
13
from sdoc.antlr.sdoc1Lexer import sdoc1Lexer
14
from sdoc.antlr.sdoc1Parser import sdoc1Parser
15
from sdoc.sdoc1.SDoc1Visitor import SDoc1Visitor
16
17
18
class SDoc1Interpreter:
19
    """
20
    Class for processing SDoc1 documents.
21
    """
22
23
    # ------------------------------------------------------------------------------------------------------------------
24
    def __init__(self, styled_output):
25
        """
26
        Object constructor.
27
        """
28
29
        self._styled_output = styled_output
30
        """
31
        Styled output formatter.
32
33
        :type: sdoc.style.SdocStyle.SdocStyle
34
        """
35
36
    # ------------------------------------------------------------------------------------------------------------------
37
    def process(self, infile, outfile):
38
        """
39
        Processes a SDoc1 document.
40
41
        :param str infile: The input filename with the SDoc1 document.
42
        :param str outfile: The output filename with the SDoc2 document.
43
        """
44
        in_stream = antlr4.FileStream(infile)
45
46
        with open(outfile, 'wt') as out_stream:
47
            lexer = sdoc1Lexer(in_stream)
48
            tokens = antlr4.CommonTokenStream(lexer)
49
            parser = sdoc1Parser(tokens)
50
            tree = parser.sdoc()
51
52
            visitor = SDoc1Visitor(self._styled_output, root_dir=os.path.dirname(os.path.realpath(infile)))
53
54
            visitor.output = out_stream
55
            visitor.visit(tree)
56
57
            return visitor.errors
58
59
# ----------------------------------------------------------------------------------------------------------------------
60