Project Name: google-research+arxiv-latex-cleaner
Language: Python
Statement Type: Assignment

Source Code:
def _find_and_replace_patterns(content, patterns_and_insertions):
  r"""content: str

  patterns_and_insertions: List[Dict]

  Example for patterns_and_insertions:

      [
          {
              "pattern" :
              r"(?:\\figcompfigures{\s*)(?P<first>.*?)\s*}\s*{\s*(?P<second>.*?)\s*}\s*{\s*(?P<third>.*?)\s*}",
              "insertion" :
              r"\parbox[c]{{{second}\linewidth}}{{\includegraphics[width={third}\linewidth]{{figures/{first}}}}}}",
              "description": "Replace figcompfigures"
          },
      ]
  """
  for pattern_and_insertion in patterns_and_insertions:
    pattern = pattern_and_insertion['pattern']
    insertion = pattern_and_insertion['insertion']
    description = pattern_and_insertion['description']
    logging.info('Processing pattern: %s.', description)
    p = regex.compile(pattern)
    m = p.search(content)
    while m is not None:
      local_insertion = insertion.format(**m.groupdict())
      if pattern_and_insertion.get('strip_whitespace', True):
        local_insertion = strip_whitespace(local_insertion)
      logging.info(f'Found {content[m.start():m.end()]:<70}')
      logging.info(f'Replacing with {local_insertion:<30}')
      content = content[: m.start()] + local_insertion + content[m.end() :]
      m = p.search(content)
    logging.info('Finished pattern: %s.', description)
  return content

_find_and_replace_patterns(content='& \\figcompfigures{\n\timage1.jpg\n}{\n\t\\ww\n}{\n\t1.0\n\t}\n& \\figcompfigures{image2.jpg}{\\ww}{1.0}', patterns_and_insertions=[{'pattern': '(?:\\\\figcompfigures{\\s*)(?P<first>.*?)\\s*}\\s*{\\s*(?P<second>.*?)\\s*}\\s*{\\s*(?P<third>.*?)\\s*}', 'insertion': '\\parbox[c]{{\n            {second}\\linewidth\n        }}{{\n            \\includegraphics[\n                width={third}\\linewidth\n            ]{{\n                figures/{first}\n            }}\n        }} ', 'description': 'Replace figcompfigures'}])

Selected Statement: pattern = pattern_and_insertion['pattern']

Function Input:
content: '& \\figcompfigures{\n\timage1.jpg\n}{\n\t\\ww\n}{\n\t1.0\n\t}\n& \\figcompfigures{image2.jpg}{\\ww}{1.0}'
patterns_and_insertions: pattern: (?:\\figcompfigures{\s*)(?P<first>.*?)\s*}\s*{\s*(?P<second>.*?)\s*}\s*{\s*(?P<third>.*?)\s*}
insertion: \parbox[c]{{
            {second}\linewidth
        }}{{
            \includegraphics[
                width={third}\linewidth
            ]{{
                figures/{first}
            }}
        }} 
description: Replace figcompfigures

Variable Values Before Statement:
pattern_and_insertion: pattern: (?:\\figcompfigures{\s*)(?P<first>.*?)\s*}\s*{\s*(?P<second>.*?)\s*}\s*{\s*(?P<third>.*?)\s*}
insertion: \parbox[c]{{
            {second}\linewidth
        }}{{
            \includegraphics[
                width={third}\linewidth
            ]{{
                figures/{first}
            }}
        }} 
description: Replace figcompfigures

Value After Statement Execution: '(?:\\\\figcompfigures{\\s*)(?P<first>.*?)\\s*}\\s*{\\s*(?P<second>.*?)\\s*}\\s*{\\s*(?P<third>.*?)\\s*}'

Variable States During Runtime (line, value):
content: 1
'& \\figcompfigures{\n\timage1.jpg\n}{\n\t\\ww\n}{\n\t1.0\n\t}\n& \\figcompfigures{image2.jpg}{\\ww}{1.0}'
31
'& \\parbox[c]{\\ww\\linewidth}{\\includegraphics[width=1.0\\linewidth]{figures/image1.jpg}}\n& \\figcompfigures{image2.jpg}{\\ww}{1.0}'
31
'& \\parbox[c]{\\ww\\linewidth}{\\includegraphics[width=1.0\\linewidth]{figures/image1.jpg}}\n& \\parbox[c]{\\ww\\linewidth}{\\includegraphics[width=1.0\\linewidth]{figures/image2.jpg}}'
patterns_and_insertions: 1
pattern: (?:\\figcompfigures{\s*)(?P<first>.*?)\s*}\s*{\s*(?P<second>.*?)\s*}\s*{\s*(?P<third>.*?)\s*}
insertion: \parbox[c]{{
            {second}\linewidth
        }}{{
            \includegraphics[
                width={third}\linewidth
            ]{{
                figures/{first}
            }}
        }} 
description: Replace figcompfigures
pattern_and_insertion: 18
pattern: (?:\\figcompfigures{\s*)(?P<first>.*?)\s*}\s*{\s*(?P<second>.*?)\s*}\s*{\s*(?P<third>.*?)\s*}
insertion: \parbox[c]{{
            {second}\linewidth
        }}{{
            \includegraphics[
                width={third}\linewidth
            ]{{
                figures/{first}
            }}
        }} 
description: Replace figcompfigures
pattern: 19
'(?:\\\\figcompfigures{\\s*)(?P<first>.*?)\\s*}\\s*{\\s*(?P<second>.*?)\\s*}\\s*{\\s*(?P<third>.*?)\\s*}'
insertion: 20
'\\parbox[c]{{\n            {second}\\linewidth\n        }}{{\n            \\includegraphics[\n                width={third}\\linewidth\n            ]{{\n                figures/{first}\n            }}\n        }} '
description: 21
'Replace figcompfigures'
p: 23
regex.Regex('(?:\\\\figcompfigures{\\s*)(?P<first>.*?)\\s*}\\s*{\\s*(?P<second>.*?)\\s*}\\s*{\\s*(?P<third>.*?)\\s*}', flags=regex.V0)
m: 24
<regex.Match object; span=(2, 49), match='\\figcompfigures{\n\timage1.jpg\n}{\n\t\\ww\n}{\n\t1.0\n\t}'>
32
<regex.Match object; span=(89, 126), match='\\figcompfigures{image2.jpg}{\\ww}{1.0}'>
32
None
local_insertion: 26
'\\parbox[c]{\n            \\ww\\linewidth\n        }{\n            \\includegraphics[\n                width=1.0\\linewidth\n            ]{\n                figures/image1.jpg\n            }\n        } '
28
'\\parbox[c]{\\ww\\linewidth}{\\includegraphics[width=1.0\\linewidth]{figures/image1.jpg}}'
26
'\\parbox[c]{\n            \\ww\\linewidth\n        }{\n            \\includegraphics[\n                width=1.0\\linewidth\n            ]{\n                figures/image2.jpg\n            }\n        } '
28
'\\parbox[c]{\\ww\\linewidth}{\\includegraphics[width=1.0\\linewidth]{figures/image2.jpg}}'