1 |
joko |
1.1 |
import string |
2 |
|
|
import re |
3 |
|
|
|
4 |
|
|
content=" \ |
5 |
|
|
function abc(abc, def) { \n\ |
6 |
|
|
blah blah \n\ |
7 |
|
|
} \n\ |
8 |
|
|
function huhu(abc, def) { \n\ |
9 |
|
|
blah blah \n\ |
10 |
|
|
} \n\ |
11 |
|
|
sub def(abc, def) { \n\ |
12 |
|
|
blah blah \n\ |
13 |
|
|
} \n\ |
14 |
|
|
function blah(abc, def) { \n\ |
15 |
|
|
blah blah \n\ |
16 |
|
|
} \n\ |
17 |
|
|
" |
18 |
|
|
|
19 |
|
|
|
20 |
|
|
# --------------------------------------------------------- |
21 |
|
|
|
22 |
|
|
sigpart = '(.+?)[\(| ]' |
23 |
|
|
regex_func=re.compile('function ' + sigpart) |
24 |
|
|
regex_sub=re.compile('sub ' + sigpart) |
25 |
|
|
|
26 |
|
|
def get_functionNameFromLine(str): |
27 |
|
|
for regex in (regex_func, regex_sub): |
28 |
|
|
match=regex.search(str) |
29 |
|
|
if match: |
30 |
|
|
return match.group(1) |
31 |
|
|
|
32 |
|
|
def get_allFunctionNames(): |
33 |
|
|
names=[] |
34 |
|
|
lines=string.split(content, "\n") |
35 |
|
|
count=0 |
36 |
|
|
for line in lines: |
37 |
|
|
funcname=get_functionNameFromLine(line) |
38 |
|
|
if funcname: |
39 |
|
|
names.append((funcname, count)) |
40 |
|
|
count=count+1 |
41 |
|
|
return names |
42 |
|
|
|
43 |
|
|
names=get_allFunctionNames() |
44 |
|
|
|
45 |
|
|
# --------------------------------------------------------- |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
# dump names |
49 |
|
|
print names |
50 |
|
|
|
51 |
|
|
# iterate through names |
52 |
|
|
for name in names: |
53 |
|
|
print name |
54 |
|
|
|