Utilities/ModuleParser.py

changeset 4182
a84cadf71513
parent 4021
195a471c327b
child 4435
9f6555d3c3c0
equal deleted inserted replaced
4180:50fa3b7454e2 4182:a84cadf71513
169 [ \t]* = [ \t]* (?P<VariableSignal> (?:pyqtSignal)? ) 169 [ \t]* = [ \t]* (?P<VariableSignal> (?:pyqtSignal)? )
170 ) 170 )
171 171
172 | (?P<Import> 172 | (?P<Import>
173 ^ [ \t]* (?: import | from [ \t]+ \. [ \t]+ import ) [ \t]+ 173 ^ [ \t]* (?: import | from [ \t]+ \. [ \t]+ import ) [ \t]+
174 (?P<ImportList> (?: [^#;\\\n]+ (?: \\\n )* )* ) 174 (?P<ImportList> (?: [^#;\\\n]* (?: \\\n )* )* )
175 ) 175 )
176 176
177 | (?P<ImportFrom> 177 | (?P<ImportFrom>
178 ^ [ \t]* from [ \t]+ 178 ^ [ \t]* from [ \t]+
179 (?P<ImportFromPath> 179 (?P<ImportFromPath>
182 [ \t]* \. [ \t]* \w+ 182 [ \t]* \. [ \t]* \w+
183 )* 183 )*
184 ) 184 )
185 [ \t]+ 185 [ \t]+
186 import [ \t]+ 186 import [ \t]+
187 (?P<ImportFromList> (?: [^#;\\\n]+ (?: \\\n )* )* ) 187 (?P<ImportFromList>
188 (?: \( \s* .*? \s* \) )
189 |
190 (?: [^#;\\\n]* (?: \\\n )* )* )
188 ) 191 )
189 192
190 | (?P<ConditionalDefine> 193 | (?P<ConditionalDefine>
191 ^ 194 ^
192 (?P<ConditionalDefineIndent> [ \t]* ) 195 (?P<ConditionalDefineIndent> [ \t]* )
764 elif m.start("Import") >= 0: 767 elif m.start("Import") >= 0:
765 # import module 768 # import module
766 names = [n.strip() for n in 769 names = [n.strip() for n in
767 "".join(m.group("ImportList").splitlines()) 770 "".join(m.group("ImportList").splitlines())
768 .replace("\\", "").split(',')] 771 .replace("\\", "").split(',')]
769 for name in names: 772 self.imports.extend(
770 if name not in self.imports: 773 [name for name in names
771 self.imports.append(name) 774 if name not in self.imports])
772 775
773 elif m.start("ImportFrom") >= 0: 776 elif m.start("ImportFrom") >= 0:
774 # from module import stuff 777 # from module import stuff
775 mod = m.group("ImportFromPath") 778 mod = m.group("ImportFromPath")
779 namesLines = (m.group("ImportFromList")
780 .replace("(", "").replace(")", "")
781 .replace("\\", "")
782 .strip().splitlines())
783 namesLines = [line.split("#")[0].strip()
784 for line in namesLines]
776 names = [n.strip() for n in 785 names = [n.strip() for n in
777 "".join(m.group("ImportFromList").splitlines()) 786 "".join(namesLines)
778 .replace("\\", "").split(',')] 787 .split(',')]
779 if mod not in self.from_imports: 788 if mod not in self.from_imports:
780 self.from_imports[mod] = [] 789 self.from_imports[mod] = []
781 self.from_imports[mod].extend(names) 790 self.from_imports[mod].extend(
791 [name for name in names
792 if name not in self.from_imports[mod]])
782 793
783 elif m.start("ConditionalDefine") >= 0: 794 elif m.start("ConditionalDefine") >= 0:
784 # a conditional function/method definition 795 # a conditional function/method definition
785 thisindent = _indent(m.group("ConditionalDefineIndent")) 796 thisindent = _indent(m.group("ConditionalDefineIndent"))
786 while conditionalsstack and \ 797 while conditionalsstack and \

eric ide

mercurial