""" Processing of docstrings, which means parsing for types. """

import re

import evaluate
import parsing


#@cache.memoize_default()  # TODO add
def follow_param(param):
    func = param.parent_function
    #print func, param, param.parent_function
    param_str = search_param_in_docstr(func.docstr, str(param.get_name()))

    if param_str is not None:
        p = parsing.PyFuzzyParser(param_str, None, (1, 0), no_docstr=True)
        p.user_stmt.parent = func
        return evaluate.follow_statement(p.user_stmt)
    return []


def search_param_in_docstr(docstr, param_str):
    lines = docstr.split('\n')

    # look at #40 to see definitions of those params
    sphinx_comp = ':type %s:' % param_str
    googley_comp = re.compile('\s*%s\s+\(([^()]+)\)' % re.escape(param_str))
    for l in lines:
        if l.startswith(sphinx_comp):
            return l.replace(sphinx_comp, '', 1).strip()

        r = re.match(googley_comp, l)
        if r is not None:
            return r.group(1)
    return None

@@ -102,16 +102,183 @@
 arsing%0A%0A
+DOCSTRING_PARAM_PATTERNS = %5B%0A    r'%5Cs*:type%5Cs+%25s:%5Cs*(%5B%5Cd%5Cw_%5D+)', # Sphinx%0A    r'%5Cs*@type%5Cs+%25s:%5Cs*(%5B%5Cd%5Cw_%5D+)', # Epidoc%0A    r'%5Cs*%25s%5Cs+%5C((%5B%5E()%5D+)%5C)'         # googley%0A%5D%0A
 %0A#@cache
@@ -775,17 +775,16 @@
 t('%5Cn')%0A
-%0A
     # lo
@@ -836,303 +836,210 @@
     
-sphinx_comp = ':type %25s:' %25 param_str%0A    googley_comp = re.compile('%5Cs*%25s%5Cs+%5C((%5B%5E()%5D+)%5C)' %25 re.escape(param_str))%0A    for l in lines:%0A        if l.startswith(sphinx_comp):%0A            return l.replace(sphinx_comp, '', 1).strip()%0A%0A        r = re.match(googley_comp, l)%0A        if r is not None:%0A
+patterns = %5B re.compile(p %25 re.escape(param_str)) for p in DOCSTRING_PARAM_PATTERNS %5D%0A    for l in lines:%0A        for pattern in patterns:%0A            match = pattern.match(l)%0A            if match:%0A    
     
@@ -1053,17 +1053,21 @@
  return 
-r
+match
 .group(1
@@ -1068,16 +1068,17 @@
 roup(1)%0A
+%0A
     retu

Support for Epydoc format in docstrings