fparser.two.parser

This file provides utilities to create a Fortran parser suitable for a particular standard.

Module Contents

Classes

ParserFactory

Creates a parser suitable for the specified Fortran standard.

Functions

get_module_classes(input_module)

Return all classes local to a module.

fparser.two.parser.get_module_classes(input_module)[source]

Return all classes local to a module.

Parameters:

input_module (module) – the module containing the classes.

Returns:

list of class names and types.

Return type:

List[Tuple[str, type]]

class fparser.two.parser.ParserFactory[source]

Creates a parser suitable for the specified Fortran standard.

create(std=None)[source]

Creates a class hierarchy suitable for the specified Fortran standard. Also sets-up the list of classes that define scoping regions in the global SymbolTables object and clears any existing symbol table information.

Parameters:

std (str) – the Fortran standard. Choices are ‘f2003’ or ‘f2008’. ‘f2003’ is the default.

Returns:

a Program class (not object) for use with the Fortran reader

Return type:

fparser.two.Fortran2003.Program

Raises:

ValueError – if the supplied value for the std parameter is invalid

For example:

>>> from fparser.two.parser import ParserFactory
>>> f2003_parser = ParserFactory().create()
>>> f2003_parser = ParserFactory().create(std='f2003')
>>> f2008_parser = ParserFactory().create(std='f2008')
>>> # Assuming that a reader has already been created ...
>>> ast = f2008_parser(reader)
>>> print(ast)
_setup(input_classes)[source]

Perform some Python magic to create the connections between classes and populate the baseclass with this information. This has been lifted from the original implementation and no attempt has been made to tidy up the code, other than making it conformant to the coding rules.

Parameters:

input_classes (list) – a list of tuples each containing a class name and a class.