OpenADFortTk (SourceProcessing)
|
00001 ''' 00002 specific exceptions that we may want to catch 00003 at the top level rather than the system exceptions 00004 which should continue to produce a stack trace. 00005 ''' 00006 00007 class UserError(Exception): 00008 '''exception for errors caused by the user''' 00009 def __init__(self,msg): 00010 self.msg = msg 00011 00012 def __str__(self): 00013 errString='\nERROR: UserError :'+str(self.msg) 00014 return (errString) 00015 00016 class ScanError(Exception): 00017 ''' 00018 exception for errors detected in the scanner caused either by 00019 faulty code or by incomplete logic in the scanner implementation 00020 ''' 00021 def __init__(self,lineNumber,aFortLine,scanned,rest): 00022 self.lineNumber = lineNumber 00023 self.aFortLine=aFortLine 00024 self.scanned=scanned 00025 self.rest=rest 00026 00027 def __str__(self): 00028 errString='\nERROR: ScanError at line '+str(self.lineNumber)+':\n' 00029 errString+=str(self.aFortLine)+'\n' 00030 errString+=(len(str(self.aFortLine))-len(str(self.rest)))*' '+'^' 00031 errString+="\nTokens scanned ok: "+str(self.scanned)+'\tUnable to scan: "'+str(self.rest)+'"' 00032 if (self.rest == '&' and (config.inputFormat=='fixed')): 00033 errString+="\nThis failure is likely due to running this script on free-formatted code without specifying the --inputFormat=free flag." 00034 else: 00035 errString+="\nThis failure is likely due to possibly legal but unconventional Fortran," 00036 errString+="such as unusual spacing. Please consider modifying your source code." 00037 return str(errString) 00038 00039 class ParseError(Exception): 00040 ''' 00041 exception for errors detected in the parser caused either by 00042 faulty code or by incomplete logic in the parser implementation 00043 ''' 00044 def __init__(self,lineNumber,scannedLine,target,details=None): 00045 ''' 00046 the parser failed to parse scannedLine as a target 00047 where target is some string to indicated verbally what it is 00048 ''' 00049 self.lineNumber = lineNumber 00050 self.scannedLine=scannedLine 00051 self.target=target 00052 self.details=details 00053 00054 def __str__(self): 00055 errString='\nERROR: ParseError: parser fails to assemble tokens in scanned line '+str(self.lineNumber)+':' 00056 errString+=str(self.scannedLine) 00057 if self.details: errString+=str(self.details) 00058 if self.target: errString+="tried to parse as"+str(self.target) 00059 return (errString) 00060 00061 class LogicError(Exception): 00062 ''' 00063 exception for general logic errors 00064 ''' 00065 def __init__(self,reason,lineNumber=None): 00066 ''' 00067 the parser failed to parse scannedLine as a target 00068 where target is some string to indicated verbally what it is 00069 ''' 00070 self.lineNumber = lineNumber 00071 self.reason=reason 00072 00073 def __str__(self): 00074 errString='\nERROR: LogicError: '+str(self.reason) 00075 if self.lineNumber: errString+='line '+str(self.lineNumber) 00076 return (errString)