\n'
done2.append(namespace[0])
for functions in namespace[1]:
class_func=functions[0].split('.')
if len(class_func)>1:
f_name=''
if class_func[1].find('_')==0:
f_name='
'\
+namespace[0]+''+ "." + ''+class_func[0]+''+'.'+f_name+''+' ( '+ functions[1]+ ' )' +'
\n'
else:
buf+= '
'\
+namespace[0]+''+ "." + ''+class_func[0]+'' +'
\n'
else:
if functions[0].find('_')==0:
f_name='
'+functions[0]+''
else:
f_name=functions[0]
buf+= '
'\
+namespace[0]+''+ "." + ''+f_name+''+ ' ( '+ functions[1]+ ' )' +'
\n'
for comment in functions[2]:
if comment.find('=====')!=-1:
buf+='
'
else:
tempComment = comment.replace('#','').replace('<','<').replace('>','>')
if tempComment.strip()!="":
buf+= '
\n'
buf+='\n'
if namespace[0] not in done2:
buf+='
\n'
buf+=''
fw.write(buf)
fw.close()
def parse_file(filename):
with open(filename,'rb') as fr:
content = fr.readlines()
i=0
retval=[]
classname=""
for line in content:
match=re.search(r'^var\s+([A-Za-z0-9_-]+)\s*=\s*func\s*\(?([A-Za-z0-9_\s,=.\n-]*)\)?',line)
if match is not None:
func_name=match.group(1)
comments=[]
param=match.group(2)
if(line.find(')')==-1 and line.find('(')!=-1):
k=i+1
while(content[k].find(')')==-1):
param+=content[k].rstrip('\n')
k+=1
param+=content[k].split(')')[0]
j=i-1
count=0
while ( j>i-35 and j>-1):
if count>3:
break
if len(content[j])<2:
j-=1
count+=1
continue
if re.search(r'^\s*#',content[j]) is not None:
comments.append(content[j].rstrip('\n'))
j-=1
else:
break
if(len(comments)>1):
comments.reverse()
retval.append((func_name, param,comments))
i+=1
continue
match3=re.search(r'^var\s*([A-Za-z0-9_-]+)\s*=\s*{\s*(\n|})',line)
if match3 is not None:
classname=match3.group(1)
comments=[]
j=i-1
count=0
while ( j>i-35 and j>-1):
if count>3:
break
if len(content[j])<2:
j-=1
count+=1
continue
if re.search(r'^\s*#',content[j]) is not None:
comments.append(content[j].rstrip('\n'))
j-=1
else:
break
if(len(comments)>1):
comments.reverse()
retval.append((classname+'.', '',comments))
i+=1
continue
match2=re.search(r'^\s*([A-Za-z0-9_-]+)\s*:\s*func\s*\(?([A-Za-z0-9_\s,=.\n-]*)\)?',line)
if match2 is not None:
func_name=match2.group(1)
comments=[]
param=match2.group(2)
if(line.find(')')==-1 and line.find('(')!=-1):
k=i+1
while(content[k].find(')')==-1):
param+=content[k].rstrip('\n')
k+=1
param+=content[k].split(')')[0]
j=i-1
count=0
while ( j>i-35 and j>-1):
if count>3:
break
if len(content[j])<2:
j-=1
count+=1
continue
if re.search(r'^\s*#',content[j]) is not None:
comments.append(content[j].rstrip('\n'))
j-=1
else:
break
if(len(comments)>1):
comments.reverse()
if classname =='':
continue
retval.append((classname+'.'+func_name, param,comments))
i+=1
continue
match4=re.search(r'^([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]+)\s*=\s*func\s*\(?([A-Za-z0-9_\s,=\n.-]*)\)?',line)
if match4 is not None:
classname=match4.group(1)
func_name=match4.group(2)
comments=[]
param=match4.group(3)
if(line.find(')')==-1 and line.find('(')!=-1):
k=i+1
while(content[k].find(')')==-1):
param+=content[k].rstrip('\n')
k+=1
param+=content[k].split(')')[0]
j=i-1
count=0
while ( j>i-35 and j>-1):
if count>3:
break
if len(content[j])<2:
j-=1
count+=1
continue
if re.search(r'^\s*#',content[j]) is not None:
comments.append(content[j].rstrip('\n'))
j-=1
else:
break
if(len(comments)>1):
comments.reverse()
retval.append((classname+'.'+func_name, param,comments))
i+=1
continue
i+=1
return retval
if __name__ == "__main__":
if len(sys.argv) <2:
print('Usage: nasal_api_doc.py parse [path to $FGROOT/Nasal/]')
sys.exit()
else:
if sys.argv[1]=='parse':
if len(sys.argv) <3:
nasal_path=NASAL_PATH
else:
nasal_path=sys.argv[2]
get_files(nasal_path)
else:
print('Usage: nasal_api_doc.py parse [path to $FGROOT/Nasal/]')
sys.exit()