def visitEntityImport(self, ctx:AHParser.EntityImportContext): imports = [] originModuleName = self.visit(ctx.qualifiedName()) for importedNameCtx in ctx.importedName(): ie = ImportedEntity() ie.originModuleName = originModuleName ie.originName, ie.importedName = self.visit(importedNameCtx) imports.append(ie) return ParsedDataExtractor.ImportList(imports)
def visitModuleImport(self, ctx:AHParser.ModuleImportContext): ie = ImportedEntity() ie.originModuleName = self.visit(ctx.qualifiedName()) ie.originName = ie.originModuleName[-1] renaming = ctx.ID() assert len(renaming) == 0 or len(renaming) == 2 if len(renaming) == 0: ie.importedName = ie.originName elif len(renaming) == 2: asWord, importedName = renaming if asWord != 'as': raise SyntaxError("Unexpected token {} when 'as' was expected " "in module import context" .format(asWord)) ie.importedName = importedName return ie