def clean_headline(self, s, p=None):
'''
Return the cleaned version headline s.
Will typically be overridden in subclasses.
'''
return s.strip()
clean_regex_list1 = [
re.compile(r'\s*\(?(function\b\s*[\w]*)\s*\('),
re.compile(r'\s*([\w]+\:\s*\(*\s*function\s*\()'),
re.compile(r'\s*(?:const|let|var)\s*(\w+\s*(?:=\s*.*)=>)'),
]
clean_regex_list2 = [
re.compile(r'(.*)\((\s*function)'),
re.compile(r'(.*\=)(\s*function)'),
]
def clean_headline(self, s, p=None):
'''Return a cleaned up headline s.'''
s = s.strip()
# Don't clean a headline twice.
if s.endswith('>>') and s.startswith('<<'):
return s
for ch in '{(=':
if s.endswith(ch):
s = s[:-1].strip()
# First regex cleanup.
for pattern in self.clean_regex_list1:
m = pattern.match(s)
if m:
s = m.group(1)
break
# Second regex cleanup.
for pattern in self.clean_regex_list2:
m = pattern.match(s)
if m:
s = m.group(1) + m.group(2)
break
s = s.replace(' ', ' ')
return g.truncate(s, 100)
I am working on improvements [to . Please hold suggestions for a bit.
There are problems assigning lines to nodes.
Edward
Cleaning generated headlines is just a part of the problem. More serious problem is choosing what should go in to single node.
As far as I am concerned, I would much prefer to have a toolbox with several commands to help me importing files on my own. I wrote about that idea here. I don't know when (and if) I would have time to write such a plugin. Solving this serious problem (* importing external source files) in fully automatic but satisfactory way IMHO must involve writing a proper lexer/parser functions at least for .js .jsx, .ts .tsx files. That seems to be a lot of work, so I believe more likely is that I would pursue this simpler idea - a plugin with handful of universal functions for manipulating source code, that user can use to reshape code any way he/she likes. That would work for all kinds of source files.
many (most?) problems with imports can be fixed by hand in the generated @clean tree.