| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
om> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
import re |
| 21 |
|
| 22 |
|
| 23 |
autolist = [ |
| 24 |
(r'^\s*(?:class|typedef|struct|union|namespace)\s+([\w_]+)|\b([\w_]+)\s*\(', |
| 25 |
('.h', '.hh', '.hpp', '.hxx')), |
| 26 |
(r'(?<=typedef)\s+(?:struct|union)\s+([\w_]+)', |
| 27 |
('.h', '.hh', '.hpp', '.hxx', '.c')), |
| 28 |
(r'\b(([\w_]+)::([\w_]+))|\b([\w_]+)\s*\(', |
| 29 |
('.cpp', '.cc', '.c', '.cxx')), |
| 30 |
(r'(?:(?:prototype\.|this\.)(\w+)\s*=\s*)?function\s*(?:(\w*)\s*)\(', |
| 31 |
('.js',)), |
| 32 |
(r'(\w+)\s+=\s+(?:class|record|interface)|(?:procedure|function|property|constructor)\s+(\w+)', |
| 33 |
('.pas',)), |
| 34 |
(r'^\s*(?:class|def)\s+(\w+)', |
| 35 |
('.py', '.pyw', '.rb')), |
| 36 |
(r'(\w+)\s*=\s*', |
| 37 |
('.py', '.pyw')), |
| 38 |
(r'^\s*sub\s+(\w+)|\s*(?:package|use)\s+([\w\:]+)', |
| 39 |
('.pl', '.pm')), |
| 40 |
(r'^\s*class\s+(\w+)|^\s*(?:(?:public|private|)\s+function)\s+(\w+)|::(\w+)|->(\w+)', |
| 41 |
('.php',)), |
| 42 |
(r'(?:class|function|sub)\s+(\w+)(?:\s*(?:[\(\']|$))', |
| 43 |
('.vb', '.vb6')), |
| 44 |
(r'^\s*(?:(?:Public (?:Default )?|Private )?(?:Sub|Function|Property Get|Property Set|Property Let) ?)(\w+)\(|^Attribute VB_Name = "(\w+)"', |
| 45 |
('.bas', '.frm', '.cls')), |
| 46 |
(r'(?:public|protected|private|internal)\s+(?:[\w\d_\.]+\s+)*([\w\d_\.]+)', |
| 47 |
('.cs', '.asp', '.aspx')), |
| 48 |
(r'class\s+([\w_]+)(?:(?:\s+)?(?:extends|implements)(?:\s+)?([\w_]+)?)', |
| 49 |
('.java',)), |
| 50 |
(r'(?:public|protected|private|internal)\s+(?:[\w\d_\.]+\s+)*([\w\d_\.]+)', |
| 51 |
('.java',)), |
| 52 |
(r'^.{6} ([A-Z][A-Z0-9-]*)(?: SECTION)?\.', |
| 53 |
('.cbl', '.cpy')), |
| 54 |
(r'Func\s+([\w_]+)|\$([\w_]+)', |
| 55 |
('.au3', '.auh')), |
| 56 |
(r'^([\w]+) *', |
| 57 |
('.asm',)), |
| 58 |
] |
| 59 |
|
| 60 |
_autolist_map = {} |
| 61 |
|
| 62 |
|
| 63 |
class AutocompleteWordListBuilder(object): |
| 64 |
|
| 65 |
def __init__(self): |
| 66 |
self.regexes = [] |
| 67 |
self.compiled_regexes = None |
| 68 |
|
| 69 |
def compile_regexes(self): |
| 70 |
if self.compiled_regexes is None: |
| 71 |
self.compiled_regexes = list(map(re.compile, self.regexes)) |
| 72 |
|
| 73 |
def iter_words(self, file): |
| 74 |
self.compile_regexes() |
| 75 |
for line in file: |
| 76 |
for regex in self.compiled_regexes: |
| 77 |
for result in regex.findall(line): |
| 78 |
if not isinstance(result, tuple): |
| 79 |
result = (result,) |
| 80 |
for word in [_f for _f in result if _f]: |
| 81 |
yield word |
| 82 |
|
| 83 |
|
| 84 |
def get_wordlist_builder(ext): |
| 85 |
if not _autolist_map: |
| 86 |
for regex, extensions in autolist: |
| 87 |
for extension in extensions: |
| 88 |
if extension not in _autolist_map: |
| 89 |
_autolist_map[extension] = AutocompleteWordListBuilder() |
| 90 |
_autolist_map[extension].regexes.append(regex) |
| 91 |
return _autolist_map.get(ext) |