Test Failed
Push — master ( a9d702...2d3582 )
by P.R.
02:02
created

SDoc1Interpreter.process()   B

Complexity

Conditions 2

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 8.9713
cc 2
crap 2
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9 1
import os
10
11 1
import antlr4
12
13 1
from sdoc.antlr.sdoc1Lexer import sdoc1Lexer
14 1
from sdoc.antlr.sdoc1Parser import sdoc1Parser
15 1
from sdoc.sdoc1.SDoc1Visitor import SDoc1Visitor
16
17
18 1
class SDoc1Interpreter:
19
    """
20
    Class for processing SDoc1 documents.
21
    """
22
23
    # ------------------------------------------------------------------------------------------------------------------
24 1
    def __init__(self, io):
25
        """
26
        Object constructor.
27
        """
28
29 1
        self._io = io
30 1
        """
31
        Styled output formatter.
32
33
        :type: sdoc.style.SdocStyle.SdocStyle
34
        """
35
36
    # ------------------------------------------------------------------------------------------------------------------
37 1
    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 1
        :rtype: int
45
        """
46 1
        in_stream = antlr4.FileStream(infile)
47 1
48 1
        self._io.writeln('Writing <fso>{0!s}</fso>'.format(outfile))
49 1
        with open(outfile, 'wt') as out_stream:
50 1
            lexer = sdoc1Lexer(in_stream)
51 1
            tokens = antlr4.CommonTokenStream(lexer)
52
            parser = sdoc1Parser(tokens)
53 1
            tree = parser.sdoc()
54
55 1
            visitor = SDoc1Visitor(self._io, root_dir=os.path.dirname(os.path.realpath(infile)))
56 1
57
            visitor.output = out_stream
58 1
            visitor.visit(tree)
59
60
            return visitor.errors
61
62
# ----------------------------------------------------------------------------------------------------------------------
63