f90wrap.codegen module

class f90wrap.codegen.CodeGenerator(indent, max_length, continuation, comment)[source]

Bases: object

Simple class to handle code generation.

Handles simple tasks such as indent/dedent and continuation symbols.

Parameters:
  • indent (str) – Specification of the indent size/type. Typical choices may be " "*4 or "  ".

  • max_length (int) – Maximum length of a code line.

  • continuation (str) – Symbol to represent continuation in the desired language (eg. ‘&’ in Fortran)

  • comment (str) – Character used to define comments (e.g. ‘!’ in Fortran, ‘#’ in Python)

dedent()[source]

Dedent code level

indent()[source]

Indent code level

split_long_lines()[source]

Split lines longer than max_length using continuation

Ignores lines starting with comment marker

write(*args)[source]

Write arbitrary string arguments to the instance’s code, split by newline characters and implied newline after last arg.

writelines(items, insert=None, level=None)[source]

Write the given code lines to the instance’s code.

Parameters:
  • items (list of strings) – A list of code lines to be appended to the instance’s code. Newline characters with strings will automatically be propagated into the code.

  • insert (integer or None) – If present, insert lines after index insert rather than appending

  • level (integer or None) – If present, override the current indent level

Returns:

index

Return type:

index for next line to be added (equal to len(code) if insert=None)