-
Notifications
You must be signed in to change notification settings - Fork 0
/
treeDebugVisitor.py
70 lines (50 loc) · 2.23 KB
/
treeDebugVisitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Generated from lazyvideo.g4 by ANTLR 4.10.1
from antlr4 import *
if __name__ is not None and "." in __name__:
from .lazyvideoLexer import lazyvideoLexer
from .lazyvideoParser import lazyvideoParser
else:
from lazyvideoLexer import lazyvideoLexer
from lazyvideoParser import lazyvideoParser
# This class defines a complete generic visitor for a parse tree produced by lazyvideoParser.
class TreeDebugVisitor(ParseTreeVisitor):
def msgBuild(self, name, ctx):
msg = name + "("
li = list(ctx.getChildren())
for i in range(len(li)):
msgch = self.visit(li[i])
if msgch != None:
msg += msgch + ","
if msg.endswith(","): msg = msg[:-1]
msg = msg + ")"
return msg
# Visit a parse tree produced by lazyvideoParser#root.
def visitRoot(self, ctx:lazyvideoParser.RootContext):
return self.msgBuild("Root", ctx)
# Visit a parse tree produced by lazyvideoParser#instruction.
def visitInstruction(self, ctx:lazyvideoParser.InstructionContext):
return self.msgBuild("Instruction", ctx)
# Visit a parse tree produced by lazyvideoParser#wordslide.
def visitWordslide(self, ctx:lazyvideoParser.WordslideContext):
return self.msgBuild("WordSlide", ctx)
# Visit a parse tree produced by lazyvideoParser#sentenceslide.
def visitSentenceslide(self, ctx:lazyvideoParser.SentenceslideContext):
return self.msgBuild("SentenceSlide", ctx)
# Visit a parse tree produced by lazyvideoParser#modifiers.
def visitModifiers(self, ctx:lazyvideoParser.ModifiersContext):
return self.msgBuild("Modifiers", ctx)
# Visit a parse tree produced by lazyvideoParser#modifier.
def visitModifier(self, ctx:lazyvideoParser.ModifierContext):
return self.msgBuild("Modifier", ctx)
def main():
text = open("input.txt").read()
print(text)
input_stream = InputStream(text)
lexer = lazyvideoLexer(input_stream)
token_stream = CommonTokenStream(lexer)
parser = lazyvideoParser(token_stream)
tree = parser.root()
debug_visitor = TreeDebugVisitor()
print( debug_visitor.visit(tree) )
if __name__ == "__main__": main()
del lazyvideoParser