コード例 #1
0
 def parse_coco_string(data):
     input_stream = antlr4.FileStream(data)
     l = lexer.cocoLexer(input_stream)
     stream = antlr4.CommonTokenStream(l)
     p = parser.cocoParser(stream)
     tree = p.stylesheet()
     visitor = builder.CocoCustomVisitor()
     convention_set = visitor.visitStylesheet(tree)
     return convention_set
コード例 #2
0
def try_get_coco_ast():
    input_stream = antlr4.FileStream(sys.argv[2])
    lexer = cocoLexer.cocoLexer(input_stream)

    stream = antlr4.CommonTokenStream(lexer)
    parser = cocoParser.cocoParser(stream)
    parser.removeParseListeners()
    error_listener = listener.CocoErrorListener()
    parser.addErrorListener(error_listener)
    tree = parser.stylesheet()
    if error_listener.has_errors():
        return False, error_listener.print_errors()
    visitor = ast.CocoCustomVisitor()
    convention_set = visitor.visitStylesheet(tree)
    return True, convention_set