def scan_input_file()

in swig_commenter.py [0:0]


def scan_input_file(comments, input_filename):
  """Scan a file for comments prepended to classes, structs and namespaces.

  Scans each line of the given file, looking for block of Doxygen comments (that
  is, lines that start with '///') which appear immediately before a class,
  struct or namespace declaration. Each match is stored in the given dict using
  the name identifier as the key and the comment as the value.

  Namespaces are handled slightly differently. Because our namespaces in C++
  map to classes in C# (but with different casing rules) we convert the
  namespace name from snake_case to CamelCase.

  Args:
    comments: A dict mapping C# class names to the comments that should be
        prepended to them.
    input_filename: The name of the file to scan for comments.
  """
  with open(input_filename, 'r') as input_file:
    most_recent_comment = []
    most_recent_enum = None
    for line in input_file:
      captures = []
      parsing_comment = False
      if line.strip().startswith('///'):
        most_recent_comment.append(line)
        parsing_comment = True
      elif line.strip().startswith('//'):
        # Filter out non-doxygen comment lines.
        pass
      elif extract_regex_captures(captures, CPP_CLASS_DECLARATION_REGEX, line):
        class_name = captures[0]
        # This handles replacing forward declarations with no docs.
        comments['classes'][class_name] = comments['classes'].get(
            class_name, '') or ''.join(most_recent_comment)
      elif extract_regex_captures(captures, CPP_NAMESPACE_DECLARATION_REGEX,
                                  line):
        # The C++ namespace is converted to a C# class.
        class_name = FLAGS.namespace_prefix + snake_case_to_camel_case(
            captures[0])
        comments['classes'][class_name] = ''.join(most_recent_comment)
      elif extract_regex_captures(captures, CPP_ENUM_DECLARATION_REGEX, line):
        enum_name = captures[0]
        most_recent_enum = {
            'comment': ''.join(most_recent_comment),
            'values': {}
        }
        comments['enums'][enum_name] = most_recent_enum
      elif extract_regex_captures(captures, CPP_GLOBAL_STRING_REGEX, line):
        property_name = captures[0]
        comments['properties'][property_name] = ''.join(most_recent_comment)
      elif most_recent_enum and '};' in line:
        most_recent_enum = None
      elif most_recent_enum and extract_regex_captures(
          captures, CPP_ENUM_VALUE_IDENTIFIER_REGEX, line):
        identifier = captures[0]
        most_recent_enum['values'][identifier] = ''.join(most_recent_comment)
      if not parsing_comment:
        most_recent_comment = []