Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f2e1cfb

Browse files
committed
Use regex and don't use path
1 parent a93265a commit f2e1cfb

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

Tools/scripts/ptags.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# No warnings about duplicate tags.
1212

1313
import sys
14-
import regexp
15-
import path
14+
import regex
15+
import os
1616

1717
tags = [] # Modified global variable!
1818

@@ -24,24 +24,25 @@ def main():
2424
tags.sort()
2525
for s in tags: fp.write(s)
2626

27-
matcher = regexp.compile('^[ \t]*(def|class)[ \t]+([a-zA-Z0-9_]+)[ \t]*\(')
27+
28+
expr = '^[ \t]*\(def\|class\)[ \t]+\([a-zA-Z0-9_]+\)[ \t]*[:(]'
29+
matcher = regex.compile(expr)
2830

2931
def treat_file(file):
3032
try:
3133
fp = open(file, 'r')
3234
except:
3335
print 'Cannot open', file
3436
return
35-
base = path.basename(file)
37+
base = os.path.basename(file)
3638
if base[-3:] == '.py': base = base[:-3]
3739
s = base + '\t' + file + '\t' + '1\n'
3840
tags.append(s)
3941
while 1:
4042
line = fp.readline()
4143
if not line: break
42-
res = matcher.exec(line)
43-
if res:
44-
(a, b), (a1, b1), (a2, b2) = res
44+
if matcher.search(line) >= 0:
45+
(a, b), (a1, b1), (a2, b2) = matcher.regs[:3]
4546
name = line[a2:b2]
4647
s = name + '\t' + file + '\t/^' + line[a:b] + '/\n'
4748
tags.append(s)

0 commit comments

Comments
 (0)