Skip to content

Commit

Permalink
better function name search
Browse files Browse the repository at this point in the history
  • Loading branch information
ostinelli committed Oct 16, 2012
1 parent c770f52 commit c88f5f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions sublimerl_core.py
Expand Up @@ -146,10 +146,26 @@ def test_path(path):

return True

def strip_code_for_parsing(self, code):
code = self.strip_comments(code)
code = self.strip_quoted_content(code)
return self.strip_record_with_dots(code)

def strip_comments(self, code):
# strip comments but keep the same character count
return re.sub(re.compile(r"%(.*)\n"), lambda m: (len(m.group(0)) - 1) * ' ' + '\n', code)

def strip_quoted_content(self, code):
# strip quoted content
regex = re.compile(r"(\"([^\"]*)\")", re.MULTILINE + re.DOTALL)
for m in regex.finditer(code):
code = code[:m.start()] + (len(m.groups()[0]) * ' ') + code[m.end():]
return code

def strip_record_with_dots(self, code):
# strip records with dot notation
return re.sub(re.compile(r"(\.[a-z]+)"), lambda m: len(m.group(0)) * ' ', code)

def get_erlang_module_name(self, view):
# find module declaration and get module name
module_region = view.find(r"^\s*-\s*module\s*\(\s*(?:[a-zA-Z0-9_]+)\s*\)\s*\.", 0)
Expand Down
8 changes: 4 additions & 4 deletions sublimerl_tests_integration.py
Expand Up @@ -224,12 +224,12 @@ def run(self):
def get_test_function_name(self):
# get current line position
cursor_position = self.view.sel()[0].a

# get module content
region_full = sublime.Region(0, self.view.size())
content = SUBLIMERL.strip_comments(self.view.substr(region_full))

module = SUBLIMERL.strip_code_for_parsing(self.view.substr(region_full))
# parse regions
regex = re.compile(r"([a-z0-9][a-zA-Z0-9_]*_test(_)?\s*\(\s*\)\s*->[^.]*\.)", re.MULTILINE)
for m in regex.finditer(content):
for m in regex.finditer(module):
if m.start() <= cursor_position and cursor_position <= m.end():
function_content = m.groups()[0]
return function_content[:function_content.index('(')]
Expand Down

0 comments on commit c88f5f0

Please sign in to comment.