Issues (60)

sdoc/sdoc1/SDoc1Interpreter.py (1 issue)

1 1
import os
2
3 1
import antlr4
4 1
from cleo.io.io import IO
5
6 1
from sdoc.antlr.sdoc1Lexer import sdoc1Lexer
7 1
from sdoc.antlr.sdoc1Parser import sdoc1Parser
8 1
from sdoc.sdoc1.SDoc1Visitor import SDoc1Visitor
9
10
11 1 View Code Duplication
class SDoc1Interpreter:
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
12
    """
13
    Class for processing SDoc1 documents.
14
    """
15
16
    # ------------------------------------------------------------------------------------------------------------------
17 1
    def __init__(self, io: IO):
18
        """
19
        Object constructor.
20
        """
21
22 1
        self._io: IO = io
23 1
        """
24
        Styled output formatter.
25
        """
26
27
    # ------------------------------------------------------------------------------------------------------------------
28 1
    def process(self, infile: str, outfile: str) -> int:
29
        """
30
        Processes a SDoc1 document.
31
32
        :param str infile: The input filename with the SDoc1 document.
33
        :param str outfile: The output filename with the SDoc2 document.
34
        """
35 1
        in_stream = antlr4.FileStream(infile)
36
37 1
        self._io.write_line('Writing <fso>{0!s}</fso>'.format(outfile))
38 1
        with open(outfile, 'wt') as out_stream:
39 1
            lexer = sdoc1Lexer(in_stream)
40 1
            tokens = antlr4.CommonTokenStream(lexer)
41 1
            parser = sdoc1Parser(tokens)
42 1
            tree = parser.sdoc()
43
44 1
            visitor = SDoc1Visitor(self._io, root_dir=os.path.dirname(os.path.realpath(infile)))
45
46 1
            visitor.output = out_stream
47 1
            visitor.visit(tree)
48
49 1
            return visitor.errors
50
51
# ----------------------------------------------------------------------------------------------------------------------
52