Total Complexity | 3 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | """ |
||
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 | |||
63 |