def parse_cpp_files(test_directory):
  file_list = []
  snippet_list = {}
  for path, dirs, files in os.walk(test_directory):
    for cpp_file in files:
      if not re.match(r'.*\.c(pp|c)$', cpp_file): continue
      parse_lines = False
      snippet_lines = []
      token = ''
      md_file = ''
      cpp_file_path = os.path.join(path, cpp_file)
      try:
        with open(cpp_file_path, 'r') as ccfile:
          for line in ccfile:
            match = CPPDOXYSNIPPETSTART_RE.match(line)
            if match:
              parse_lines = True
              group_dict = match.groupdict()
              md_file = group_dict['md_file']
              token = group_dict['token']
              if md_file not in file_list:
                file_list.append(md_file)
            elif DOXYSNIPPETEND_RE.match(line):
              parse_lines = False
              snippet_list[token] = snippet_lines
            elif parse_lines:
              snippet_lines.append(line)
      except IOError as e:
        print 'ERROR: Failed to open file %s: %s' % (cpp_file, e.strerror)
      if parse_lines is True:
        print 'WARNING: Count not find end of %s. Skipping.' % (token)
  return (file_list, snippet_list)
Parse cpp files looking for snippet marks.
dataset/ETHPy150Open google/fplutil/docs/update_code_snippets.py/parse_cpp_files