fparser.two.Fortran2003

Fortran 2003 Syntax Rules.

Module Contents

Classes

Comment

Represents a Fortran Comment.

Program

Fortran 2003 rule R201:

Include_Filename

Implements the matching of a filename from an include statement.

Include_Stmt

Implements the matching of a Fortran include statement. There is no

Program_Unit

Fortran 2003 Rule R202:

External_Subprogram

Fortran2003 Rule R203:

Specification_Part

Fortran2003 Rule R204:

Implicit_Part

Fortran2003 Rule R205:

Implicit_Part_Stmt

Fortran2003 Rule R206:

Declaration_Construct

Fortran 2003 rule R207:

Execution_Part

Fortran2003 Rule R208:

Execution_Part_Construct

Execution_Part_Construct_C201

Base class for Fortran 2003 syntax rules.

Internal_Subprogram_Part

Internal_Subprogram

Specification_Stmt

Executable_Construct

Fortran 2003 rule R213:

Executable_Construct_C201

Base class for Fortran 2003 syntax rules.

Action_Stmt

Action_Stmt_C201

Action_Stmt_C802

Action_Stmt_C824

Keyword

Name

Fortran 2003 rule R304:

Constant

Literal_Constant

Named_Constant

Int_Constant

Char_Constant

Defined_Operator

Fortran 2003 rule R311:

Extended_Intrinsic_Op

Fortran 2003 rule R312:

Label

Type_Spec

Type_Param_Value

Fortran 2003 Rule 402:

Intrinsic_Type_Spec

Kind_Selector

Fortran 2003 rule R404:

Signed_Int_Literal_Constant

Int_Literal_Constant

Digit_String

Boz_Literal_Constant

Binary_Constant

Octal_Constant

Hex_Constant

Signed_Real_Literal_Constant

Real_Literal_Constant

Complex_Literal_Constant

Real_Part

Imag_Part

Char_Selector

Length_Selector

Char_Length

Char_Literal_Constant

Fortran 2003 rule R427:

Logical_Literal_Constant

Derived_Type_Def

Derived_Type_Stmt

Fortran 2003 rule R430:

Type_Name

Type_Attr_Spec

Private_Or_Sequence

End_Type_Stmt

Sequence_Stmt

Type_Param_Def_Stmt

Type_Param_Decl

Type_Param_Attr_Spec

Component_Part

Component_Def_Stmt

Data_Component_Def_Stmt

Fortran 2003 rule 440:

Dimension_Component_Attr_Spec

Component_Attr_Spec

Component_Decl

Component_Array_Spec

Component_Initialization

Proc_Component_Def_Stmt

Proc_Component_PASS_Arg_Name

Proc_Component_Attr_Spec

Private_Components_Stmt

Fortran2003 Rule R447:

Type_Bound_Procedure_Part

Fortran 2003 rule R448.

Binding_Private_Stmt

Fortran2003 Rule R449:

Proc_Binding_Stmt

Fortran2003 Rule R450:

Specific_Binding

Fortran2003 Rule R451:

Binding_PASS_Arg_Name

Fortran 2003 helper rule (for R453):

Generic_Binding

Fortran2003 Rule R452:

Binding_Attr

Fortran2003 Rule R453:

Final_Binding

Fortran2003 Rule R454:

Derived_Type_Spec

Type_Param_Spec

Structure_Constructor

Component_Spec

Component_Data_Source

Enum_Def

Enum_Def_Stmt

Enumerator_Def_Stmt

Enumerator

End_Enum_Stmt

Array_Constructor

Ac_Spec

Ac_Value

Ac_Implied_Do

Fortran2003 rule R470.

Ac_Implied_Do_Control

Fortran2003 rule R471.

Ac_Do_Variable

Fortran2003 rule R472.

Type_Declaration_Stmt

Fortran 2003 rule 501:

Declaration_Type_Spec

Dimension_Attr_Spec

Intent_Attr_Spec

Attr_Spec

Entity_Decl

Object_Name

Initialization

Null_Init

Access_Spec

Fortran2003 Rule R508:

Language_Binding_Spec

Fortran2003 Rule R509:

Array_Spec

Fortran2003 Rule R510:

Explicit_Shape_Spec

Lower_Bound

Upper_Bound

Assumed_Shape_Spec

Fortran2003 Rule R514:

Deferred_Shape_Spec

Fortran2003 Rule R515:

Assumed_Size_Spec

Fortran2003 Rule R516:

Intent_Spec

Access_Stmt

Fortran2003 Rule R518:

Access_Id

Fortran2003 Rule R519:

Object_Name_Deferred_Shape_Spec_List_Item

Allocatable_Stmt

Fortran2003 Rule R520:

Asynchronous_Stmt

Fortran2003 Rule R521:

Bind_Stmt

Fortran2003 Rule R522:

Bind_Entity

Data_Stmt

Fortran 2003 Rule R524:

Data_Stmt_Set

Fortran2003 Rule R525:

Data_Stmt_Object

Fortran 2003 Rule R526:

Data_Implied_Do

Fortran 2003 Rule R527:

Data_I_Do_Object

Data_I_Do_Variable

Data_Stmt_Value

Data_Stmt_Repeat

Data_Stmt_Constant

Fortran 2003 Rule R532:

Int_Constant_Subobject

Fortran 2003 Rule R533:

Constant_Subobject

Fortran 2003 Rule R534:

Dimension_Stmt

Fortran 2003 Rule R535:

Intent_Stmt

Optional_Stmt

Parameter_Stmt

Named_Constant_Def

Cray_Pointer_Stmt

Cray_Pointer_Decl

Cray_Pointee_Decl

Cray_Pointee_Array_Spec

Pointer_Stmt

Pointer_Decl

Protected_Stmt

Save_Stmt

Saved_Entity

Proc_Pointer_Name

Target_Entity_Decl

Target_Stmt

Value_Stmt

Volatile_Stmt

Implicit_Stmt

Implicit_Spec

Letter_Spec

Namelist_Stmt

Fortran 2003 rule R552:

Namelist_Group_Object

Equivalence_Stmt

Equivalence_Set

Equivalence_Object

Common_Stmt

Common_Block_Object

Variable

Variable_Name

Designator

Fortran 2003 rule R603:

Logical_Variable

Default_Logical_Variable

Char_Variable

Default_Char_Variable

Int_Variable

Substring

Parent_String

Substring_Range

Data_Ref

Fortran 2003 Rule R612:

Part_Ref

Structure_Component

Type_Param_Inquiry

Array_Element

Array_Section

Subscript

Section_Subscript

Subscript_Triplet

Stride

Vector_Subscript

Allocate_Stmt

Fortran2003 rule R623:

Stat_Variable

Errmsg_Variable

Source_Expr

Alloc_Opt

Allocation

Allocate_Object

Allocate_Shape_Spec

Lower_Bound_Expr

Upper_Bound_Expr

Nullify_Stmt

Pointer_Object

Deallocate_Stmt

Dealloc_Opt

Scalar_Char_Initialization_Expr

Base class for Fortran 2003 syntax rules.

Primary

Fortran 2003 rule R701:

Parenthesis

Part of Fortran 2003 rule R701:

Level_1_Expr

Defined_Unary_Op

Fortran 2003 rule R703:

Defined_Op

Utility class that Implements the functionality of rules R703 and

Mult_Operand

Add_Operand

Fortran 2003 rule R705:

Level_2_Expr

Level_2_Unary_Expr

Level_3_Expr

Level_4_Expr

And_Operand

Or_Operand

Equiv_Operand

Level_5_Expr

Expr

Defined_Binary_Op

Fortran 2003 rule R723:

Logical_Expr

Fortran 2003 rule R724:

Char_Expr

Fortran 2003 rule R725:

Default_Char_Expr

Fortran 2003 rule R726:

Int_Expr

Fortran 2003 rule R727:

Numeric_Expr

Fortran 2003 rule R728:

Specification_Expr

Initialization_Expr

Char_Initialization_Expr

Int_Initialization_Expr

Logical_Initialization_Expr

Assignment_Stmt

Pointer_Assignment_Stmt

Data_Pointer_Object

Bounds_Spec

Bounds_Remapping

Data_Target

Proc_Pointer_Object

Proc_Component_Ref

Proc_Target

Where_Stmt

Where_Construct

Where_Construct_Stmt

Where_Body_Construct

Where_Assignment_Stmt

Mask_Expr

<mask-expr> = <logical-expr>

Masked_Elsewhere_Stmt

Elsewhere_Stmt

<elsewhere-stmt> = ELSEWHERE [ <where-construct-name> ]

End_Where_Stmt

<end-where-stmt> = END WHERE [ <where-construct-name> ]

Forall_Construct

Forall_Construct_Stmt

Forall_Header

Fortran 2003 rule R754:

Forall_Triplet_Spec

Forall_Body_Construct

Forall_Assignment_Stmt

End_Forall_Stmt

<end-forall-stmt> = END FORALL [ <forall-construct-name> ]

Forall_Stmt

Fortran 2003 rule R759:

Block

<block> = [ <execution-part-construct> ]...

If_Construct

If_Then_Stmt

Else_If_Stmt

Else_Stmt

<else-stmt> = ELSE [ <if-construct-name> ]

End_If_Stmt

<end-if-stmt> = END IF [ <if-construct-name> ]

If_Stmt

Fortran 2003 rule R807:

Case_Construct

Select_Case_Stmt

Case_Stmt

<case-stmt> = CASE <case-selector> [ <case-construct-name> ]

End_Select_Stmt

<end-select-stmt> = END SELECT [ <case-construct-name> ]

Case_Expr

Case_Selector

Case_Value_Range

Case_Value

Associate_Construct

Associate_Stmt

Association

<association> = <associate-name> => <selector>

Selector

End_Associate_Stmt

<end-associate-stmt> = END ASSOCIATE [ <associate-construct-name> ]

Select_Type_Construct

Select_Type_Stmt

Type_Guard_Stmt

End_Select_Type_Stmt

<end-select-type-stmt> = END SELECT [ <select-construct-name> ]

Do_Construct

R825:

Block_Do_Construct

R826:

Block_Label_Do_Construct

R826_1:

Block_Nonlabel_Do_Construct

R826_2:

Do_Stmt

R827:

Label_Do_Stmt

R828:

Nonlabel_Do_Stmt

R829:

Loop_Control

Fortran 2003 rule R830

Do_Variable

R831:

Do_Block

R832:

End_Do

R833:

End_Do_Stmt

R834:

Nonblock_Do_Construct

R835:

Action_Term_Do_Construct

Do_Body

<do-body> = [ <execution-part-construct> ]...

Do_Term_Action_Stmt

Outer_Shared_Do_Construct

Shared_Term_Do_Construct

Inner_Shared_Do_Construct

Do_Term_Shared_Stmt

Cycle_Stmt

<cycle-stmt> = CYCLE [ <do-construct-name> ]

Exit_Stmt

<exit-stmt> = EXIT [ <do-construct-name> ]

Goto_Stmt

<goto-stmt> = GO TO <label>

Computed_Goto_Stmt

<computed-goto-stmt> = GO TO ( <label-list> ) [ , ] <scalar-int-expr>

Arithmetic_If_Stmt

Continue_Stmt

<continue-stmt> = CONTINUE

Stop_Stmt

<stop-stmt> = STOP [ <stop-code> ]

Stop_Code

Io_Unit

File_Unit_Number

<file-unit-number> = <scalar-int-expr>

Internal_File_Variable

Open_Stmt

R904 is:

Connect_Spec

R905 is:

File_Name_Expr

<file-name-expr> = <scalar-default-char-expr>

Iomsg_Variable

<iomsg-variable> = <scalar-default-char-variable>

Close_Stmt

<close-stmt> = CLOSE ( <close-spec-list> )

Close_Spec

Read_Stmt

Fortran2003 Rule R910:

Write_Stmt

Fortran 2003 rule R911.

Print_Stmt

Fortran2003 Rule R912:

Io_Control_Spec_List

Rule 913 - Control information list:

Io_Control_Spec

This class implements partial support for Rule 913:

Format

Input_Item

Output_Item

Io_Implied_Do

Io_Implied_Do_Object

Io_Implied_Do_Control

Dtv_Type_Spec

Wait_Stmt

<wait-stmt> = WAIT ( <wait-spec-list> )

Wait_Spec

Backspace_Stmt

Fortran2003 Rule R923:

Endfile_Stmt

Fortran2003 Rule R924:

Rewind_Stmt

Fortran2003 Rule R925:

Position_Spec

Flush_Stmt

Fortran2003 Rule R927:

Flush_Spec

Fortran2003 Rule R928:

Inquire_Stmt

Fortran2003 Rule R929:

Inquire_Spec

Fortran2003 Rule R930:

Format_Stmt

<format-stmt> = FORMAT <format-specification>

Format_Item_List

This class replaces the one generated by fparser. This class is

Format_Specification

Fortran 2003 rule R1002:

Format_Item_C1002

Fortran 2003 constraint C1002:

Hollerith_Item

Hollerith strings take the form nHx, where n is an integer and

Format_Item

Fortran 2003 rule R1003:

R

Data_Edit_Desc_C1002

This class helps implement the matching for the first part of the

Data_Edit_Desc

W

M

D

E

V

Control_Edit_Desc

Fortran 2003 rule R1011:

K

Position_Edit_Desc

Fortran 2003 rule R1013:

N

Sign_Edit_Desc

Blank_Interp_Edit_Desc

Round_Edit_Desc

Decimal_Edit_Desc

<decimal-edit-desc> = DC

Char_String_Edit_Desc

<char-string-edit-desc> = <char-literal-constant>

Main_Program

Fortran 2003 rule R1101:

Main_Program0

Rule 1101 specifies that the opening 'program-stmt' is optional. This

Program_Stmt

Fortran 2003 rule R1102:

End_Program_Stmt

<end-program-stmt> = END [ PROGRAM [ <program-name> ] ]

Module

Module_Stmt

<module-stmt> = MODULE <module-name>

End_Module_Stmt

<end-module-stmt> = END [ MODULE [ <module-name> ] ]

Module_Subprogram_Part

Module_Subprogram

Use_Stmt

Fortran 2003 rule R1109:

Module_Nature

R1110:

Rename

Class defining Rule #R1111:

Only

Only_Use_Name

Local_Defined_Operator

Use_Defined_Operator

Block_Data

Block_Data_Stmt

End_Block_Data_Stmt

Interface_Block

Interface_Specification

Interface_Stmt

End_Interface_Stmt

Function_Body

Subroutine_Body

Interface_Body

Procedure_Stmt

Generic_Spec

Dtio_Generic_Spec

Import_Stmt

Fortran 2003 rule R1209:

External_Stmt

Procedure_Declaration_Stmt

Proc_Interface

Proc_Attr_Spec

Proc_Decl

Interface_Name

<interface-name> = <name>

Intrinsic_Stmt

Function_Reference

<function-reference> = <procedure-designator>

Intrinsic_Name

Represents the name of a Fortran intrinsic function.

Intrinsic_Function_Reference

Represents Fortran intrinsics:

Call_Stmt

Procedure_Designator

Actual_Arg_Spec

<actual-arg-spec> = [ <keyword> = ] <actual-arg>

Actual_Arg

Alt_Return_Spec

Function_Subprogram

Function_Stmt

Proc_Language_Binding_Spec

<proc-language-binding-spec> = <language-binding-spec>

Dummy_Arg_Name

<dummy-arg-name> = <name>

Prefix

Fortran2003 rule R1227:

Prefix_Spec

Suffix

End_Function_Stmt

<end-function-stmt> = END [ FUNCTION [ <function-name> ] ]

Subroutine_Subprogram

Subroutine_Stmt

Fortran2003 rule R1232:

Dummy_Arg

End_Subroutine_Stmt

<end-subroutine-stmt> = END [ SUBROUTINE [ <subroutine-name> ] ]

Entry_Stmt

Return_Stmt

<return-stmt> = RETURN [ <scalar-int-expr> ]

Contains_Stmt

<contains-stmt> = CONTAINS

Stmt_Function_Stmt

Functions

match_comment_or_include(reader)

Creates a comment or include object from the current line.

add_comments_includes_directives(content, reader)

Creates comment, include, and/or cpp directive objects and adds them to

skip_digits(string)

Skips over any potential digits (including spaces) to the next

c1242_valid(prefix, binding_spec)

If prefix and binding-spec exist then check whether they conform to

Attributes

ClassType

_names

my_cls

classes

__all__

class fparser.two.Fortran2003.Comment(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Represents a Fortran Comment.

subclass_names = [][source]
init(comment)[source]

Initialise this Comment

Parameters:

comment (readfortran.Comment) – The comment object produced by the reader

tostr()[source]
Returns:

this comment as a string.

Return type:

str

restore_reader(reader)[source]

Undo the read of this comment by putting its content back into the reader (which has a FIFO buffer)

Parameters:

reader (fparser.readfortran.FortranReaderBase) – the reader instance to return the comment to

fparser.two.Fortran2003.match_comment_or_include(reader)[source]

Creates a comment or include object from the current line.

Parameters:

reader (fparser.common.readfortran.FortranFileReader or fparser.common.readfortran.FortranStringReader) – the fortran file reader containing the line of code that we are trying to match

Returns:

a comment or include object if found, otherwise None.

Return type:

fparser.two.Fortran2003.Comment or fparser.two.Fortran2003.Include_Stmt

fparser.two.Fortran2003.add_comments_includes_directives(content, reader)[source]

Creates comment, include, and/or cpp directive objects and adds them to the content list. Comment, include, and/or directive objects are added until a line that is not a comment, include, or directive is found.

Parameters:
class fparser.two.Fortran2003.Program(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

Fortran 2003 rule R201:

program is program-unit
           [ program-unit ] ...
subclass_names = [][source]
use_names = ['Program_Unit'][source]
static match(reader)[source]

Implements the matching for a Program. Whilst the rule looks like it could make use of BlockBase, the parser must not match if an optional program_unit has a syntax error, which the BlockBase match implementation does not do.

Parameters:

reader (fparser.common.readfortran.FortranFileReader or fparser.common.readfortran.FortranStringReader) – the fortran file reader containing the line(s) of code that we are trying to match

Returns:

tuple containing a single list which contains instance of the classes that have matched if there is a match or None if there is no match

class fparser.two.Fortran2003.Include_Filename(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

Implements the matching of a filename from an include statement.

subclass_names = [][source]
static match(string)[source]

Match the string with the regular expression file_name in the pattern_tools file. The only content that is not accepted is an empty string or white space at the start or end of the string.

Parameters:

string (str) – the string to match with the pattern rule.

Returns:

a tuple of size 1 containing a string with the matched name if there is a match, or None if there is not.

Return type:

(str) or NoneType

class fparser.two.Fortran2003.Include_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Implements the matching of a Fortran include statement. There is no rule for this as the compiler is expected to inline any content from an include statement when one is found. However, for a parser it can make sense to represent an include statement in a parse tree:

include-stmt is INCLUDE ['filename' or "filename"]
use_names = ['Include_Filename'][source]
static match(string)[source]

Implements the matching for an include statement.

Parameters:

string (str) – the string to match with as an include statement.

Returns:

a tuple of size 1 containing an Include_Filename object with the matched filename if there is a match, or None if there is not.

Return type:

(fparser.two.Fortran2003.Include_Filename) or NoneType

tostr()[source]
Returns:

this include_stmt as a string

Return type:

str

class fparser.two.Fortran2003.Program_Unit(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 Rule R202:

<program-unit> = <main-program>
                 | <external-subprogram>
                 | <module>
                 | <block-data>
subclass_names = ['Comment', 'Main_Program', 'External_Subprogram', 'Module', 'Block_Data'][source]
class fparser.two.Fortran2003.External_Subprogram(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 Rule R203:

<external-subprogram> = <function-subprogram>
                        | <subroutine-subprogram>
subclass_names = ['Comment', 'Function_Subprogram', 'Subroutine_Subprogram'][source]
class fparser.two.Fortran2003.Specification_Part(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

Fortran2003 Rule R204:

<specification-part> = [ <use-stmt> ]...
                         [ <import-stmt> ]...
                         [ <implicit-part> ]
                         [ <declaration-construct> ]...
subclass_names = [][source]
use_names = ['Use_Stmt', 'Import_Stmt', 'Implicit_Part', 'Declaration_Construct'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Implicit_Part(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

Fortran2003 Rule R205:

<implicit-part> = [ <implicit-part-stmt> ]...
                    <implicit-stmt>
subclass_names = [][source]
use_names = ['Implicit_Part_Stmt', 'Implicit_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Implicit_Part_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 Rule R206:

<implicit-part-stmt> = <implicit-stmt>
                       | <parameter-stmt>
                       | <format-stmt>
                       | <entry-stmt>
subclass_names = ['Comment', 'Implicit_Stmt', 'Parameter_Stmt', 'Format_Stmt', 'Entry_Stmt'][source]
class fparser.two.Fortran2003.Declaration_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R207:

declaration-construct is derived-type-def
                       or entry-stmt
                       or enum-def
                       or format-stmt
                       or interface-block
                       or parameter-stmt
                       or procedure-declaration-stmt
                       or specification-stmt
                       or type-declaration-stmt
                       or stmt-function-stmt

Note, stmt-function-stmt is not currently matched.

subclass_names = ['Derived_Type_Def', 'Entry_Stmt', 'Enum_Def', 'Format_Stmt', 'Interface_Block',...[source]
class fparser.two.Fortran2003.Execution_Part(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

Fortran2003 Rule R208:

<execution-part> = <executable-construct>
[ <execution-part-construct> ]…

<execution-part> shall not contain <end-function-stmt>, <end-program-stmt>, <end-subroutine-stmt>

subclass_names = [][source]
use_names = ['Executable_Construct_C201', 'Execution_Part_Construct_C201'][source]
static match(string)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Execution_Part_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<execution-part-construct> = <executable-construct>
                             | <format-stmt>
                             | <entry-stmt>
                             | <data-stmt>
subclass_names = ['Comment', 'Executable_Construct', 'Format_Stmt', 'Entry_Stmt', 'Data_Stmt'][source]
class fparser.two.Fortran2003.Execution_Part_Construct_C201(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Base class for Fortran 2003 syntax rules.

All Base classes have the following attributes:

self.string - original argument to construct a class instance, its
              type is either str or FortranReaderBase.
self.item   - Line instance (holds label) or None.
Parameters:
subclass_names = ['Comment', 'Executable_Construct_C201', 'Format_Stmt', 'Entry_Stmt', 'Data_Stmt'][source]
class fparser.two.Fortran2003.Internal_Subprogram_Part(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<internal-subprogram-part> = <contains-stmt>
                               <internal-subprogram>
                               [ <internal-subprogram> ]...
subclass_names = [][source]
use_names = ['Contains_Stmt', 'Internal_Subprogram'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Internal_Subprogram(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<internal-subprogram> = <function-subprogram>
                        | <subroutine-subprogram>
subclass_names = ['Function_Subprogram', 'Subroutine_Subprogram'][source]
class fparser.two.Fortran2003.Specification_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<specification-stmt> = <access-stmt>
                       | <allocatable-stmt>
                       | <asynchronous-stmt>
                       | <bind-stmt>
                       | <common-stmt>
                       | <data-stmt>
                       | <dimension-stmt>
                       | <equivalence-stmt>
                       | <external-stmt>
                       | <intent-stmt>
                       | <intrinsic-stmt>
                       | <namelist-stmt>
                       | <optional-stmt>
                       | <pointer-stmt>
                       | <protected-stmt>
                       | <save-stmt>
                       | <target-stmt>
                       | <volatile-stmt>
                       | <value-stmt>
subclass_names = ['Access_Stmt', 'Allocatable_Stmt', 'Asynchronous_Stmt', 'Bind_Stmt', 'Comment', 'Common_Stmt',...[source]
class fparser.two.Fortran2003.Executable_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R213:

executable-construct is action-stmt
                     or associate-construct
                     or case-construct
                     or do-construct
                     or forall-construct
                     or if-construct
                     or select-type-construct
                     or where-construct
subclass_names = ['Action_Stmt', 'Associate_Construct', 'Case_Construct', 'Do_Construct', 'Forall_Construct',...[source]
class fparser.two.Fortran2003.Executable_Construct_C201(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Base class for Fortran 2003 syntax rules.

All Base classes have the following attributes:

self.string - original argument to construct a class instance, its
              type is either str or FortranReaderBase.
self.item   - Line instance (holds label) or None.
Parameters:
subclass_names[source]
class fparser.two.Fortran2003.Action_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<action-stmt> = <allocate-stmt>
                | <assignment-stmt>
                | <backspace-stmt>
                | <call-stmt>
                | <close-stmt>
                | <continue-stmt>
                | <cycle-stmt>
                | <deallocate-stmt>
                | <endfile-stmt>
                | <end-function-stmt>
                | <end-program-stmt>
                | <end-subroutine-stmt>
                | <exit-stmt>
                | <flush-stmt>
                | <forall-stmt>
                | <goto-stmt>
                | <if-stmt>
                | <inquire-stmt>
                | <nullify-stmt>
                | <open-stmt>
                | <pointer-assignment-stmt>
                | <print-stmt>
                | <read-stmt>
                | <return-stmt>
                | <rewind-stmt>
                | <stop-stmt>
                | <wait-stmt>
                | <where-stmt>
                | <write-stmt>
                | <arithmetic-if-stmt>
                | <computed-goto-stmt>
subclass_names = ['Allocate_Stmt', 'Assignment_Stmt', 'Backspace_Stmt', 'Call_Stmt', 'Close_Stmt', 'Comment',...[source]
class fparser.two.Fortran2003.Action_Stmt_C201(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<action-stmt-c201> = <action-stmt>

C201 is applied.

subclass_names[source]
class fparser.two.Fortran2003.Action_Stmt_C802(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<action-stmt-c802> = <action-stmt>

C802 is applied.

subclass_names[source]
class fparser.two.Fortran2003.Action_Stmt_C824(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<action-stmt-c824> = <action-stmt>

C824 is applied.

subclass_names[source]
class fparser.two.Fortran2003.Keyword(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<keyword> = <name>
subclass_names = ['Name'][source]
class fparser.two.Fortran2003.Name(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

Fortran 2003 rule R304:

name is letter [ alphanumeric_character ]...
subclass_names = [][source]
static match(string)[source]

Match the string with the regular expression abs_name in the pattern_tools file.

Parameters:

string (str) – the string to match with the pattern rule.

Returns:

a tuple of size 1 containing a string with the matched name if there is a match, or None if there is not.

Return type:

(str) or None

class fparser.two.Fortran2003.Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<constant> = <literal-constant>
             | <named-constant>
subclass_names = ['Literal_Constant', 'Named_Constant'][source]
class fparser.two.Fortran2003.Literal_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<literal-constant> = <int-literal-constant>
                     | <real-literal-constant>
                     | <complex-literal-constant>
                     | <logical-literal-constant>
                     | <char-literal-constant>
                     | <boz-literal-constant>
subclass_names = ['Int_Literal_Constant', 'Real_Literal_Constant', 'Complex_Literal_Constant',...[source]
class fparser.two.Fortran2003.Named_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

::

<named-constant> = <name>

subclass_names = ['Name'][source]
class fparser.two.Fortran2003.Int_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<int-constant> = <constant>
subclass_names = ['Constant'][source]
class fparser.two.Fortran2003.Char_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<char-constant> = <constant>
subclass_names = ['Constant'][source]
class fparser.two.Fortran2003.Defined_Operator(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R311:

defined-operator is defined-unary-op
                  or defined-binary-op
                  or extended-intrinsic-op

Note, defined-operator is defined in pattern_tools.py so could be called directly via a stringbase match. However, the defined unary and binary op rules have constraints which would not be checked if we did this.

Note, whilst we subclass for both Defined Unary and Binary ops, the match is the same so we will only ever match with the first (so the second is not really necessary here). This is OK from a parsing point of view as they both return a Defined_Op class, so are identical from the parsers point of view.

subclass_names = ['Defined_Unary_Op', 'Defined_Binary_Op', 'Extended_Intrinsic_Op'][source]
class fparser.two.Fortran2003.Extended_Intrinsic_Op(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

Fortran 2003 rule R312:

extended-intrinsic-op is intrinsic-operator

Note, extended-intrinsic-op is only ever used by R311 and is defined in pattern_tools.py so could be matched directly in the Defined_Operator class (by changing it to STRINGBase and moving the match in this class into the Defined_Operator class). This would mean that this class would not be required. However, the parse tree would then not have the concept of an Extended_Intrinsic_Op which might be useful for code manipulation tools.

static match(string)[source]

Implements the matching for the extended-intrinsic-op rule. Matches the string with the regular expression extended_intrinsic_operator in the pattern_tools file.

Parameters:

string (str) – the string to match with the pattern rule.

Returns:

a tuple of size 1 containing a string with the matched name if there is a match, or None if there is not.

Return type:

(str) or None

class fparser.two.Fortran2003.Label(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

<label> = <digit> [ <digit> [ <digit> [ <digit> [ <digit> ] ] ] ]

Has attributes:

string : str
subclass_names = [][source]
static match(string)[source]
__int__()[source]
class fparser.two.Fortran2003.Type_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

::
<type-spec> = <intrinsic-type-spec>
<derived-type-spec>
subclass_names = ['Intrinsic_Type_Spec', 'Derived_Type_Spec'][source]
class fparser.two.Fortran2003.Type_Param_Value(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

Fortran 2003 Rule 402:

<type-param-value> = <scalar-int-expr>
                   | *
                   | :
subclass_names = ['Scalar_Int_Expr'][source]
use_names = [][source]
static match(string)[source]
class fparser.two.Fortran2003.Intrinsic_Type_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.WORDClsBase

<intrinsic-type-spec> = INTEGER [ <kind-selector> ]
                        | REAL [ <kind-selector> ]
                        | DOUBLE COMPLEX
                        | COMPLEX [ <kind-selector> ]
                        | CHARACTER [ <char-selector> ]
                        | LOGICAL [ <kind-selector> ]
Extensions:
                        | DOUBLE PRECISION
                        | BYTE
subclass_names = [][source]
use_names = ['Kind_Selector', 'Char_Selector'][source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Kind_Selector(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R404:

kind-selector is ( [ KIND = ] scalar-int-initialization-expr )

A non-standard extension is also supported here:
                  | * char-length

There is an associated constraint that we can’t enforce in fparser:

C404 (R404) The value of scalar-int-initialization-expr shall be
nonnegative and shall specify a representation method that
exists on the processor.
subclass_names = [][source]
use_names = ['Char_Length', 'Scalar_Int_Initialization_Expr'][source]
static match(string)[source]

Implements the matching for a Kind_Selector.

Parameters:

string (str) – a string containing the code to match

Returns:

None if there is no match, otherwise a tuple of size 3 containing a ‘(’, a single list which contains an instance of classes that have matched and a ‘)’, or a tuple of size 2 containing a ‘*’ and an instance of classes that have matched.

Return type:

NoneType or ( str, [ MatchedClasses ], str) or ( str, fparser.two.Fortran2003.Char_Length)

Raises:
  • InternalError – if None is passed instead of a string. The parent rule should not pass None and the logic in this routine relies on a valid string.

  • InternalError – if the string passed is <=1 characters long. The parent rule passing this string should ensure the string is at least 2 characters long and the logic in this routine relies on this. The reason there is a minimum of two is that the pattern ‘*n’ where ‘n’ is a number is the smallest valid pattern. The other valid pattern must have at least a name with one character surrounded by brackets e.g. ‘(x)’ so should be at least 3 characters long.

tostr()[source]
Returns:

this kind_selector as a string

Return type:

str

class fparser.two.Fortran2003.Signed_Int_Literal_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.NumberBase

::

<signed-int-literal-constant> = [ <sign> ] <int-literal-constant>

subclass_names = ['Int_Literal_Constant'][source]
static match(string)[source]
class fparser.two.Fortran2003.Int_Literal_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.NumberBase

::

<int-literal-constant> = <digit-string> [ _ <kind-param> ]

subclass_names = [][source]
static match(string)[source]
class fparser.two.Fortran2003.Digit_String(string, parent_cls=None)[source]

Bases: fparser.two.utils.NumberBase

<digit-string> = <digit> [ <digit> ]...
subclass_names = [][source]
static match(string)[source]
class fparser.two.Fortran2003.Boz_Literal_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<boz-literal-constant> = <binary-constant>
                         | <octal-constant>
                         | <hex-constant>
subclass_names = ['Binary_Constant', 'Octal_Constant', 'Hex_Constant'][source]
class fparser.two.Fortran2003.Binary_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<binary-constant> = B ' <digit> [ <digit> ]... '
                    | B " <digit> [ <digit> ]... "
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Octal_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<octal-constant> = O ' <digit> [ <digit> ]... '
                   | O " <digit> [ <digit> ]... "
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Hex_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<hex-constant> = Z ' <digit> [ <digit> ]... '
                 | Z " <digit> [ <digit> ]... "
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Signed_Real_Literal_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.NumberBase

<signed-real-literal-constant> = [ <sign> ] <real-literal-constant>
subclass_names = ['Real_Literal_Constant'][source]
static match(string)[source]
class fparser.two.Fortran2003.Real_Literal_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.NumberBase

subclass_names = [][source]
static match(string)[source]
class fparser.two.Fortran2003.Complex_Literal_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<complex-literal-constant> = ( <real-part>, <imag-part> )
subclass_names = [][source]
use_names = ['Real_Part', 'Imag_Part'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Real_Part(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<real-part> = <signed-int-literal-constant>
              | <signed-real-literal-constant>
              | <named-constant>
subclass_names = ['Signed_Int_Literal_Constant', 'Signed_Real_Literal_Constant', 'Named_Constant'][source]
class fparser.two.Fortran2003.Imag_Part(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<imag-part> = <real-part>
subclass_names = ['Signed_Int_Literal_Constant', 'Signed_Real_Literal_Constant', 'Named_Constant'][source]
class fparser.two.Fortran2003.Char_Selector(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<char-selector> = <length-selector>
                  | ( LEN = <type-param-value> ,
                     KIND = <scalar-int-initialization-expr> )
                  | ( <type-param-value> ,
                     [ KIND = ] <scalar-int-initialization-expr> )
                  | ( KIND = <scalar-int-initialization-expr>
                    [ , LEN = <type-param-value> ] )
subclass_names = ['Length_Selector'][source]
use_names = ['Type_Param_Value', 'Scalar_Int_Initialization_Expr'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Length_Selector(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<length -selector> = ( [ LEN = ] <type-param-value> )
                    | * <char-length> [ , ]
subclass_names = [][source]
use_names = ['Type_Param_Value', 'Char_Length'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Char_Length(string, parent_cls=None)[source]

Bases: fparser.two.utils.BracketBase

<char-length> = ( <type-param-value> )
                | <scalar-int-literal-constant>
subclass_names = ['Scalar_Int_Literal_Constant'][source]
use_names = ['Type_Param_Value'][source]
static match(string)[source]

A generic match method for all types of bracketed expressions.

Parameters:
  • brackets (str) – the format of the left and right brackets provided as a string, for example ‘()’

  • cls – the class to match the content within the brackets :type cls: subclass of fparser.two.utils.Base

  • string (str) – the content to match

  • require_cls (bool) – whether the class and associated content is mandatory (True) or optional (False). The default is True.

Returns:

None if there is no match, otherwise a tuple with the first and third entries being strings containing the left and right brackets respectively and the second entry being either None or an instance of the class provided as the second argument (cls).

Return type:

‘NoneType’, ( str, NoneType, str) or ( str, cls, str )

class fparser.two.Fortran2003.Char_Literal_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R427:

char-literal-constant is [ kind-param _ ] ' rep-char '
                      or [ kind-param _ ] " rep-char "
subclass_names = [][source]
rep[source]
static match(string)[source]

Implements the matching for a Char_Literal_Constant. For example:

"hello"
'hello'
nondefaultcharset_"nondefaultchars"

There is an associated constraint C422: “The value of kind-param shall specify a representation method that exists on the processor.” However, this cannot be validated by fparser so no checks are performed.

Parameters:

string (str) – a string containing the code to match.

Returns:

None if there is no match, otherwise a tuple of size 2 containing the character constant and the kind value as strings.

Return type:

NoneType or (str, NoneType) or (str, str)

tostr()[source]
Returns:

this Char_Literal_Constant as a string.

Return type:

str

Raises:
  • InternalError – if the internal items list variable is not the expected size.

  • InternalError – if the first element of the internal items list is None or is an empty string.

class fparser.two.Fortran2003.Logical_Literal_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.NumberBase

<logical-literal-constant> = .TRUE. [ _ <kind-param> ]
                             | .FALSE. [ _ <kind-param> ]
subclass_names = [][source]
static match(string)[source]
class fparser.two.Fortran2003.Derived_Type_Def(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<derived-type-def> = <derived-type-stmt>
                       [ <type-param-def-stmt> ]...
                       [ <private-or-sequence> ]...
                       [ <component-part> ]
                       [ <type-bound-procedure-part> ]
                       <end-type-stmt>
subclass_names = [][source]
use_names = ['Derived_Type_Stmt', 'Type_Param_Def_Stmt', 'Private_Or_Sequence', 'Component_Part',...[source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Derived_Type_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran 2003 rule R430:

derived-type-stmt is TYPE [ [ , type-attr-spec-list ] :: ]
                     type-name [ ( type-param-name-list ) ]
subclass_names = [][source]
use_names = ['Type_Attr_Spec_List', 'Type_Name', 'Type_Param_Name_List'][source]
static match(string)[source]

Implements the matching for a Derived Type Statement.

Parameters:

string (str) – a string containing the code to match

Returns:

None if there is no match, otherwise a tuple of size 3 containing an Attribute_Spec_List (or None if there isn’t one), the name of the type (in a Name class) and a Parameter_Name_List (or None is there isn’t one).

Return type:

( Type_Attr_Spec_List or None, Name, Type_Param_Name_List or None ) or None

tostr()[source]
Returns:

this derived type statement as a string

Return type:

str

Raises:
get_start_name()[source]
Returns:

this derived type statement’s name as a string

Return type:

str

class fparser.two.Fortran2003.Type_Name(string, parent_cls=None)[source]

Bases: Name

<type-name> = <name>
<type-name> shall not be DOUBLEPRECISION or the name of intrinsic type
subclass_names = [][source]
use_names = [][source]
static match(string)[source]

Match the string with the regular expression abs_name in the pattern_tools file.

Parameters:

string (str) – the string to match with the pattern rule.

Returns:

a tuple of size 1 containing a string with the matched name if there is a match, or None if there is not.

Return type:

(str) or None

class fparser.two.Fortran2003.Type_Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<type-attr-spec> = <access-spec>
                   | EXTENDS ( <parent-type-name> )
                   | ABSTRACT
                   | BIND (C)
subclass_names[source]
use_names = ['Parent_Type_Name'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Private_Or_Sequence(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<private-or-sequence> = <private-components-stmt>
                        | <sequence-stmt>
subclass_names = ['Private_Components_Stmt', 'Sequence_Stmt'][source]
class fparser.two.Fortran2003.End_Type_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-type-stmt> = END TYPE [ <type-name> ]
subclass_names = [][source]
use_names = ['Type_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Sequence_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<sequence-stmt> = SEQUENCE
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Type_Param_Def_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<type-param-def-stmt> = INTEGER [ <kind-selector> ] ,
    <type-param-attr-spec> :: <type-param-decl-list>
subclass_names = [][source]
use_names = ['Kind_Selector', 'Type_Param_Attr_Spec', 'Type_Param_Decl_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Type_Param_Decl(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

::
<type-param-decl> = <type-param-name>

[ = <scalar-int-initialization-expr> ]

subclass_names = ['Type_Param_Name'][source]
use_names = ['Scalar_Int_Initialization_Expr'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Type_Param_Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<type-param-attr-spec> = KIND
                         | LEN
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Component_Part(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<component-part> is [ <component-def-stmt> ]...
subclass_names = [][source]
use_names = ['Component_Def_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

tofortran(tab='', isfix=None)[source]

Converts this node (and all children) into Fortran.

Parameters:
  • tab (str) – white space to prefix to output.

  • isfix (bool) – whether or not to generate fixed-format output.

Returns:

Fortran code.

Return type:

str

class fparser.two.Fortran2003.Component_Def_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<component-def-stmt> is <data-component-def-stmt>
                     or <proc-component-def-stmt>
subclass_names = ['Data_Component_Def_Stmt', 'Proc_Component_Def_Stmt'][source]
class fparser.two.Fortran2003.Data_Component_Def_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Type_Declaration_StmtBase

Fortran 2003 rule 440:

<data-component-def-stmt> is <declaration-type-spec> [
         [ , <component-attr-spec-list> ] :: ] <component-decl-list>

Associated constraints are:

C436 (R440)  No component-attr-spec shall appear more than once in a given
     component-def-stmt.
C437 (R440)  A component declared with the CLASS keyword shall have the
     ALLOCATABLE or POINTER attribute.
C438 (R440)  If the POINTER attribute is not specified for a component,
     the declaration-type-spec in the component-def-stmt shall be CLASS(*)
     or shall specify an intrinsic type or a previously defined derived
     type.
C439 (R440)  If the POINTER attribute is specified for a component, the
     declaration-type-spec in the component-def-stmt shall be CLASS(*) or
     shall specify an intrinsic type or any accessible derived type
     including the type being defined.
C440 (R440)  If the POINTER or ALLOCATABLE attribute is specified, each
     component-array-spec shall be a deferred-shape-spec-list.
C441 (R440)  If neither the POINTER attribute nor the ALLOCATABLE
     attribute is specified, each component-array-spec shall be an
     explicit-shape-spec-list.
C443 (R440)  A component shall not have both the ALLOCATABLE and the
     POINTER attribute.
C446 (R440)  If component-initialization appears, a double-colon separator
     shall appear before the component-decl-list.
C447 (R440)  If => appears in component-initialization, POINTER shall
     appear in the component-attr-spec-list. If = appears in
     component-initialization, POINTER or ALLOCATABLE shall not appear in
     the component-attr-spec-list.

C436-C441, C443, C446-C447 are currently not checked - issue #258.

subclass_names = [][source]
use_names = ['Declaration_Type_Spec', 'Component_Attr_Spec_List', 'Component_Decl_List'][source]
static match(string)[source]
class fparser.two.Fortran2003.Dimension_Component_Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.CALLBase

<dimension-component-attr-spec> = DIMENSION ( <component-array-spec> )
subclass_names = [][source]
use_names = ['Component_Array_Spec'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Component_Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<component-attr-spec> = POINTER
                        | DIMENSION ( <component-array-spec> )
                        | ALLOCATABLE
                        | <access-spec>
subclass_names = ['Access_Spec', 'Dimension_Component_Attr_Spec'][source]
use_names = [][source]
attributes = ['POINTER', 'ALLOCATABLE'][source]
classmethod match(string)[source]

Implements the matching for component attribute specifications.

Note that this is implemented as a classmethod (not a staticmethod), using attribute keywords from the list provided as a class property. This allows expanding this list for Fortran 2008 without having to reimplement the matching.

Parameters:

string (str) – the string to match as an attribute.

Returns:

None if there is no match, otherwise a 1-tuple containing the matched attribute string.

Return type:

NoneType or (str,)

class fparser.two.Fortran2003.Component_Decl(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<component-decl> = <component-name> [ ( <component-array-spec> ) ]
    [ * <char-length> ] [ <component-initialization> ]
subclass_names = [][source]
use_names = ['Component_Name', 'Component_Array_Spec', 'Char_Length', 'Component_Initialization'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Component_Array_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<component-array-spec> = <explicit-shape-spec-list>
                         | <deferred-shape-spec-list>
subclass_names = ['Explicit_Shape_Spec_List', 'Deferred_Shape_Spec_List'][source]
class fparser.two.Fortran2003.Component_Initialization(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<component-initialization> =  = <initialization-expr>
                             | => <null-init>
subclass_names = [][source]
use_names = ['Initialization_Expr', 'Null_Init'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Proc_Component_Def_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<proc-component-def-stmt> is PROCEDURE ( [ <proc-interface> ] )
    , <proc-component-attr-spec-list> :: <proc-decl-list>

where:

proc-component-attr-spec is POINTER
                         or PASS [ (arg-name) ]
                         or NOPASS
                         or access-spec

The standard specifies the following constraints:

C448 The same proc-component-attr-spec shall not appear more than once
     in a given proc-component-def-stmt. Not checked by fparser - #232.

C449 POINTER shall appear in each proc-component-attr-spec-list.

C450 If the procedure pointer component has an implicit interface or
     has no arguments, NOPASS shall be specified. Not checked by
     fparser - #232.

C451 If PASS (arg-name) appears, the interface shall have a dummy argument
     named arg-name. Not checked by fparser - #232.

C452 PASS and NOPASS shall not both appear in the same
     proc-component-attr-spec-list. Not checked by fparser - #232.
subclass_names = [][source]
use_names = ['Proc_Interface', 'Proc_Component_Attr_Spec_List', 'Proc_Decl_List'][source]
static match(string)[source]

Attempts to match the supplied string with the pattern for a declaration of a procedure part of a component.

Parameters:

string (str) – the string to test for a match.

Returns:

None (if no match) or a tuple consisting of the procedure interface, the list of attributes and a list of procedure names or None.

Return type:

NoneType or (fparser.two.Fortran2003.Proc_Interface, fparser.two.Fortran2003.Proc_Component_Attr_Spec_List, fparser.two.Fortran2003.Proc_Decl_List)

tostr()[source]
class fparser.two.Fortran2003.Proc_Component_PASS_Arg_Name(string, parent_cls=None)[source]

Bases: fparser.two.utils.CALLBase

<proc-component-PASS-arg-name> = PASS ( <arg-name> )
subclass_names = [][source]
use_names = ['Arg_Name'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Proc_Component_Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<proc-component-attr-spec> = POINTER
                             | PASS [ ( <arg-name> ) ]
                             | NOPASS
                             | <access-spec>
subclass_names = ['Access_Spec', 'Proc_Component_PASS_Arg_Name'][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Private_Components_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

Fortran2003 Rule R447:

<private-components-stmt> = PRIVATE

Specifies support for private components statement within a derived type.

subclass_names = [][source]
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

keyword “PRIVATE” or None if no match is found

Return type:

str or None

class fparser.two.Fortran2003.Type_Bound_Procedure_Part(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

Fortran 2003 rule R448.

Specifies the type-bound procedure part of a derived type:

type-bound-procedure-part is contains-stmt
                                  [ binding-private-stmt ]
                                  proc-binding-stmt
                                  [ proc-binding-stmt ]...
subclass_names = [][source]
use_names = ['Contains_Stmt', 'Binding_Private_Stmt', 'Proc_Binding_Stmt'][source]
static match(reader)[source]
Parameters:

reader (fparser.common.readfortran.FortranReaderBase) – the Fortran reader containing the line(s) of code that we are trying to match

Returns:

code block containing instances of the classes that match the syntax of the type-bound procedure part of a derived type.

Return type:

([Contains_Stmt, Specific_Binding, str, Name, Name]) or None

class fparser.two.Fortran2003.Binding_Private_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.STRINGBase

Fortran2003 Rule R449:

<binding-private-stmt> = PRIVATE

For binding private statement within the type-bound procedure part of a derived type.

subclass_names = [][source]
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

keyword “PRIVATE” or None if no match is found

Return type:

str or None

class fparser.two.Fortran2003.Proc_Binding_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 Rule R450:

<proc-binding-stmt> = <specific-binding>
                      | <generic-binding>
                      | <final-binding>

Specifies the procedure binding for the type-bound procedures within a derived type.

subclass_names = ['Specific_Binding', 'Generic_Binding', 'Final_Binding'][source]
class fparser.two.Fortran2003.Specific_Binding(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 Rule R451:

<specific-binding> = PROCEDURE [ ( <interface-name> ) ] [
    [ , <binding-attr-list> ] :: ] <binding-name> [ => <procedure-name> ]

Specifies the syntax of specific binding for a type-bound procedure within a derived type.

The following are associated constraints:

C456 (R451) If => procedure-name appears, the double-colon
separator shall appear.

C457 (R451) If => procedure-name appears, interface-name shall not
appear.

C458 (R451) The procedure-name shall be the name of an accessible
module procedure or an external procedure that has an explicit
interface. Note, this is not checked by fparser.
subclass_names = [][source]
use_names = ['Interface_Name', 'Binding_Attr_List', 'Binding_Name', 'Procedure_Name'][source]
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

5-tuple containing strings and instances of the classes describing a specific type-bound procedure (optional interface name, optional binding attribute list, optional double colon delimiter, mandatory binding name and optional procedure name)

Return type:

5-tuple of objects (1 mandatory and 4 optional)

tostr()[source]
Returns:

parsed representation of a specific type-bound procedure

Return type:

str

class fparser.two.Fortran2003.Binding_PASS_Arg_Name(string, parent_cls=None)[source]

Bases: fparser.two.utils.CALLBase

Fortran 2003 helper rule (for R453):

<binding-PASS-arg-name> = PASS ( <arg-name> )

Specifies the syntax of passed-object dummy argument for a specific type-bound procedure.

subclass_names = [][source]
use_names = ['Arg_Name'][source]
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

keyword “PASS” with the name of a passed-object dummy argument or nothing if no match is found

Return type:

str

class fparser.two.Fortran2003.Generic_Binding(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 Rule R452:

<generic-binding> = GENERIC [ , <access-spec> ] ::
    <generic-spec> => <binding-name-list>

Specifies the syntax of generic binding for a type-bound procedure within a derived type.

subclass_names = [][source]
use_names = ['Access_Spec', 'Generic_Spec', 'Binding_Name_List'][source]
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

3-tuple containing strings and instances of the classes describing a generic type-bound procedure (optional access specifier, mandatory generic identifier and mandatory binding name list)

Return type:

3-tuple of objects (2 mandatory and 1 optional)

tostr()[source]
Returns:

parsed representation of a “GENERIC” type-bound procedure

Return type:

str

class fparser.two.Fortran2003.Binding_Attr(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

Fortran2003 Rule R453:

<binding-attr> = PASS [ ( <arg-name> ) ]
                 | NOPASS
                 | NON_OVERRIDABLE
                 | DEFERRED
                 | <access-spec>

Specifies syntax of allowed binding attributes for a specific type-bound procedure binding.

subclass_names = ['Access_Spec', 'Binding_PASS_Arg_Name'][source]
static match(string)[source]
Returns:

keywords for allowed binding attributes or nothing if no match is found

Return type:

str

class fparser.two.Fortran2003.Final_Binding(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

Fortran2003 Rule R454:

<final-binding> = FINAL [ :: ] <final-subroutine-name-list>

Specifies the syntax of final binding for a type-bound procedure within a derived type.

subclass_names = [][source]
use_names = ['Final_Subroutine_Name_List'][source]
tostr[source]
static match(string)[source]
Returns:

keyword “FINAL” with the list of “FINAL” type-bound procedures or nothing if no match is found

Return type:

str

class fparser.two.Fortran2003.Derived_Type_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<derived-type-spec> = <type-name> [ ( <type-param-spec-list> ) ]
subclass_names = ['Type_Name'][source]
use_names = ['Type_Param_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Type_Param_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

<type-param-spec> = [ <keyword> = ] <type-param-value>
subclass_names = ['Type_Param_Value'][source]
use_names = ['Keyword'][source]
static match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Structure_Constructor(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<structure-constructor> = <derived-type-spec> ( [ <component-spec-list> ] )
subclass_names = [][source]
use_names = ['Derived_Type_Spec', 'Component_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Component_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

<component-spec> = [ <keyword> = ] <component-data-source>
subclass_names = ['Component_Data_Source'][source]
use_names = ['Keyword'][source]
static match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Component_Data_Source(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<component-data-source> = <expr>
                          | <data-target>
                          | <proc-target>
subclass_names = ['Proc_Target', 'Data_Target', 'Expr'][source]
class fparser.two.Fortran2003.Enum_Def(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<enum-def> = <enum-def-stmt>
                 <enumerator-def-stmt>
                 [ <enumerator-def-stmt> ]...
                 <end-enum-stmt>
subclass_names = [][source]
use_names = ['Enum_Def_Stmt', 'Enumerator_Def_Stmt', 'End_Enum_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Enum_Def_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<enum-def-stmt> = ENUM, BIND(C)
subclass_names = [][source]
use_names = [][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Enumerator_Def_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<enumerator-def-stmt> = ENUMERATOR [ :: ] <enumerator-list>
subclass_names = [][source]
use_names = ['Enumerator_List'][source]
tostr[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Enumerator(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<enumerator> = <named-constant> [ = <scalar-int-initialization-expr> ]
subclass_names = ['Named_Constant'][source]
use_names = ['Scalar_Int_Initialization_Expr'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.End_Enum_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-enum-stmt> = END ENUM
subclass_names = [][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Array_Constructor(string, parent_cls=None)[source]

Bases: fparser.two.utils.BracketBase

<array-constructor> = (/ <ac-spec> /)
                      | <left-square-bracket> <ac-spec>
                        <right-square-bracket>
subclass_names = [][source]
use_names = ['Ac_Spec'][source]
static match(string)[source]

A generic match method for all types of bracketed expressions.

Parameters:
  • brackets (str) – the format of the left and right brackets provided as a string, for example ‘()’

  • cls – the class to match the content within the brackets :type cls: subclass of fparser.two.utils.Base

  • string (str) – the content to match

  • require_cls (bool) – whether the class and associated content is mandatory (True) or optional (False). The default is True.

Returns:

None if there is no match, otherwise a tuple with the first and third entries being strings containing the left and right brackets respectively and the second entry being either None or an instance of the class provided as the second argument (cls).

Return type:

‘NoneType’, ( str, NoneType, str) or ( str, cls, str )

class fparser.two.Fortran2003.Ac_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<ac-spec> = <type-spec> ::
            | [ <type-spec> :: ] <ac-value-list>
subclass_names = ['Ac_Value_List'][source]
use_names = ['Type_Spec'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Ac_Value(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<ac-value> = <expr>
             | <ac-implied-do>
subclass_names = ['Ac_Implied_Do', 'Expr'][source]
class fparser.two.Fortran2003.Ac_Implied_Do(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 rule R470. Describes the form of implicit do loop used within an array constructor:

ac-implied-do is ( ac-value-list , ac-implied-do-control )

Subject to the following constraint:

C497 (R470) The ac-do-variable of an ac-implied-do that is in another
      ac-implied-do shall not appear as the ac-do-variable of the
      containing ac-implied-do.

C497 is currently not checked - issue #257.

subclass_names = [][source]
use_names = ['Ac_Value_List', 'Ac_Implied_Do_Control'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Ac_Implied_Do_Control(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 rule R471. Specifies the syntax for the control of an implicit loop within an array constructor:

ac-implied-do-control is ac-do-variable = scalar-int-expr,
                                scalar-int-expr [ , scalar-int-expr ]

where (R472) ac-do-variable is scalar-int-variable

subclass_names = [][source]
use_names = ['Ac_Do_Variable', 'Scalar_Int_Expr'][source]
static match(string)[source]

Attempts to match the supplied string with the pattern for implied-do control.

Parameters:

string (str) – the string to test for a match.

Returns:

None if there is no match or a 2-tuple containing the do-variable name and the list of integer expressions (for start, stop [, step]).

Return type:

NoneType or (fparser.two.Fortran2003.Ac_Do_Variable, list)

tostr()[source]
class fparser.two.Fortran2003.Ac_Do_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 rule R472. Specifies the permitted form of an implicit do-loop variable within an array constructor:

ac-do-variable is scalar-int-variable
ac-do-variable shall be a named variable

Subject to the following constraint:

C493 (R472) ac-do-variable shall be a named variable.

C493 is currently not checked - issue #257.

subclass_names = ['Scalar_Int_Variable'][source]
class fparser.two.Fortran2003.Type_Declaration_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Type_Declaration_StmtBase

Fortran 2003 rule 501:

type-declaration-stmt is declaration-type-spec [
    [ , attr-spec ]... :: ] entity-decl-list

Associated constraints are:

C507 (R501)  The same attr-spec shall not appear more than once in a given
     type-declaration-stmt.
C509 (R501)  An entity declared with the CLASS keyword shall be a dummy
     argument or have the ALLOCATABLE or POINTER attribute.
C510 (R501)  An array that has the POINTER or ALLOCATABLE attribute shall
     be specified with an array-spec that is a deferred-shape-spec-list.
C511 (R501)  An array-spec for an object-name that is a function result
     that does not have the ALLOCATABLE or POINTER attribute shall be an
     explicit-shape-spec-list.
C512 (R501)  If the POINTER attribute is specified, the ALLOCATABLE,
     TARGET, EXTERNAL, or INTRINSIC attribute shall not be specified.
C513 (R501)  If the TARGET attribute is specified, the POINTER, EXTERNAL,
     INTRINSIC, or PARAMETER attribute shall not be specified.
C514 (R501)  The PARAMETER attribute shall not be specified for a dummy
     argument, a pointer, an allocatable entity, a function, or an object
     in a common block.
C515 (R501)  The INTENT, VALUE, and OPTIONAL attributes may be specified
     only for dummy arguments.
C516 (R501)  The INTENT attribute shall not be specified for a dummy
     procedure without the POINTER attribute.
C517 (R501)  The SAVE attribute shall not be specified for an object that
     is in a common block, a dummy argument, a procedure, a function
     result, an automatic data object, or an object with the PARAMETER
     attribute.
C519 (R501)  An entity in an entity-decl-list shall not have the EXTERNAL
     or INTRINSIC attribute specified unless it is a function.
C522 (R501)  The initialization shall appear if the statement contains a
     PARAMETER attribute.
C523 (R501)  If initialization appears, a double-colon separator shall
     appear before the entity-decl-list.
C526 (R501)  If the VOLATILE attribute is specified, the PARAMETER,
     INTRINSIC, EXTERNAL, or INTENT(IN) attribute shall not be specified.
C527 (R501)  If the VALUE attribute is specified, the PARAMETER, EXTERNAL,
     POINTER, ALLOCATABLE, DIMENSION, VOLATILE, INTENT(INOUT), or
     INTENT(OUT) attribute shall not be specified.
C528 (R501)  If the VALUE attribute is specified, the length type
     parameter values shall be omitted or specified by initialization
     expressions.
C529 (R501)  The VALUE attribute shall not be specified for a dummy
     procedure.
C530 (R501)  The ALLOCATABLE, POINTER, or OPTIONAL attribute shall not be
     specified for adummy argument of a procedure that has
     aproc-language-binding-spec.
C532 (R501)  If a language-binding-spec is specified, the entity declared
     shall be an interoperable variable.
C533 (R501)  If a language-binding-spec with a NAME= specifier appears,
     the entity-decl-list shall consist of a single entity-decl.
C534 (R503)  The PROTECTED attribute is permitted only in the
     specification part of a module.
C535 (R501)  The PROTECTED attribute is permitted only for a procedure
     pointer or named variable that is not in a common block.
C536 (R501)  If the PROTECTED attribute is specified, the EXTERNAL,
     INTRINSIC, or PARAMETER attribute shall not be specified.

C507, C509-C517, C519, C522-C523, C526-C530, C532-C533, C535-C536 are currently not checked - issue #259.

subclass_names = [][source]
use_names = ['Declaration_Type_Spec', 'Attr_Spec_List', 'Entity_Decl_List'][source]
static get_attr_spec_list_cls()[source]

Return the type used to match the attr-spec-list

This method allows to overwrite the type used in match() in derived classes (e.g., fparser.two.Fortran2008.Type_Declaration_Stmt).

This cannot be implemented as an attribute because the relevant type Attr_Spec_List is auto-generated at the end of the file using the use_names property of the class.

static add_to_symbol_table(result)[source]

Capture the declared symbols in the symbol table of the current scoping region

Parameters:

result (NoneType or (Declaration_Type_Spec, Attr_Spec_List or NoneType, Entity_Decl_List)) – the declared type, attributes and entities or None

classmethod match(string)[source]

Attempts to match the supplied string as a type declaration. If the match is successful the declared symbols are added to the symbol table of the current scope (if there is one).

Note that this is implemented as a class method to allow parameterizing the type used to match attr-spec-list via get_attr_spec_list_cls().

Parameters:

string (str) – the string to match.

Returns:

3-tuple containing the matched declaration.

Return type:

(Declaration_Type_Spec, Attr_Spec_List or NoneType, Entity_Decl_List)

static match2(string)[source]
tostr()[source]
Returns:

the text representation of this node.

Return type:

str

class fparser.two.Fortran2003.Declaration_Type_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<declaration-type-spec> = <intrinsic-type-spec>
                          | TYPE ( <derived-type-spec> )
                          | CLASS ( <derived-type-spec> )
                          | CLASS ( * )
subclass_names = ['Intrinsic_Type_Spec'][source]
use_names = ['Derived_Type_Spec'][source]
static match(string)[source]

Implements the matching of a declaration type specification.

Parameters:

string (str) – the reader or string to match as a declaration type specification.

Returns:

A tuple of size 2 containing a string with the value ‘TYPE’ or ‘CLASS’ and a ‘Derived_Type_Spec’ instance if there is a match or None if not.

Return type:

Optional[Tuple[Str, py:class:fparser.two.Fortran2003.Derived_Type_Spec]

tostr()[source]
class fparser.two.Fortran2003.Dimension_Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.CALLBase

<dimension-attr-spec> = DIMENSION ( <array-spec> )
subclass_names = [][source]
use_names = ['Array_Spec'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Intent_Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.CALLBase

<intent-attr-spec> = INTENT ( <intent-spec> )
subclass_names = [][source]
use_names = ['Intent_Spec'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<attr-spec> = <access-spec>
              | ALLOCATABLE
              | ASYNCHRONOUS
              | DIMENSION ( <array-spec> )
              | EXTERNAL
              | INTENT ( <intent-spec> )
              | INTRINSIC
              | <language-binding-spec>
              | OPTIONAL
              | PARAMETER
              | POINTER
              | PROTECTED
              | SAVE
              | TARGET
              | VALUE
              | VOLATILE
subclass_names = ['Access_Spec', 'Language_Binding_Spec', 'Dimension_Attr_Spec', 'Intent_Attr_Spec'][source]
use_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Entity_Decl(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<entity-decl> = <object-name> [ ( <array-spec> ) ]
    [ * <char-length> ] [ <initialization> ]
                | <function-name> [ * <char-length> ]
subclass_names = [][source]
use_names = ['Object_Name', 'Array_Spec', 'Char_Length', 'Initialization', 'Function_Name'][source]
static match(string, target=False)[source]
tostr()[source]
get_name()[source]

Provides the entity name as an instance of the Name class.

Return type:

Name

class fparser.two.Fortran2003.Object_Name(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<object-name> = <name>
subclass_names = ['Name'][source]
class fparser.two.Fortran2003.Initialization(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<initialization> =  = <initialization-expr>
                   | => <null-init>
subclass_names = [][source]
use_names = ['Initialization_Expr', 'Null_Init'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Null_Init(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

null-init is function-reference

where:

function-reference shall be a reference to the NULL
                   intrinsic function with no arguments.
subclass_names = ['Function_Reference'][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Access_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

Fortran2003 Rule R508:

<access-spec> = PUBLIC
                | PRIVATE
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Language_Binding_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 Rule R509:

<language-binding-spec> = BIND ( C [ ,
    NAME = <scalar-char-initialization-expr> ] )
subclass_names = [][source]
use_names = ['Scalar_Char_Initialization_Expr'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Array_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 Rule R510:

<array-spec> = <explicit-shape-spec-list>
               | <assumed-shape-spec-list>
               | <deferred-shape-spec-list>
               | <assumed-size-spec>
subclass_names = ['Assumed_Size_Spec', 'Explicit_Shape_Spec_List', 'Assumed_Shape_Spec_List', 'Deferred_Shape_Spec_List'][source]
class fparser.two.Fortran2003.Explicit_Shape_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

<explicit-shape-spec> = [ <lower-bound> : ] <upper-bound>
subclass_names = [][source]
use_names = ['Lower_Bound', 'Upper_Bound'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Lower_Bound(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<lower-bound> = <specification-expr>
subclass_names = ['Specification_Expr'][source]
class fparser.two.Fortran2003.Upper_Bound(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<upper-bound> = <specification-expr>
subclass_names = ['Specification_Expr'][source]
class fparser.two.Fortran2003.Assumed_Shape_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

Fortran2003 Rule R514:

<assumed-shape-spec> = [ <lower-bound> ] :
subclass_names = [][source]
use_names = ['Lower_Bound'][source]
static match(string)[source]
class fparser.two.Fortran2003.Deferred_Shape_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

Fortran2003 Rule R515:

<deferred_shape_spec> = :
subclass_names = [][source]
static match(string)[source]
class fparser.two.Fortran2003.Assumed_Size_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 Rule R516:

<assumed-size-spec> = [ <explicit-shape-spec-list> , ]
    [ <lower-bound> : ] *
subclass_names = [][source]
use_names = ['Explicit_Shape_Spec_List', 'Lower_Bound'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Intent_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<intent-spec> = IN
                | OUT
                | INOUT
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Access_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

Fortran2003 Rule R518:

<access-stmt> = <access-spec> [ [ :: ] <access-id-list> ]
subclass_names = [][source]
use_names = ['Access_Spec', 'Access_Id_List'][source]
tostr[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Access_Id(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 Rule R519:

<access-id> = <use-name>
              | <generic-spec>
subclass_names = ['Use_Name', 'Generic_Spec'][source]
class fparser.two.Fortran2003.Object_Name_Deferred_Shape_Spec_List_Item(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<..> =  <object-name> [ ( <deferred-shape-spec-list> ) ]
subclass_names = ['Object_Name'][source]
use_names = ['Deferred_Shape_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Allocatable_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

Fortran2003 Rule R520:

<allocateble-stmt> = ALLOCATABLE [ :: ] <object-name> [
    ( <deferred-shape-spec-list> ) ] [ , <object-name>
    [ ( <deferred-shape-spec-list> ) ] ]...
subclass_names = [][source]
use_names = ['Object_Name_Deferred_Shape_Spec_List_Item_List'][source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Asynchronous_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

Fortran2003 Rule R521:

<asynchronous-stmt> = ASYNCHRONOUS [ :: ] <object-name-list>
subclass_names = [][source]
use_names = ['Object_Name_List'][source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Bind_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 Rule R522:

<bind-stmt> = <language-binding-spec> [ :: ] <bind-entity-list>
subclass_names = [][source]
use_names = ['Language_Binding_Spec', 'Bind_Entity_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Bind_Entity(string, parent_cls=None)[source]

Bases: fparser.two.utils.BracketBase

<bind-entity> = <entity-name>
                | / <common-block-name> /
subclass_names = ['Entity_Name'][source]
use_names = ['Common_Block_Name'][source]
static match(string)[source]

A generic match method for all types of bracketed expressions.

Parameters:
  • brackets (str) – the format of the left and right brackets provided as a string, for example ‘()’

  • cls – the class to match the content within the brackets :type cls: subclass of fparser.two.utils.Base

  • string (str) – the content to match

  • require_cls (bool) – whether the class and associated content is mandatory (True) or optional (False). The default is True.

Returns:

None if there is no match, otherwise a tuple with the first and third entries being strings containing the left and right brackets respectively and the second entry being either None or an instance of the class provided as the second argument (cls).

Return type:

‘NoneType’, ( str, NoneType, str) or ( str, cls, str )

class fparser.two.Fortran2003.Data_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran 2003 Rule R524:

<data-stmt> = DATA <data-stmt-set> [ [ , ] <data-stmt-set> ]...
subclass_names = [][source]
use_names = ['Data_Stmt_Set'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Data_Stmt_Set(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran2003 Rule R525:

<data-stmt-set> = <data-stmt-object-list> / <data-stmt-value-list> /
subclass_names = [][source]
use_names = ['Data_Stmt_Object_List', 'Data_Stmt_Value_List'][source]
data_stmt_object_list[source]
data_stmt_value_list[source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Data_Stmt_Object(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 Rule R526:

<data-stmt-object> = <variable>
                     | <data-implied-do>
subclass_names = ['Variable', 'Data_Implied_Do'][source]
class fparser.two.Fortran2003.Data_Implied_Do(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 Rule R527:

<data-implied-do> = ( <data-i-do-object-list> ,
    <data-i-do-variable> = <scalar-int-expr > ,
    <scalar-int-expr> [ , <scalar-int-expr> ] )
subclass_names = [][source]
use_names = ['Data_I_Do_Object_List', 'Data_I_Do_Variable', 'Scalar_Int_Expr'][source]
data_i_do_object_list[source]
data_i_do_variable[source]
scalar_int_expr1[source]
scalar_int_expr2[source]
scalar_int_expr3[source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Data_I_Do_Object(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<data-i-do-object> = <array-element>
                     | <scalar-structure-component>
                     | <data-implied-do>
subclass_names = ['Array_Element', 'Scalar_Structure_Component', 'Data_Implied_Do'][source]
class fparser.two.Fortran2003.Data_I_Do_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<data-i-do-variable> = <scalar-int-variable>
subclass_names = ['Scalar_Int_Variable'][source]
class fparser.two.Fortran2003.Data_Stmt_Value(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<data-stmt-value> = [ <data-stmt-repeat> * ] <data-stmt-constant>
subclass_names = ['Data_Stmt_Constant'][source]
use_names = ['Data_Stmt_Repeat'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Data_Stmt_Repeat(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<data-stmt-repeat> = <scalar-int-constant>
                     | <scalar-int-constant-subobject>
subclass_names = ['Scalar_Int_Constant', 'Scalar_Int_Constant_Subobject'][source]
class fparser.two.Fortran2003.Data_Stmt_Constant(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 Rule R532:

<data-stmt-constant> = <scalar-constant>
                       | <scalar-constant-subobject>
                       | <signed-int-literal-constant>
                       | <signed-real-literal-constant>
                       | <null-init>
                       | <structure-constructor>
subclass_names = ['Scalar_Constant', 'Scalar_Constant_Subobject', 'Signed_Int_Literal_Constant',...[source]
class fparser.two.Fortran2003.Int_Constant_Subobject(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 Rule R533:

<int-constant-subobject> = <constant-subobject>
subclass_names = ['Constant_Subobject'][source]
class fparser.two.Fortran2003.Constant_Subobject(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 Rule R534:

<constant-subobject> = <designator>
subclass_names = ['Designator'][source]
class fparser.two.Fortran2003.Dimension_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran 2003 Rule R535:

<dimension-stmt> = DIMENSION [ :: ] <array-name> ( <array-spec> )
    [ , <array-name> ( <array-spec> ) ]...
subclass_names = [][source]
use_names = ['Array_Name', 'Array_Spec'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Intent_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<intent-stmt> = INTENT ( <intent-spec> ) [ :: ] <dummy-arg-name-list>
subclass_names = [][source]
use_names = ['Intent_Spec', 'Dummy_Arg_Name_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Optional_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<optional-stmt> = OPTIONAL [ :: ] <dummy-arg-name-list>
subclass_names = [][source]
use_names = ['Dummy_Arg_Name_List'][source]
tostr[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Parameter_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.CALLBase

<parameter-stmt> = PARAMETER ( <named-constant-def-list> )
subclass_names = [][source]
use_names = ['Named_Constant_Def_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Named_Constant_Def(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

<named-constant-def> = <named-constant> = <initialization-expr>
subclass_names = [][source]
use_names = ['Named_Constant', 'Initialization_Expr'][source]
static match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Cray_Pointer_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

cray-pointer-stmt is POINTER cray-pointer-decl-list
subclass_names = [][source]
use_names = ['Cray_Pointer_Decl_List'][source]
static match(string)[source]

Implements the matching for a Cray-pointer statement.

Parameters:

string (fparser.common.readfortran.FortranReaderBase or str) – the reader or string to match as a Cray-pointer statement.

Returns:

a tuple of size 2 containing a string with the name “POINTER” and a cray-pointer-decl-list, if there is a match, or None if there is not.

Return type:

(str, Cray_Pointer_Decl_List) or None

class fparser.two.Fortran2003.Cray_Pointer_Decl(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

cray-pointer-decl is ( cray-pointer-name, cray-pointee-decl )
use_names = ['Cray_Pointer_Name', 'Cray_Pointee_Name', 'Cray_Pointee_Decl'][source]
static match(string)[source]

Implements the matching for a Cray-pointer declaration.

Parameters:

string (str) – the string to match as a Cray-pointer declaration.

Returns:

None if there is no match, otherwise a tuple of size 2 containing the name of the pointer as the first argument and either the name of the pointee as the second argument or a Cray-pointee declaration.

Return type:

None, (Name, Name) or (Name, Cray_Pointee_Decl)

tostr()[source]
Returns:

this Cray-pointee declaration as a string

Return type:

str

Raises:
  • InternalError – if the internal items list variable is not the expected size.

  • InternalError – if the first element of the internal items list is None or is empty.

  • InternalError – if the second element of the internal items list is None or is empty.

class fparser.two.Fortran2003.Cray_Pointee_Decl(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

cray-pointee-decl is cray-pointee-name ( cray-pointee-array-spec )
subclass_names = [][source]
use_names = ['Cray_Pointee_Name', 'Cray_Pointee_Array_Spec'][source]
static match(string)[source]

Implements the matching for a Cray-pointee declaration.

Parameters:

string (str) – the string to match as a Cray-pointee declaration.

Returns:

None if there is no match, otherwise a tuple of size 2 containing the name of the pointee as the first argument and a Cray-pointee array spec as the second argument.

Return type:

None or (Name, Cray_Pointee_Array_Spec)

class fparser.two.Fortran2003.Cray_Pointee_Array_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

cray-pointee-array-spec is explicit-shape-spec-list
                        or assumed-size-spec

The above two forms of declaration are the only ones allowed according to http://pubs.cray.com/content/S-3901/8.6/cray-fortran-reference-manual-s-3901-86/types or https://docs.oracle.com/cd/E19957-01/805-4941/z40000a54ba7/index.html

subclass_names = ['Assumed_Size_Spec', 'Explicit_Shape_Spec_List'][source]
class fparser.two.Fortran2003.Pointer_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<pointer-stmt> = POINTER [ :: ] <pointer-decl-list>
subclass_names = [][source]
use_names = ['Pointer_Decl_List'][source]
tostr[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Pointer_Decl(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<pointer-decl> = <object-name> [ ( <deferred-shape-spec-list> ) ]
                 | <proc-entity-name>
subclass_names = ['Proc_Entity_Name', 'Object_Name'][source]
use_names = ['Deferred_Shape_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Protected_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<protected-stmt> = PROTECTED [ :: ] <entity-name-list>
subclass_names = [][source]
use_names = ['Entity_Name_List'][source]
tostr[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Save_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<save-stmt> = SAVE [ [ :: ] <saved-entity-list> ]
subclass_names = [][source]
use_names = ['Saved_Entity_List'][source]
tostr[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Saved_Entity(string, parent_cls=None)[source]

Bases: fparser.two.utils.BracketBase

<saved-entity> = <object-name>
                 | <proc-pointer-name>
                 | / <common-block-name> /
subclass_names = ['Object_Name', 'Proc_Pointer_Name'][source]
use_names = ['Common_Block_Name'][source]
static match(string)[source]

A generic match method for all types of bracketed expressions.

Parameters:
  • brackets (str) – the format of the left and right brackets provided as a string, for example ‘()’

  • cls – the class to match the content within the brackets :type cls: subclass of fparser.two.utils.Base

  • string (str) – the content to match

  • require_cls (bool) – whether the class and associated content is mandatory (True) or optional (False). The default is True.

Returns:

None if there is no match, otherwise a tuple with the first and third entries being strings containing the left and right brackets respectively and the second entry being either None or an instance of the class provided as the second argument (cls).

Return type:

‘NoneType’, ( str, NoneType, str) or ( str, cls, str )

class fparser.two.Fortran2003.Proc_Pointer_Name(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<proc-pointer-name> = <name>
subclass_names = ['Name'][source]
class fparser.two.Fortran2003.Target_Entity_Decl(string, parent_cls=None)[source]

Bases: Entity_Decl

<target-entity-decl> = <object-name> [ ( <array-spec> ) ]
subclass_names = [][source]
use_names = ['Object_Name', 'Array_Spec'][source]
static match(string)[source]
class fparser.two.Fortran2003.Target_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<target-stmt> = TARGET [ :: ] <target-entity-decl-list>
subclass_names = [][source]
use_names = ['Target_Entity_Decl_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Value_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<value-stmt> = VALUE [ :: ] <dummy-arg-name-list>
subclass_names = [][source]
use_names = ['Dummy_Arg_Name_List'][source]
tostr[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Volatile_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<volatile-stmt> = VOLATILE [ :: ] <object-name-list>
subclass_names = [][source]
use_names = ['Object_Name_List'][source]
tostr[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Implicit_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<implicit-stmt> = IMPLICIT <implicit-spec-list>
                  | IMPLICIT NONE

Has attributes:

items : ({'NONE', Implicit_Spec_List},)
subclass_names = [][source]
use_names = ['Implicit_Spec_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Implicit_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<implicit-spec> = <declaration-type-spec> ( <letter-spec-list> )
subclass_names = [][source]
use_names = ['Declaration_Type_Spec', 'Letter_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Letter_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<letter-spec> = <letter> [ - <letter> ]
subclass_names = [][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Namelist_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran 2003 rule R552:

namelist-stmt is NAMELIST
                 / namelist-group-name / namelist-group-object-list
                 [ [,] / namelist-group-name /
                 namelist-group-object-list ] ...
subclass_names = [][source]
use_names = ['Namelist_Group_Name', 'Namelist_Group_Object_List'][source]
static match(string)[source]

Implements the matching for a Namelist_Stmt.

Parameters:

string (str) – a string containing the code to match.

Returns:

None if there is no match, otherwise a tuple containing 2-tuples with a namelist name and a namelist object list.

Return type:

Optional[Tuple[Tuple[ fparser.two.Fortran2003.Namelist_Group_Name, fparser.two.Fortran2003.Namelist_Group_Object_List]]]

tostr()[source]
Returns:

this Namelist_Stmt as a string.

Return type:

str

class fparser.two.Fortran2003.Namelist_Group_Object(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<namelist-group-object> = <variable-name>
subclass_names = ['Variable_Name'][source]
class fparser.two.Fortran2003.Equivalence_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<equivalence-stmt> = EQUIVALENCE <equivalence-set-list>
subclass_names = [][source]
use_names = ['Equivalence_Set_List'][source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Equivalence_Set(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<equivalence-set> = ( <equivalence-object> , <equivalence-object-list> )
subclass_names = [][source]
use_names = ['Equivalence_Object', 'Equivalence_Object_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Equivalence_Object(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<equivalence-object> = <variable-name>
                       | <array-element>
                       | <substring>
subclass_names = ['Variable_Name', 'Array_Element', 'Substring'][source]
class fparser.two.Fortran2003.Common_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<common-stmt> = COMMON [ / [ <common-block-name> ] / ]
    <common-block-object-list> [ [ , ] / [ <common-block-name> ]
    / <common-block-object-list> ]...
subclass_names = [][source]
use_names = ['Common_Block_Name', 'Common_Block_Object_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Common_Block_Object(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<common-block-object> = <variable-name> [ ( <explicit-shape-spec-list> ) ]
                        | <proc-pointer-name>
subclass_names = ['Proc_Pointer_Name', 'Variable_Name'][source]
use_names = ['Variable_Name', 'Explicit_Shape_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<variable> = <designator>
subclass_names = ['Designator'][source]
class fparser.two.Fortran2003.Variable_Name(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<variable-name> = <name>
subclass_names = ['Name'][source]
class fparser.two.Fortran2003.Designator(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R603:

designator is object-name
           or array-element
           or array-section
           or structure-component
           or substring
subclass_names = ['Object_Name', 'Array_Element', 'Array_Section', 'Structure_Component', 'Substring'][source]
class fparser.two.Fortran2003.Logical_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<logical-variable> = <variable>
subclass_names = ['Variable'][source]
class fparser.two.Fortran2003.Default_Logical_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<default-logical-variable> = <variable>
subclass_names = ['Variable'][source]
class fparser.two.Fortran2003.Char_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<char-variable> = <variable>
subclass_names = ['Variable'][source]
class fparser.two.Fortran2003.Default_Char_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<default-char-variable> = <variable>
subclass_names = ['Variable'][source]
class fparser.two.Fortran2003.Int_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<int-variable> = <variable>
subclass_names = ['Variable'][source]
class fparser.two.Fortran2003.Substring(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<substring> = <parent-string> ( <substring-range> )
subclass_names = [][source]
use_names = ['Parent_String', 'Substring_Range'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Parent_String(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<parent-string> = <scalar-variable-name>
                  | <array-element>
                  | <scalar-structure-component>
                  | <scalar-constant>
subclass_names = ['Scalar_Variable_Name', 'Array_Element', 'Scalar_Structure_Component', 'Scalar_Constant'][source]
class fparser.two.Fortran2003.Substring_Range(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

<substring-range> = [ <scalar-int-expr> ] : [ <scalar-int-expr> ]
subclass_names = [][source]
use_names = ['Scalar_Int_Expr'][source]
static match(string)[source]
class fparser.two.Fortran2003.Data_Ref(string, parent_cls=None)[source]

Bases: fparser.two.utils.SequenceBase

Fortran 2003 Rule R612:

data-ref is part-ref [ % part-ref ] ...

If there is only one part-ref then return a ‘Part_Ref’ object (or another object from a matching sub-rule). If there is more than one part-ref then return a ‘Data_Ref’ object containing the part-ref’s.

subclass_names = ['Part_Ref'][source]
use_names = [][source]
static match(string)[source]

Implements the matching for a data-reference. This defines a series of dereferences e.g. a%b%c.

If there is more than one part-ref then return a ‘Data_Ref’ object containing the part-ref’s, otherwise return ‘None’. A single ‘part-ref’ is purposely not matched here.

Parameters:

string (str) – Fortran code to check for a match

Returns:

None if there is no match, or a tuple containing the matched operator as a string and another tuple containing the matched subclasses.

Return type:

NoneType or (str, (obj, obj, …))

class fparser.two.Fortran2003.Part_Ref(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<part-ref> = <part-name> [ ( <section-subscript-list> ) ]
subclass_names = ['Part_Name'][source]
use_names = ['Section_Subscript_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Structure_Component(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<structure-component> = <data-ref>
subclass_names = ['Data_Ref'][source]
class fparser.two.Fortran2003.Type_Param_Inquiry(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<type-param-inquiry> = <designator> % <type-param-name>
subclass_names = [][source]
use_names = ['Designator', 'Type_Param_Name'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Array_Element(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<array-element> = <data-ref>
subclass_names = ['Data_Ref'][source]
class fparser.two.Fortran2003.Array_Section(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<array-section> = <data-ref> [ ( <substring-range> ) ]
subclass_names = ['Data_Ref'][source]
use_names = ['Substring_Range'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Subscript(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<subscript> = <scalar-int-expr>
subclass_names = ['Scalar_Int_Expr'][source]
class fparser.two.Fortran2003.Section_Subscript(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<section-subscript> = <subscript>
                      | <subscript-triplet>
                      | <vector-subscript>
subclass_names = ['Subscript_Triplet', 'Vector_Subscript', 'Subscript'][source]
class fparser.two.Fortran2003.Subscript_Triplet(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<subscript-triplet> = [ <subscript> ] : [ <subscript> ] [ : <stride> ]
subclass_names = [][source]
use_names = ['Subscript', 'Stride'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Stride(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<stride> = <scalar-int-expr>
subclass_names = ['Scalar_Int_Expr'][source]
class fparser.two.Fortran2003.Vector_Subscript(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<vector-subscript> = <int-expr>
subclass_names = ['Int_Expr'][source]
class fparser.two.Fortran2003.Allocate_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 rule R623:

allocate-stmt is ALLOCATE ( [ type-spec :: ] allocation-list
                            [, alloc-opt-list ] )

Subject to the following constraints:

C622 (R629) Each allocate-object shall be a nonprocedure pointer or an

allocatable variable.

C623 (R623) If any allocate-object in the statement has a deferred type

parameter, either type-spec or SOURCE= shall appear.

C624 (R623) If a type-spec appears, it shall specify a type with which

each allocate-object is type compatible.

C625 (R623) If any allocate-object is unlimited polymorphic, either

type-spec or SOURCE= shall appear.

C626 (R623) A type-param-value in a type-spec shall be an asterisk if and

only if each allocate-object is a dummy argument for which the corresponding type parameter is assumed.

C627 (R623) If a type-spec appears, the kind type parameter values of each

allocate-object shall be the same as the corresponding type parameter values of the type-spec.

C628 (R628) An allocate-shape-spec-list shall appear if and only if the

allocate-object is an array.

C629 (R628) The number of allocate-shape-specs in an

allocate-shape-spec-list shall be the same as the rank of the allocate-object.

C630 (R624) No alloc-opt shall appear more than once in a given

alloc-opt-list.

C631 (R623) If SOURCE= appears, type-spec shall not appear and

allocation-list shall contain only one allocate-object, which shall be type compatible (5.1.1.2) with source-expr.

C632 (R623) The source-expr shall be a scalar or have the same rank as

allocate-object.

C633 (R623) Corresponding kind type parameters of allocate-object and

source-expr shall have the same values.

None of these constraints are currently applied - issue #355.

subclass_names = [][source]
use_names = ['Type_Spec', 'Allocation_List', 'Alloc_Opt_List'][source]
classmethod match(string)[source]

Attempts to match the supplied string as an Allocate_Stmt.

Parameters:

string (str) – the string to attempt to match.

Returns:

A 2-tuple giving the Type_Spec and Allocation_List if the match is successful, None otherwise.

Return type:

Optional[ Tuple[Optional[fparser.two.Fortran2003.Type_Spec], fparser.two.Fortran2003.Allocation_List]]

classmethod alloc_opt_list()[source]
Returns:

the Fortran2003 flavour of Alloc_Opt_List.

Return type:

type

tostr()[source]
class fparser.two.Fortran2003.Stat_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<stat-variable> = <scalar-int-variable>
subclass_names = ['Scalar_Int_Variable'][source]
class fparser.two.Fortran2003.Errmsg_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<errmsg-variable> = <scalar-default-char-variable>
subclass_names = ['Scalar_Default_Char_Variable'][source]
class fparser.two.Fortran2003.Source_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<source-expr> = <expr>
subclass_names = ['Expr'][source]
class fparser.two.Fortran2003.Alloc_Opt(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

<alloc-opt> = STAT = <stat-variable>
              | ERRMSG = <errmsg-variable>
              | SOURCE = <source-expr>
subclass_names = [][source]
use_names = ['Stat_Variable', 'Errmsg_Variable', 'Source_Expr'][source]
_keyword_pairs = [('STAT',), ('ERRMSG',), ('SOURCE',)][source]
classmethod match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Allocation(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<allocation> = <allocate-object> [ ( <allocate-shape-spec-list> ) ]
             | <variable-name>
subclass_names = ['Variable_Name', 'Allocate_Object'][source]
use_names = ['Allocate_Shape_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Allocate_Object(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<allocate-object> = <variable-name>
                    | <structure-component>
subclass_names = ['Variable_Name', 'Structure_Component'][source]
class fparser.two.Fortran2003.Allocate_Shape_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

<allocate-shape-spec> = [ <lower-bound-expr> : ] <upper-bound-expr>
subclass_names = [][source]
use_names = ['Lower_Bound_Expr', 'Upper_Bound_Expr'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Lower_Bound_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<lower-bound-expr> = <scalar-int-expr>
subclass_names = ['Scalar_Int_Expr'][source]
class fparser.two.Fortran2003.Upper_Bound_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<upper-bound-expr> = <scalar-int-expr>
subclass_names = ['Scalar_Int_Expr'][source]
class fparser.two.Fortran2003.Nullify_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.CALLBase

<nullify-stmt> = NULLIFY ( <pointer-object-list> )
subclass_names = [][source]
use_names = ['Pointer_Object_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Pointer_Object(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<pointer-object> = <variable-name>
                   | <structure-component>
                   | <proc-pointer-name>
subclass_names = ['Variable_Name', 'Structure_Component', 'Proc_Pointer_Name'][source]
class fparser.two.Fortran2003.Deallocate_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<deallocate-stmt> = DEALLOCATE ( <allocate-object-list> [
    , <dealloc-opt-list> ] )
subclass_names = [][source]
use_names = ['Allocate_Object_List', 'Dealloc_Opt_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Dealloc_Opt(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

<dealloc-opt> = STAT = <stat-variable>
                | ERRMSG = <errmsg-variable>
subclass_names = [][source]
use_names = ['Stat_Variable', 'Errmsg_Variable'][source]
static match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Scalar_Char_Initialization_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Base class for Fortran 2003 syntax rules.

All Base classes have the following attributes:

self.string - original argument to construct a class instance, its
              type is either str or FortranReaderBase.
self.item   - Line instance (holds label) or None.
Parameters:
subclass_names = ['Char_Initialization_Expr'][source]
class fparser.two.Fortran2003.Primary(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R701:

primary is intrinsic_function_reference
        or constant
        or designator
        or array-constructor
        or structure-constructor
        or function-reference
        or type-param-inquiry
        or type-param-name
        or ( expr )

intrinsic_function_reference is not part of rule R701 but is required for fparser to recognise intrinsic functions. This is placed before array-constructor in the subclass_names list so that an intrinsic is not (incorrectly) matched as an array (as class Base matches rules in list order).

Note, ( expr ) is implemented in the Parenthesis subclass.

subclass_names = ['Intrinsic_Function_Reference', 'Constant', 'Designator', 'Array_Constructor',...[source]
class fparser.two.Fortran2003.Parenthesis(string, parent_cls=None)[source]

Bases: fparser.two.utils.BracketBase

Part of Fortran 2003 rule R701:

parenthesis = ( expr )
subclass_names = [][source]
use_names = ['Expr'][source]
static match(string)[source]

Implements the matching of round brackets surrounding an expression which is specified as one of the matches in R701.

Parameters:

string (str) – Fortran code to check for a match.

Returns:

None if there is no match, or a 3-tuple containing the left bracket, the matched expression and the right bracket.

Return type:

NoneType or (str, subclass of fparser.two.utils.Base, str)

class fparser.two.Fortran2003.Level_1_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.UnaryOpBase

<level-1-expr> = [ <defined-unary-op> ] <primary>
<defined-unary-op> = . <letter> [ <letter> ]... .
subclass_names = ['Primary'][source]
use_names = [][source]
static match(string)[source]
class fparser.two.Fortran2003.Defined_Unary_Op(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R703:

defined-unary-op is . letter [ letter ]... .

C704 (R703) A defined-unary-op shall not contain more than 63 letters and shall not be the same as any intrinsic-operator or logical-literal-constant.

Implemented in Defined_Op class.

subclass_names = ['Defined_Op'][source]
class fparser.two.Fortran2003.Defined_Op(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

Utility class that Implements the functionality of rules R703 and R723 (as the rules are the same):

defined-op is . letter [ letter ]... .

C704 (R723) A defined-binary-op shall not contain more than 63 letters and shall not be the same as any intrinsic-operator or logical-literal-constant.

C704 (R703) A defined-unary-op shall not contain more than 63 letters and shall not be the same as any intrinsic-operator or logical-literal-constant.

subclass_names = [][source]
static match(string)[source]

Implements the matching for a (user) Defined Unary or Binary Operator.

Parameters:

string (str) – Fortran code to check for a match

Returns:

None if there is no match, or a tuple containing the matched operator as a string

Return type:

None or (str)

class fparser.two.Fortran2003.Mult_Operand(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<mult-operand> = <level-1-expr> [ <power-op> <mult-operand> ]
<power-op> = **
subclass_names = ['Level_1_Expr'][source]
use_names = ['Mult_Operand'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Add_Operand(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

Fortran 2003 rule R705:

add-operand is [ add-operand mult-op ] mult-operand

Rule R705 is implemented in two parts, the first with the optional part included (in the match method for this class) and the second without the optional part (specified in subclass_names).

Note rule R708 (mult-op is * or /) is implemented directly here as the mult_op pattern.

There is potential to accidentally match a sign in an exponent as the plus/minus sign in a level-2-expr. If this were to happen then it is possible to end up matching a * or / (a level 1 expression) before matching a valid + or - which would normally result in no match overall as * or / are matched after + or -. This situation is avoided by tokenising the string before performing the match so that any numerical constants involving exponents are replaced by simple symbols. (The tokenisation is performed by fparser.common.splitline.string_replace_map.)

subclass_names = ['Mult_Operand'][source]
use_names = ['Mult_Operand'][source]
static match(string)[source]

Implement the matching for the add-operand rule. Makes use of the pre-defined mult_op pattern and the BinaryOpBase baseclass.

Parameters:

string (str) – the string to match.

Returns:

a tuple of size 3 containing an fparser2 class instance matching a level-2-expr expression, a string containing the matched operator and an fparser2 class instance matching a mult-operand if there is a match, or None if there is not.

Return type:

(subclass of fparser.two.utils.Base, str, subclass of fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Level_2_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<level-2-expr> = [ [ <level-2-expr> ] <add-op> ] <add-operand>
<level-2-expr> = [ <level-2-expr> <add-op> ] <add-operand>
                 | <level-2-unary-expr>
<add-op>   = +
             | -
subclass_names = ['Level_2_Unary_Expr'][source]
use_names = ['Level_2_Expr'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Level_2_Unary_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.UnaryOpBase

<level-2-unary-expr> = [ <add-op> ] <add-operand>
subclass_names = ['Add_Operand'][source]
use_names = [][source]
static match(string)[source]
class fparser.two.Fortran2003.Level_3_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<level-3-expr> = [ <level-3-expr> <concat-op> ] <level-2-expr>
<concat-op>    = //
subclass_names = ['Level_2_Expr'][source]
use_names = ['Level_3_Expr'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Level_4_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<level-4-expr> = [ <level-3-expr> <rel-op> ] <level-3-expr>
<rel-op> = .EQ. | .NE. | .LT. | .LE. | .GT. | .GE. | == |
    /= | < | <= | > | >=
subclass_names = ['Level_3_Expr'][source]
use_names = [][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.And_Operand(string, parent_cls=None)[source]

Bases: fparser.two.utils.UnaryOpBase

<and-operand> = [ <not-op> ] <level-4-expr>
<not-op> = .NOT.
subclass_names = ['Level_4_Expr'][source]
use_names = [][source]
static match(string)[source]
class fparser.two.Fortran2003.Or_Operand(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<or-operand> = [ <or-operand> <and-op> ] <and-operand>
<and-op> = .AND.
subclass_names = ['And_Operand'][source]
use_names = ['Or_Operand', 'And_Operand'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Equiv_Operand(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<equiv-operand> = [ <equiv-operand> <or-op> ] <or-operand>
<or-op>  = .OR.
subclass_names = ['Or_Operand'][source]
use_names = ['Equiv_Operand'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Level_5_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<level-5-expr> = [ <level-5-expr> <equiv-op> ] <equiv-operand>
<equiv-op> = .EQV.
           | .NEQV.
subclass_names = ['Equiv_Operand'][source]
use_names = ['Level_5_Expr'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<expr> = [ <expr> <defined-binary-op> ] <level-5-expr>
<defined-binary-op> = . <letter> [ <letter> ]... .
subclass_names = ['Level_5_Expr'][source]
use_names = ['Expr'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Defined_Binary_Op(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R723:

defined-binary-op is . letter [ letter ]... .

C704 (R723) A defined-binary-op shall not contain more than 63 letters and shall not be the same as any intrinsic-operator or logical-literal-constant.

Implemented in Defined_Op class.

subclass_names = ['Defined_Op'][source]
class fparser.two.Fortran2003.Logical_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R724:

logical-expr is expr

C705 logical-expr shall be of type logical.

subclass_names = [][source]
static match(string)[source]

Implements the matching for a logical expression.

Note, whilst we exclude Signed_Int_Literal_Constant and Signed_Real_Literal_Constant, it seems that it is not possible to create these from code as a “-” sign is treated as a unary operator.

Parameters:

string (str) – Fortran code to check for a match.

Returns:

None if there is no match, or an fparser2 class instance containing the matched expression.

Return type:

NoneType or fparser.two.utils.Base

class fparser.two.Fortran2003.Char_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R725:

char-expr is expr

C706 char-expr shall be of type character.

subclass_names = [][source]
static match(string)[source]

Implements the matching for a character expression.

Parameters:

string (str) – Fortran code to check for a match.

Returns:

None if there is no match, or an fparser2 class instance containing the matched expression.

Return type:

NoneType or fparser.two.utils.Base

class fparser.two.Fortran2003.Default_Char_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R726:

default-char-expr is expr

C707 default-char-expr shall be of type default character.

subclass_names = [][source]
static match(string)[source]

Implements the matching for a default character expression.

Parameters:

string (str) – Fortran code to check for a match.

Returns:

None if there is no match, or an fparser2 class instance containing the matched expression.

Return type:

NoneType or fparser.two.utils.Base

class fparser.two.Fortran2003.Int_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R727:

int-expr is expr

C708 int-expr shall be of type integer.

subclass_names = [][source]
static match(string)[source]

Implements the matching for an integer expression.

Parameters:

string (str) – Fortran code to check for a match.

Returns:

None if there is no match, or an fparser2 class instance containing the matched expression.

Return type:

NoneType or fparser.two.utils.Base

class fparser.two.Fortran2003.Numeric_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R728:

numeric-expr is expr

C709 numeric-expr shall be of type integer, real or complex.

subclass_names = [][source]
static match(string)[source]

Implements the matching for a numeric expression.

Parameters:

string (str) – Fortran code to check for a match.

Returns:

None if there is no match, or an fparser2 class instance containing the matched expression.

Return type:

NoneType or fparser.two.utils.Base

class fparser.two.Fortran2003.Specification_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<specification-expr> = <scalar-int-expr>
subclass_names = ['Scalar_Int_Expr'][source]
class fparser.two.Fortran2003.Initialization_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<initialization-expr> = <expr>
subclass_names = ['Expr'][source]
class fparser.two.Fortran2003.Char_Initialization_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<char-initialization-expr> = <char-expr>
subclass_names = ['Char_Expr'][source]
class fparser.two.Fortran2003.Int_Initialization_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<int-initialization-expr> = <int-expr>
subclass_names = ['Int_Expr'][source]
class fparser.two.Fortran2003.Logical_Initialization_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<logical-initialization-expr> = <logical-expr>
subclass_names = ['Logical_Expr'][source]
class fparser.two.Fortran2003.Assignment_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.BinaryOpBase

<assignment-stmt> = <variable> = <expr>
subclass_names = [][source]
use_names = ['Variable', 'Expr'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Pointer_Assignment_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<pointer-assignment-stmt> = <data-pointer-object> [
    ( <bounds-spec-list> ) ] => <data-target>
    | <data-pointer-object> ( <bounds-remapping-list> ) => <data-target>
    | <proc-pointer-object> => <proc-target>
subclass_names = [][source]
use_names = ['Data_Pointer_Object', 'Bounds_Spec_List', 'Data_Target', 'Bounds_Remapping_List',...[source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Data_Pointer_Object(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<data-pointer-object> = <variable-name>
                        | <variable> % <data-pointer-component-name>
subclass_names = ['Variable_Name'][source]
use_names = ['Variable', 'Data_Pointer_Component_Name'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Bounds_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

<bounds-spec> = <lower-bound-expr> :
subclass_names = [][source]
use_names = ['Lower_Bound_Expr'][source]
static match(string)[source]
class fparser.two.Fortran2003.Bounds_Remapping(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

<bounds-remapping> = <lower-bound-expr> : <upper-bound-expr>
subclass_names = [][source]
use_classes = ['Lower_Bound_Expr', 'Upper_Bound_Expr'][source]
static match(string)[source]
class fparser.two.Fortran2003.Data_Target(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<data-target> = <variable>
                | <expr>
subclass_names = ['Variable', 'Expr'][source]
class fparser.two.Fortran2003.Proc_Pointer_Object(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<proc-pointer-object> = <proc-pointer-name>
                      | <proc-component-ref>
subclass_names = ['Proc_Pointer_Name', 'Proc_Component_Ref'][source]
class fparser.two.Fortran2003.Proc_Component_Ref(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<proc-component-ref> = <variable> % <procedure-component-name>
subclass_names = [][source]
use_names = ['Variable', 'Procedure_Component_Name'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Proc_Target(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<proc-target> = <expr>
                | <procedure-name>
                | <proc-component-ref>
subclass_names = ['Proc_Component_Ref', 'Procedure_Name', 'Expr'][source]
class fparser.two.Fortran2003.Where_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<where-stmt> = WHERE ( <mask-expr> ) <where-assignment-stmt>
subclass_names = [][source]
use_names = ['Mask_Expr', 'Where_Assignment_Stmt'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Where_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<where-construct> = <where-construct-stmt>
                          [ <where-body-construct> ]...
                        [ <masked-elsewhere-stmt>
                          [ <where-body-construct> ]...
                        ]...
                        [ <elsewhere-stmt>
                          [ <where-body-construct> ]... ]
                        <end-where-stmt>
subclass_names = [][source]
use_names = ['Where_Construct_Stmt', 'Where_Body_Construct', 'Masked_Elsewhere_Stmt', 'Elsewhere_Stmt',...[source]
static match(string)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

tofortran(tab='', isfix=None)[source]

Converts this node (and all children) into Fortran.

Parameters:
  • tab (str) – white space to prefix to output.

  • isfix (bool) – whether or not to generate fixed-format output.

Returns:

Fortran code.

Return type:

str

class fparser.two.Fortran2003.Where_Construct_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<where-construct-stmt> = [ <where-construct-name> : ] WHERE ( <mask-expr> )
subclass_names = [][source]
use_names = ['Where_Construct_Name', 'Mask_Expr'][source]
static match(string)[source]
tostr()[source]
get_start_name()[source]
class fparser.two.Fortran2003.Where_Body_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<where-body-construct> = <where-assignment-stmt>
                         | <where-stmt>
                         | <where-construct>
subclass_names = ['Where_Assignment_Stmt', 'Where_Stmt', 'Where_Construct'][source]
class fparser.two.Fortran2003.Where_Assignment_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<where-assignment-stmt> = <assignment-stmt>
subclass_names = ['Assignment_Stmt'][source]
class fparser.two.Fortran2003.Mask_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<mask-expr> = <logical-expr>

subclass_names = ['Logical_Expr'][source]
class fparser.two.Fortran2003.Masked_Elsewhere_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<masked-elsewhere-stmt> = ELSEWHERE
                          ( <mask-expr> ) [ <where-construct-name> ]
subclass_names = [][source]
use_names = ['Mask_Expr', 'Where_Construct_Name'][source]
static match(string)[source]
tostr()[source]
get_end_name()[source]
Returns:

the name at the END of this block, if it exists

Return type:

str or NoneType

class fparser.two.Fortran2003.Elsewhere_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<elsewhere-stmt> = ELSEWHERE [ <where-construct-name> ]

subclass_names = [][source]
use_names = ['Where_Construct_Name'][source]
_regex[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

get_end_name()[source]
Returns:

the name at the END of this block, if it exists

Return type:

str or NoneType

class fparser.two.Fortran2003.End_Where_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-where-stmt> = END WHERE [ <where-construct-name> ]

subclass_names = [][source]
use_names = ['Where_Construct_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Forall_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<forall-construct> = <forall-construct-stmt>
                         [ <forall-body-construct> ]...
                         <end-forall-stmt>
subclass_names = [][source]
use_names = ['Forall_Construct_Stmt', 'Forall_Body_Construct', 'End_Forall_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Forall_Construct_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<forall-construct-stmt> = [ <forall-construct-name> : ]
    FORALL <forall-header>
subclass_names = [][source]
use_names = ['Forall_Construct_Name', 'Forall_Header'][source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

get_start_name()[source]
class fparser.two.Fortran2003.Forall_Header(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R754:

forall-header is ( forall-triplet-spec-list [, scalar-mask-expr ] )
subclass_names = [][source]
use_names = ['Forall_Triplet_Spec_List', 'Scalar_Mask_Expr'][source]
static match(string)[source]

Implements the matching for a Forall_Header.

Parameters:

string (str) – A string containing the code to match.

Returns:

None if there is no match, otherwise a tuple of size 2 containing a class of type Forall_Triplet_Spec_List and a class of type Scalar_Mask_Expr if there is a scalar mask expresssion and None if not.

Return type:

(Forall_Triplet_Spec_List, Scalar_Mask_Expr) or (Forall_Triplet_Spec_List, None) or None

tostr()[source]
Returns:

this Forall Header as a string

Return type:

str

Raises:
  • InternalError – if the length of the internal items list is not 2.

  • InternalError – if the first entry of the internal items list has no content, as a Forall_Triplet_List is expected.

class fparser.two.Fortran2003.Forall_Triplet_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<forall-triplet-spec> = <index-name> = <subscript> :
    <subscript> [ : <stride> ]
subclass_names = [][source]
use_names = ['Index_Name', 'Subscript', 'Stride'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Forall_Body_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<forall-body-construct> = <forall-assignment-stmt>
                          | <where-stmt>
                          | <where-construct>
                          | <forall-construct>
                          | <forall-stmt>
subclass_names = ['Forall_Assignment_Stmt', 'Where_Stmt', 'Where_Construct', 'Forall_Construct', 'Forall_Stmt'][source]
class fparser.two.Fortran2003.Forall_Assignment_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<forall-assignment-stmt> = <assignment-stmt>
                           | <pointer-assignment-stmt>
subclass_names = ['Assignment_Stmt', 'Pointer_Assignment_Stmt'][source]
class fparser.two.Fortran2003.End_Forall_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-forall-stmt> = END FORALL [ <forall-construct-name> ]

subclass_names = [][source]
use_names = ['Forall_Construct_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Forall_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran 2003 rule R759:

forall-stmt is FORALL forall-header forall-assignment-stmt
subclass_names = [][source]
use_names = ['Forall_Header', 'Forall_Assignment_Stmt'][source]
static match(string)[source]

Implements the matching for a forall statement.

Parameters:

string (str or fparser.common.readfortran.FortranReader) – A string or the fortran reader containing the line of code that we are trying to match.

Returns:

None if there is no match or a tuple of size 2 containing an instance of the Forall_Header class followed by an instance of the Forall_Assignment_Stmt class.

Return type:

None or ( fparser.two.Fortran2003.Forall_Header, fparser.two.Fortran2003.Forall_Assignment_Stmt)

tostr()[source]
Returns:

this forall statement as a string

Return type:

str

Raises:
  • InternalError – if the internal items list variable is not the expected size.

  • InternalError – if the first element of the internal items list is None or is an empty string.

  • InternalError – if the second element of the internal items list is None or is an empty string.

class fparser.two.Fortran2003.Block(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<block> = [ <execution-part-construct> ]…

subclass_names = [][source]
use_names = ['Execution_Part_Construct'][source]
static match(string)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.If_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<if-construct> = <if-then-stmt>
                       <block>
                     [ <else-if-stmt>
                       <block>
                     ]...
                     [ <else-stmt>
                       <block>
                     ]
                     <end-if-stmt>
subclass_names = [][source]
use_names = ['If_Then_Stmt', 'Execution_Part_Construct', 'Else_If_Stmt', 'Else_Stmt', 'End_If_Stmt'][source]
static match(string)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

tofortran(tab='', isfix=None)[source]

Converts this node (and all children) into Fortran.

Parameters:
  • tab (str) – white space to prefix to output.

  • isfix (bool) – whether or not to generate fixed-format output.

Returns:

Fortran code.

Return type:

str

class fparser.two.Fortran2003.If_Then_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<if-then-stmt> = [ <if-construct-name> : ]
    IF ( <scalar-logical-expr> ) THEN
subclass_names = [][source]
use_names = ['If_Construct_Name', 'Scalar_Logical_Expr'][source]
static match(string)[source]
tostr()[source]
get_start_name()[source]
class fparser.two.Fortran2003.Else_If_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<else-if-stmt> = ELSE IF ( <scalar-logical-expr> ) THEN
    [ <if-construct-name> ]
subclass_names = [][source]
use_names = ['Scalar_Logical_Expr', 'If_Construct_Name'][source]
static match(string)[source]
tostr()[source]
get_end_name()[source]
Returns:

the name at the END of this block, if it exists

Return type:

str or NoneType

class fparser.two.Fortran2003.Else_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<else-stmt> = ELSE [ <if-construct-name> ]

subclass_names = [][source]
use_names = ['If_Construct_Name'][source]
static match(string)[source]
tostr()[source]
get_end_name()[source]
Returns:

the name at the END of this block, if it exists

Return type:

str or NoneType

class fparser.two.Fortran2003.End_If_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-if-stmt> = END IF [ <if-construct-name> ]

subclass_names = [][source]
use_names = ['If_Construct_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.If_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran 2003 rule R807:

if-stmt is IF ( scalar-logical-expr ) action-stmt

C802 (R807) The action-stmt in the if-stmt shall not be an if-stmt, end-program-stmt, end-function-stmt, or end-subroutine-stmt.

subclass_names = [][source]
use_names = ['Scalar_Logical_Expr', 'Action_Stmt_C802'][source]
action_stmt_cls[source]
classmethod match(string)[source]

Implements the matching for an if statement that controls a single action statement

This is implemented as a class method to allow parameterizing the type that is used to match the action-stmt. It is specified by the attribute action_stmt_cls, which can be overwritten in derived classes to specify an updated version, so done for example in the Fortran 2008 version fparser.two.Fortran2008.If_Stmt.

Parameters:

string (str) – Text that we are trying to match.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing the logical expression as an object matched by fparser.two.Fortran2003.Scalar_Logical_Expr and the action statement as an object matching cls.action_stmt_cls.

Return type:

(fparser.two.Fortran2003.Scalar_Logical_Expr, fparser.two.Fortran2003.Action_Stmt_C802) or NoneType

tostr()[source]
class fparser.two.Fortran2003.Case_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<case-construct> = <select-case-stmt>
                       [ <case-stmt>
                         <block> == [<execution-part-construct>]..
                       ]..
                       <end-select-stmt>
subclass_names = [][source]
use_names = ['Select_Case_Stmt', 'Case_Stmt', 'End_Select_Stmt', 'Execution_Part_Construct'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

tofortran(tab='', isfix=None)[source]

Converts this node (and all children) into Fortran.

Parameters:
  • tab (str) – white space to prefix to output.

  • isfix (bool) – whether or not to generate fixed-format output.

Returns:

Fortran code.

Return type:

str

class fparser.two.Fortran2003.Select_Case_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.CALLBase

<select-case-stmt> = [ <case-construct-name> : ]
    SELECT CASE ( <case-expr> )
subclass_names = [][source]
use_names = ['Case_Construct_Name', 'Case_Expr'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

tostr()[source]
get_start_name()[source]
class fparser.two.Fortran2003.Case_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<case-stmt> = CASE <case-selector> [ <case-construct-name> ]

subclass_names = [][source]
use_names = ['Case_Selector', 'Case_Construct_Name'][source]
static match(string)[source]
tostr()[source]
get_end_name()[source]
Returns:

the name at the END of this block, if it exists

Return type:

str or NoneType

class fparser.two.Fortran2003.End_Select_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-select-stmt> = END SELECT [ <case-construct-name> ]

subclass_names = [][source]
use_names = ['Case_Construct_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Case_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<case-expr> = <scalar-int-expr>
              | <scalar-char-expr>
              | <scalar-logical-expr>
subclass_names = [][source]
subclass_names = ['Scalar_Int_Expr', 'Scalar_Char_Expr', 'Scalar_Logical_Expr'][source]
class fparser.two.Fortran2003.Case_Selector(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<case-selector> = ( <case-value-range-list> )
                  | DEFAULT
subclass_names = [][source]
use_names = ['Case_Value_Range_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Case_Value_Range(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

<case-value-range> = <case-value>
                     | <case-value> :
                     | : <case-value>
                     | <case-value> : <case-value>
subclass_names = ['Case_Value'][source]
static match(string)[source]
class fparser.two.Fortran2003.Case_Value(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<case-value> = <scalar-int-initialization-expr>
               | <scalar-char-initialization-expr>
               | <scalar-logical-initialization-expr>
subclass_names = ['Scalar_Int_Initialization_Expr', 'Scalar_Char_Initialization_Expr',...[source]
class fparser.two.Fortran2003.Associate_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<associate-construct> = <associate-stmt>
                            <block> == [ <execution-part-construct> ]...
                            <end-associate-stmt>
subclass_names = [][source]
use_names = ['Associate_Stmt', 'Execution_Part_Construct', 'End_Associate_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Associate_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.CALLBase

<associate-stmt> = [ <associate-construct-name> : ]
    ASSOCIATE ( <association-list> )
subclass_names = [][source]
use_names = ['Associate_Construct_Name', 'Association_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

get_start_name()[source]
class fparser.two.Fortran2003.Association(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<association> = <associate-name> => <selector>

subclass_names = [][source]
use_names = ['Associate_Name', 'Selector'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Selector(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<selector> = <expr>
             | <variable>
subclass_names = ['Expr', 'Variable'][source]
class fparser.two.Fortran2003.End_Associate_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-associate-stmt> = END ASSOCIATE [ <associate-construct-name> ]

subclass_names = [][source]
use_names = ['Associate_Construct_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Select_Type_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<select-type-construct> = <select-type-stmt>
                              [ <type-guard-stmt>
                                <block> == [<execution-part-construct>]..
                              ]...
                              <end-select-type-stmt>
subclass_names = [][source]
use_names = ['Select_Type_Stmt', 'Type_Guard_Stmt', 'Execution_Part_Construct', 'End_Select_Type_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Select_Type_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<select-type-stmt> = [ <select-construct-name> : ] SELECT TYPE
    ( [ <associate-name> => ] <selector> )
subclass_names = [][source]
use_names = ['Select_Construct_Name', 'Associate_Name', 'Selector'][source]
static match(string)[source]
tostr()[source]
get_start_name()[source]
class fparser.two.Fortran2003.Type_Guard_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<type-guard-stmt> = TYPE IS ( <type-spec> ) [ <select-construct-name> ]
                    | CLASS IS ( <type-spec> ) [ <select-construct-name> ]
                    | CLASS DEFAULT [ <select-construct-name> ]

The items attribute for this class will contain:

({'TYPE IS', 'CLASS IS', 'CLASS DEFAULT'}, Type_Spec, Select_Construct_Name)
subclass_names = [][source]
use_names = ['Type_Spec', 'Select_Construct_Name'][source]
static match(string)[source]
tostr()[source]
get_end_name()[source]
Returns:

the name at the END of this block, if it exists

Return type:

str or NoneType

class fparser.two.Fortran2003.End_Select_Type_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-select-type-stmt> = END SELECT [ <select-construct-name> ]

subclass_names = [][source]
use_names = ['Select_Construct_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

R825:

<do-construct> = <block-do-construct>
                 | <nonblock-do-construct>
subclass_names = ['Block_Do_Construct', 'Nonblock_Do_Construct'][source]
class fparser.two.Fortran2003.Block_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

R826:

<block-do-construct> = <block-label-do-construct>
                       | <block-nonlabel-do-construct>
subclass_names = ['Block_Label_Do_Construct', 'Block_Nonlabel_Do_Construct'][source]
class fparser.two.Fortran2003.Block_Label_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

R826_1:

<block-label-do-construct> = <label-do-stmt>
                               [ <execution-part-construct> ]...
                               <end-do>
subclass_names = [][source]
use_names = ['Label_Do_Stmt', 'Execution_Part_Construct', 'End_Do'][source]
classmethod match(reader)[source]
Parameters:

reader (FortranReaderBase) – instance of FortranReaderBase class

Returns:

code block matching the labeled “DO” construct

Return type:

string

static label_do_stmt_cls()[source]
Returns:

Fortran2003 Label_Do_Stmt class.

Return type:

fparser.two.Fortran2003.Label_Do_Stmt

tofortran(tab='', isfix=None)[source]
Parameters:
  • tab (str) – tab character or empty string.

  • isfix (bool) – whether the reader is in fixed format.

Returns:

parsed representation of the labeled “DO” construct.

Return type:

str

class fparser.two.Fortran2003.Block_Nonlabel_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

R826_2:

<block-nonlabel-do-construct> = <nonlabel-do-stmt>
                                 [ <execution-part-construct> ]...
                                 <end-do-stmt>
subclass_names = [][source]
use_names = ['Nonlabel_Do_Stmt', 'Execution_Part_Construct', 'End_Do_Stmt'][source]
classmethod match(reader)[source]
Parameters:

reader (FortranReaderBase) – instance of FortranReaderBase class

Returns:

code block matching the nonlabeled “DO” construct

Return type:

string

static nonlabel_do_stmt_cls()[source]
Returns:

Fortran2003 Nonlabel_Do_Stmt class.

Return type:

fparser.two.Fortran2003.Nonlabel_Do_Stmt

class fparser.two.Fortran2003.Do_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

R827:

<do-stmt> = <label-do-stmt>
            | <nonlabel-do-stmt>
subclass_names = ['Label_Do_Stmt', 'Nonlabel_Do_Stmt'][source]
class fparser.two.Fortran2003.Label_Do_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

R828:

<label-do-stmt> = [ <do-construct-name> : ] DO <label> [ <loop-control> ]
subclass_names = [][source]
use_names = ['Do_Construct_Name', 'Label', 'Loop_Control'][source]
do_construct_name[source]
label[source]
loop_control[source]
classmethod match(string)[source]
Parameters:

string (str or FortranReaderBase) – (source of) Fortran string to parse

Returns:

3-tuple containing strings and instances of the classes determining labeled “DO” statement (optional statement name, label and loop control expression if present)

Return type:

3-tuple of objects

static loop_control_cls()[source]
Returns:

Fortran2003 Loop_Control class.

Return type:

fparser.two.Fortran2003.Loop_Control

tostr()[source]
Returns:

string containing Fortran code for the parsed labeled “DO” statement

Return type:

string

get_start_name()[source]
Returns:

optional labeled “DO” statement name

Return type:

string

get_start_label()[source]
Returns:

label of “DO” statement

Return type:

string

class fparser.two.Fortran2003.Nonlabel_Do_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

R829:

<nonlabel-do-stmt> = [ <do-construct-name> : ] DO [ <loop-control> ]
subclass_names = [][source]
use_names = ['Do_Construct_Name', 'Loop_Control'][source]
classmethod match(string)[source]
Parameters:

string (str) – Fortran code to check for a match.

Returns:

code line matching the nonlabeled “DO” statement.

Return type:

str

static loop_control_cls()[source]
Returns:

Fortran2003 Loop_Control class.

Return type:

fparser.two.Fortran2003.Loop_Control

get_start_name()[source]
Returns:

optional labeled “DO” statement name

Return type:

str

class fparser.two.Fortran2003.Loop_Control(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R830

loop-control is [ , ] do-variable = scalar-int-expr , scalar-int-expr

[ , scalar-int-expr ]

or [ , ] WHILE ( scalar-logical-expr )

This class would be better and more extensible if it called 2 classes, one for each of the above expressions. Something like the suggestion below. However, this would result in a different fparser tree, see issue #416.

F2003: While_Loop_Cntl: scalar-logical-expression, delim F2003: Counter_Loop_Cntl: var, lower, upper, [step], delim F2008: Concurrent_Loop_Cntl: conc_expr, delim F2018: Concurrent_Loop_Cntl: conc_expr, local_x, delim

subclass_names = [][source]
use_names = ['Do_Variable', 'Scalar_Int_Expr', 'Scalar_Logical_Expr'][source]
static match(string)[source]

Attempts to match the supplied text with this rule.

Parameters:

string (str) – Fortran code to check for a match.

Returns:

None if there is no match, a 3-tuple with the first entry providing the result of matching the ‘WHILE’ part of the rule if there is a match, the second entry providing the result of matching the ‘COUNTER’ part of the rule if there is a match and the third entry indicating whether there is an optional preceding ‘,’.

Return type:

Optional[Tuple[ Optional[ fparser.two.Fortran2003.Scalar_Logical_Expr], Optional[Tuple[ fparser.two.Fortran2003.Do_Variable, List[str]]], Optional[str]]]

tostr()[source]
Returns:

the Fortran representation of this object.

Return type:

str

class fparser.two.Fortran2003.Do_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

R831:

<do-variable> = <scalar-int-variable>
subclass_names = ['Scalar_Int_Variable'][source]
class fparser.two.Fortran2003.Do_Block(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

R832:

<do-block> = [ <execution-part-construct> ]...
subclass_names = ['Block'][source]
subclass_names = [][source]
use_names = ['Execution_Part_Construct'][source]
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

code block matching the execution part construct within the “DO” block

Return type:

string

class fparser.two.Fortran2003.End_Do(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

R833:

<end-do> = <end-do-stmt>
           | <continue-stmt>
subclass_names = ['End_Do_Stmt', 'Continue_Stmt'][source]
class fparser.two.Fortran2003.End_Do_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

R834:

<end-do-stmt> = END DO [ <do-construct-name> ]
subclass_names = [][source]
use_names = ['Do_Construct_Name'][source]
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

code line matching the “END DO” statement

Return type:

string

class fparser.two.Fortran2003.Nonblock_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

R835:

<nonblock-do-stmt> = <action-term-do-construct>
                     | <outer-shared-do-construct>
subclass_names = ['Action_Term_Do_Construct', 'Outer_Shared_Do_Construct'][source]
class fparser.two.Fortran2003.Action_Term_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<action-term-do-construct> = <label-do-stmt>
                                 <do-body>
                                 <do-term-action-stmt>

<action-term-do-construct> = <label-do-stmt>
                             [ <execution-part-construct> ]...
                             <do-term-action-stmt>
subclass_names = [][source]
use_names = ['Label_Do_Stmt', 'Execution_Part_Construct', 'Do_Term_Action_Stmt'][source]
classmethod match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

static label_do_stmt_cls()[source]
Returns:

Fortran2003 Label_Do_Stmt class.

Return type:

fparser.two.Fortran2003.Label_Do_Stmt

tofortran(tab='', isfix=None)[source]

Converts this node (and all children) into Fortran.

Parameters:
  • tab (str) – white space to prefix to output.

  • isfix (bool) – whether or not to generate fixed-format output.

Returns:

Fortran code.

Return type:

str

class fparser.two.Fortran2003.Do_Body(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<do-body> = [ <execution-part-construct> ]…

subclass_names = [][source]
use_names = ['Execution_Part_Construct'][source]
static match(string)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Do_Term_Action_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<do-term-action-stmt> = <action-stmt>

Notes:

C824 - <do-term-action-stmt> shall not be <continue-stmt>, <goto-stmt>,
      <return-stmt>, <stop-stmt>, <exit-stmt>, <cycle-stmt>,
      <end-function-stmt>, <end-subroutine-stmt>, <end-program-stmt>,
      <arithmetic-if-stmt>
subclass_names = ['Action_Stmt_C824'][source]
class fparser.two.Fortran2003.Outer_Shared_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<outer-shared-do-construct> = <label-do-stmt>
                                  <do-body>
                                  <shared-term-do-construct>
subclass_names = [][source]
use_names = ['Label_Do_Stmt', 'Do_Body', 'Shared_Term_Do_Construct'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Shared_Term_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<shared-term-do-construct> = <outer-shared-do-construct>
                             | <inner-shared-do-construct>
subclass_names = ['Outer_Shared_Do_Construct', 'Inner_Shared_Do_Construct'][source]
class fparser.two.Fortran2003.Inner_Shared_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<inner-shared-do-construct> = <label-do-stmt>
                                  <do-body>
                                  <do-term-shared-stmt>
subclass_names = [][source]
use_names = ['Label_Do_Stmt', 'Do_Body', 'Do_Term_Shared_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Do_Term_Shared_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<do-term-shared-stmt> = <action-stmt>

C826 - see C824 above.

subclass_names = ['Action_Stmt'][source]
class fparser.two.Fortran2003.Cycle_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<cycle-stmt> = CYCLE [ <do-construct-name> ]

subclass_names = [][source]
use_names = ['Do_Construct_Name'][source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Exit_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<exit-stmt> = EXIT [ <do-construct-name> ]

subclass_names = [][source]
use_names = ['Do_Construct_Name'][source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Goto_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<goto-stmt> = GO TO <label>

subclass_names = [][source]
use_names = ['Label'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Computed_Goto_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<computed-goto-stmt> = GO TO ( <label-list> ) [ , ] <scalar-int-expr>

subclass_names = [][source]
use_names = ['Label_List', 'Scalar_Int_Expr'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Arithmetic_If_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<arithmetic-if-stmt> = IF ( <scalar-numeric-expr> ) <label> ,
    <label> , <label>
subclass_names = [][source]
use_names = ['Scalar_Numeric_Expr', 'Label'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Continue_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.STRINGBase

<continue-stmt> = CONTINUE

subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

get_end_label()[source]
class fparser.two.Fortran2003.Stop_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<stop-stmt> = STOP [ <stop-code> ]

subclass_names = [][source]
use_names = ['Stop_Code'][source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Stop_Code(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

<stop-code> = <scalar-char-constant>
              | <digit> [ <digit> [ <digit> [ <digit> [ <digit> ] ] ] ]
subclass_names = ['Scalar_Char_Constant'][source]
static match(string)[source]
class fparser.two.Fortran2003.Io_Unit(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

<io-unit> = <file-unit-number>
            | *
            | <internal-file-variable>
subclass_names = ['File_Unit_Number', 'Internal_File_Variable'][source]
static match(string)[source]
class fparser.two.Fortran2003.File_Unit_Number(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<file-unit-number> = <scalar-int-expr>

subclass_names = ['Scalar_Int_Expr'][source]
class fparser.two.Fortran2003.Internal_File_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<internal-file-variable> = <char-variable>

C901 - <char-variable> shall not be an array section with a vector subscript.

subclass_names = ['Char_Variable'][source]
class fparser.two.Fortran2003.Open_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.CALLBase

R904 is:

open-stmt is OPEN ( connect-spec-list )

subclass_names = [][source]
use_names = ['Connect_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Connect_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

R905 is:

connect-spec is [ UNIT = ] file-unit-number

or ACCESS = scalar-default-char-expr or ACTION = scalar-default-char-expr or ASYNCHRONOUS = scalar-default-char-expr or BLANK = scalar-default-char-expr [ or CONVERT = scalar-default-char-expr ] or DECIMAL = scalar-default-char-expr or DELIM = scalar-default-char-expr or ENCODING = scalar-default-char-expr or ERR = label or FILE = file-name-expr or FORM = scalar-default-char-expr or IOMSG = iomsg-variable or IOSTAT = scalar-int-variable or PAD = scalar-default-char-expr or POSITION = scalar-default-char-expr or RECL = scalar-int-expr or ROUND = scalar-default-char-expr or SIGN = scalar-default-char-expr or STATUS = scalar-default-char-expr

Note that CONVERT is not a part of the Fortran standard but is supported by several major compilers (Gnu, Intel, Cray etc.) and thus is matched by fparser if the utils.EXTENSIONS() list includes the string ‘open-convert’.

subclass_names = [][source]
use_names = ['File_Unit_Number', 'Scalar_Default_Char_Expr', 'Label', 'File_Name_Expr', 'Iomsg_Variable',...[source]
classmethod _keyword_value_list()[source]

Defines the valid keywords and corresponding classes to match against. This has to be a method rather than a class property as those classes are generated after this class has been created.

Returns:

list of keyword, class pairs to match against.

Return type:

list[tuple[str, type]]

classmethod match(string)[source]

Implements the matching for connect-spec.

Note that this is implemented as a classmethod (not a staticmethod), using attribute keywords from the list provided as a class method. This allows expanding this list for Fortran 2008 without having to reimplement the matching.

Parameters:

string (str) – Fortran code to check for a match

Returns:

2-tuple containing the keyword and value or None if the supplied string is not a match

Return type:

2-tuple containing keyword (e.g. “UNIT”) and associated value

class fparser.two.Fortran2003.File_Name_Expr(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<file-name-expr> = <scalar-default-char-expr>

subclass_names = ['Scalar_Default_Char_Expr'][source]
class fparser.two.Fortran2003.Iomsg_Variable(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<iomsg-variable> = <scalar-default-char-variable>

subclass_names = ['Scalar_Default_Char_Variable'][source]
class fparser.two.Fortran2003.Close_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.CALLBase

<close-stmt> = CLOSE ( <close-spec-list> )

subclass_names = [][source]
use_names = ['Close_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Close_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

<close-spec> = [ UNIT = ] <file-unit-number>
               | IOSTAT = <scalar-int-variable>
               | IOMSG = <iomsg-variable>
               | ERR = <label>
               | STATUS = <scalar-default-char-expr>
subclass_names = [][source]
use_names = ['File_Unit_Number', 'Scalar_Default_Char_Expr', 'Label', 'Iomsg_Variable', 'Scalar_Int_Variable'][source]
static match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Read_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 Rule R910:

<read-stmt> = READ ( <io-control-spec-list> ) [ <input-item-list> ]
                | READ <format> [ , <input-item-list> ]

Attributes:

items : (Io_Control_Spec_List, Format, Input_Item_List)
subclass_names = [][source]
use_names = ['Io_Control_Spec_List', 'Input_Item_List', 'Format'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Write_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran 2003 rule R911.

Specifies the syntax of a “WRITE” statement:

write-stmt is WRITE ( io-control-spec-list ) [ output-item-list ]
subclass_names = [][source]
use_names = ['Io_Control_Spec_List', 'Output_Item_List'][source]
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

2-tuple containing strings and instances of the classes describing “WRITE” statement (mandatory IO control specification list and optional output item list.

Return type:

2-tuple of objects (1 mandatory and 1 optional)

tostr()[source]
Returns:

parsed representation of a “WRITE” statement

Return type:

str

class fparser.two.Fortran2003.Print_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 Rule R912:

<print-stmt> = PRINT <format> [ , <output-item-list> ]

Parameters:

items : (Format, Output_Item_List)
subclass_names = [][source]
use_names = ['Format', 'Output_Item_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Io_Control_Spec_List(string, parent_cls=None)[source]

Bases: fparser.two.utils.SequenceBase

Rule 913 - Control information list:

io-control-spec-list is a list of io-control-spec items.

Subject to the following constraints:

C909 No specifier shall appear more than once in a given
     io-control-spec-list.
C910 An io-unit shall be specified; if the optional characters UNIT= are
     omitted, the io-unit shall be the first item in the
     io-control-spec-list.
C911 A DELIM= or SIGN= specifier shall not appear in a read-stmt.
C912 A BLANK=, PAD=, END=, EOR=, or SIZE=specifier shall not appear in a
     write-stmt.
C913 The label in the ERR=, EOR=, or END= specifier shall be the statement
     label of a branch target statement that appears in the same scoping
     unit as the data transfer statement.
C914 A namelist-group-name shall be the name of a namelist group.
C915 A namelist-group-name shall not appear if an input-item-list or an
     output-item-list appears in the data transfer statement.
C916 An io-control-spec-list shall not contain both a format and a
     namelist-group-name.
C917 If format appears without a preceding FMT=, it shall be the second
     item in the iocontrol-spec-list and the first item shall be io-unit.
C918 If namelist-group-name appears without a preceding NML=, it shall be
     the second item in the io-control-spec-list and the first item shall
     be io-unit.
C919 If io-unit is not a file-unit-number, the io-control-spec-list shall
     not contain a REC= specifier or a POS= specifier.
C920 If the REC= specifier appears, an END= specifier shall not appear, a
     namelist-groupname shall not appear, and the format, if any, shall not
     be an asterisk.
C921 An ADVANCE= specifier may appear only in a formatted sequential or
     stream input/output statement with explicit format specification
     (10.1) whose control information list does not contain an
     internal-file-variable as the io-unit.
C922 If an EOR= specifier appears, an ADVANCE= specifier also shall appear.
C923 If a SIZE= specifier appears, an ADVANCE= specifier also shall appear.
C924 The scalar-char-initialization-expr in an ASYNCHRONOUS= specifier
     shall be of type default character and shall have the value YES or NO.
C925 An ASYNCHRONOUS= specifier with a value YES shall not appear unless
     io-unit is a file-unit-number.
C926 If an ID= specifier appears, an ASYNCHRONOUS= specifier with the value
     YES shall also appear.
C927 If a POS= specifier appears, the io-control-spec-list shall not
     contain a REC= specifier.
C928 If a DECIMAL=, BLANK=, PAD=, SIGN=, or ROUND= specifier appears, a
     format or namelist-group-name shall also appear.
C929 If a DELIM= specifier appears, either format shall be an asterisk or
     namelist-group-name shall appear.

TODO #267. Of these constraints, only C910 & C916-918 are currently enforced.

subclass_names = [][source]
use_names = ['Io_Control_Spec', 'Namelist_Group_Name', 'Format'][source]
static match(string)[source]

Attempts to match the supplied string with a list of Io_Control_Spec items. We have to override the base implementation because the first two items in the list have specific meanings if they are not explictly named: the first must be the unit number and the second may be either a format specifier or a namelist-group-name.

Parameters:

string (str) – the string that is checked for a match.

Returns:

a tuple of Io_Control_Spec objects if the match is successful, None otherwise.

Return type:

tuple of fparser.two.Fortran2003.Io_Control_Spec objects or NoneType

class fparser.two.Fortran2003.Io_Control_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

This class implements partial support for Rule 913:

<io-control-spec> is  [UNIT = ] <io-unit>
                    | [ FMT = ] <format>
                    | [ NML = ] <namelist-group-name>
                    | ADVANCE = <scalar-default-char-expr>
                    | ASYNCHRONOUS = <scalar-char-initialization-expr>
                    | BLANK = <scalar-default-char-expr>
                    | DECIMAL = <scalar-default-char-expr>
                    | DELIM = <scalar-default-char-expr>
                    | END = <label>
                    | EOR = <label>
                    | ERR = <label>
                    | ID = <scalar-int-variable>
                    | IOMSG = <iomsg-variable>
                    | IOSTAT = <scalar-int-variable>
                    | PAD = <scalar-default-char-expr>
                    | POS = <scalar-int-expr>
                    | REC = <scalar-int-expr>
                    | ROUND = <scalar-default-char-expr>
                    | SIGN = <scalar-default-char-expr>
                    | SIZE = <scalar-int-variable>

The support is partial because this class requires that every spec be named. The specs that may not be named are explicitly handled in Io_Control_Spec_List.match().

subclass_names = [][source]
use_names = ['Io_Unit', 'Format', 'Namelist_Group_Name', 'Scalar_Default_Char_Expr',...[source]
static match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Format(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

<format> = <default-char-expr>
           | <label>
           | *
subclass_names = ['Label', 'Default_Char_Expr'][source]
static match(string)[source]
class fparser.two.Fortran2003.Input_Item(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<input-item> = <variable>
               | <io-implied-do>
subclass_names = ['Variable', 'Io_Implied_Do'][source]
class fparser.two.Fortran2003.Output_Item(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<output-item> = <expr>
                | <io-implied-do>
subclass_names = ['Expr', 'Io_Implied_Do'][source]
class fparser.two.Fortran2003.Io_Implied_Do(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<io-implied-do> = ( <io-implied-do-object-list> , <io-implied-do-control> )
subclass_names = [][source]
use_names = ['Io_Implied_Do_Object_List', 'Io_Implied_Do_Control'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Io_Implied_Do_Object(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<io-implied-do-object> = <input-item>
                         | <output-item>
subclass_names = ['Input_Item', 'Output_Item'][source]
class fparser.two.Fortran2003.Io_Implied_Do_Control(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<io-implied-do-control> = <do-variable> = <scalar-int-expr> ,
    <scalar-int-expr> [ , <scalar-int-expr> ]
subclass_names = [][source]
use_names = ['Do_Variable', 'Scalar_Int_Expr'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Dtv_Type_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.CALLBase

<dtv-type-spec> = TYPE ( <derived-type-spec> )
                  | CLASS ( <derived-type-spec> )
subclass_names = [][source]
use_names = ['Derived_Type_Spec'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Wait_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.CALLBase

<wait-stmt> = WAIT ( <wait-spec-list> )

subclass_names = [][source]
use_names = ['Wait_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Wait_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

<wait-spec> = [ UNIT = ] <file-unit-number>
              | END = <label>
              | EOR = <label>
              | ERR = <label>
              | ID = <scalar-int-expr>
              | IOMSG = <iomsg-variable>
              | IOSTAT = <scalar-int-variable>
subclass_names = [][source]
use_names = ['File_Unit_Number', 'Label', 'Scalar_Int_Expr', 'Iomsg_Variable', 'Scalar_Int_Variable'][source]
static match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Backspace_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 Rule R923:

<backspace-stmt> = BACKSPACE <file-unit-number>
                   | BACKSPACE ( <position-spec-list> )

Attributes:

items : (File_Unit_Number, Position_Spec_List)
subclass_names = [][source]
use_names = ['File_Unit_Number', 'Position_Spec_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Endfile_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 Rule R924:

<endfile-stmt> = ENDFILE <file-unit-number>
                 | ENDFILE ( <position-spec-list> )

Attributes:

items : (File_Unit_Number, Position_Spec_List)
subclass_names = [][source]
use_names = ['File_Unit_Number', 'Position_Spec_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Rewind_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 Rule R925:

<rewind-stmt> = REWIND <file-unit-number>
                | REWIND ( <position-spec-list> )

Attributes:

items : (File_Unit_Number, Position_Spec_List)
subclass_names = [][source]
use_names = ['File_Unit_Number', 'Position_Spec_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Position_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

<position-spec> = [ UNIT = ] <file-unit-number>
                  | IOMSG = <iomsg-variable>
                  | IOSTAT = <scalar-int-variable>
                  | ERR = <label>
subclass_names = [][source]
use_names = ['File_Unit_Number', 'Iomsg_Variable', 'Scalar_Int_Variable', 'Label'][source]
static match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Flush_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 Rule R927:

<flush-stmt> = FLUSH <file-unit-number>
                | FLUSH ( <position-spec-list> )

Attributes:

items : (File_Unit_Number, Position_Spec_List)
subclass_names = [][source]
use_names = ['File_Unit_Number', 'Position_Spec_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Flush_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

Fortran2003 Rule R928:

<flush-spec> = [ UNIT = ] <file-unit-number>
               | IOMSG = <iomsg-variable>
               | IOSTAT = <scalar-int-variable>
               | ERR = <label>

Attributes:

items : ({'UNIT', 'IOMSG', 'IOSTAT', 'ERR'}, {File_Unit_Number,
          Iomsg_Variable, Scalar_Int_Variable, Label})
subclass_names = [][source]
use_names = ['File_Unit_Number', 'Iomsg_Variable', 'Scalar_Int_Variable', 'Label'][source]
static match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Inquire_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran2003 Rule R929:

<inquire-stmt> = INQUIRE ( <inquire-spec-list> )
                 | INQUIRE ( IOLENGTH = <scalar-int-variable> )
                   <output-item-list>

Attributes:

items : (Inquire_Spec_List, Scalar_Int_Variable, Output_Item_List)
subclass_names = [][source]
use_names = ['Inquire_Spec_List', 'Scalar_Int_Variable', 'Output_Item_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Inquire_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

Fortran2003 Rule R930:

<inquire-spec> = [ UNIT = ] <file-unit-number>
                 | FILE = <file-name-expr>
                 | ACCESS = <scalar-default-char-variable>
                 | ACTION = <scalar-default-char-variable>
                 | ASYNCHRONOUS = <scalar-default-char-variable>
                 | BLANK = <scalar-default-char-variable>
                 | DECIMAL = <scalar-default-char-variable>
                 | DELIM = <scalar-default-char-variable>
                 | DIRECT = <scalar-default-char-variable>
                 | ENCODING = <scalar-default-char-variable>
                 | ERR = <label>
                 | EXIST = <scalar-default-logical-variable>
                 | FORM = <scalar-default-char-variable>
                 | FORMATTED = <scalar-default-char-variable>
                 | ID = <scalar-int-expr>
                 | IOMSG = <iomsg-variable>
                 | IOSTAT = <scalar-int-variable>
                 | NAME = <scalar-default-char-variable>
                 | NAMED = <scalar-default-logical-variable>
                 | NEXTREC = <scalar-int-variable>
                 | NUMBER = <scalar-int-variable>
                 | OPENED = <scalar-default-logical-variable>
                 | PAD = <scalar-default-char-variable>
                 | PENDING = <scalar-default-logical-variable>
                 | POS = <scalar-int-variable>
                 | POSITION = <scalar-default-char-variable>
                 | READ = <scalar-default-char-variable>
                 | READWRITE = <scalar-default-char-variable>
                 | RECL = <scalar-int-variable>
                 | ROUND = <scalar-default-char-variable>
                 | SEQUENTIAL = <scalar-default-char-variable>
                 | SIGN = <scalar-default-char-variable>
                 | SIZE = <scalar-int-variable>
                 | STREAM = <scalar-default-char-variable>
                 | UNFORMATTED = <scalar-default-char-variable>
                 | WRITE = <scalar-default-char-variable>

The items attribute for this class contains (str, instance).

subclass_names = [][source]
use_names = ['File_Unit_Number', 'File_Name_Expr', 'Scalar_Default_Char_Variable',...[source]
static match(string)[source]
Parameters:

string (str) – The string to check for conformance with an Inquire_Spec

Returns:

2-tuple of name (e.g. “UNIT”) and value or None if string is not a valid Inquire_Spec

Return type:

2-tuple where first object represents the name and the second the value.

class fparser.two.Fortran2003.Format_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<format-stmt> = FORMAT <format-specification>

subclass_names = [][source]
use_names = ['Format_Specification'][source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Format_Item_List(string, parent_cls=None)[source]

Bases: fparser.two.utils.SequenceBase

This class replaces the one generated by fparser. This class is required as support for hollerith strings makes matching more complicated.

use_names = [][source]
subclass_names = ['Format_Item'][source]
static match(string)[source]

Implements the matching for a list of format items.

Supporting Hollerith strings makes it very difficult to correctly split the input string into items a-priori. The reason for this can be seen in the following example:

2H,x,e2.2 is 2H,x and e2.2 but when split with commas incorrectly gives 2H, x and e2.2.

Further, hollerith strings could also confuse any code that tried to determine whether code was inside quotes or not. For example:

`2H"x,2H"x` does not mean that `x,2H` is part of a string.

The solution chosen is to match one item at a time, first checking for a valid Hollerith string and then checking for any other valid input.

Parameters:

string (str) – the string to match as a Format List.

Returns:

None if there is no match or a tuple of size 2 containing a string with a comma followed by a tuple containing a list which itself contains the matched format items.

Return type:

(str, ([fparser.two.Fortran2003.Format_Item`s])) or `NoneType

class fparser.two.Fortran2003.Format_Specification(string, parent_cls=None)[source]

Bases: fparser.two.utils.BracketBase

Fortran 2003 rule R1002:

format-specification = ( [ format-item-list ] )

C1002 is implemented in a separate class Format_Item_C1002

C1002 (R1002) The comma used to separate format-items in a format-item-list may be omitted

(1) Between a P edit descriptor and an immediately following F, E, EN, ES, D, or G edit descriptor, possibly preceded by a repeat specifier,

(2) Before a slash edit descriptor when the optional repeat specification is not present,

  1. After a slash edit descriptor, or

  2. Before or after a colon edit descriptor.

subclass_names = [][source]
use_names = ['Format_Item_List'][source]
static match(string)[source]

Implements the matching for a format specification.

Parameters:

string (str) – The string to check for conformance with a format specification.

Returns:

None if there is no match, otherwise a tuple of size three, the first entry being a string containing a left bracket and the third being a string containing a right bracket. The second entry is either a Format_Item or a Format_Item_List.

Return type:

NoneType or ( str, fparser.two.Fortran2003.Format_Item or fparser.two.Fortran2003.Format_Item_List, str )

fparser.two.Fortran2003.skip_digits(string)[source]

Skips over any potential digits (including spaces) to the next non-digit character and return its index. If no such character is found or if the first character in the string is not a digit then specify that the skip has failed.

Parameters:

string (str) – The string to search

Returns:

a 2-tuple with the first entry indicating if a valid character has been found and the second entry indicating the index of this character in the ‘string’ argument.

Return type:

(bool, int)

class fparser.two.Fortran2003.Format_Item_C1002(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 constraint C1002:

format-item-c1002 is kP [,] (F|D)w.d | (E|EN|ES|G)w.d[Ee]
                  or [r]/ [,] format-item
                  or : [,] format-item
                  or format-item [,] / [[,] format-item]
                  or format-item [,] : [[,] format-item]

C1002 (R1002) The comma used to separate format-items in a format-item-list may be omitted

(1) Between a P edit descriptor and an immediately following F, E, EN, ES, D, or G edit descriptor, possibly preceded by a repeat specifier,

(2) Before a slash edit descriptor when the optional repeat specification is not present (10.7.2),

  1. After a slash edit descriptor, or

  2. Before or after a colon edit descriptor.

subclass_names = [][source]
use_names = ['K', 'W', 'D', 'E', 'Format_Item', 'R'][source]
static match(string)[source]

Implements the matching for the C1002 Format Item constraint. The constraints specify certain combinations of format items that do not need a comma to separate them. Rather than sorting this out when parsing the list, it was decided to treat these separately and match them in this class. As a result the generated class hierarchy is a little more complicated.

Parameters:

string (str) – The string to check for conformance with a C1002 format item constraint.

Returns:

None if there is no match, otherwise a tuple of size 2 containing a mixture of Control_Edit_Descriptor and Format_Item classes depending on what has been matched.

Return type:

NoneType or ( fparser.two.Control_Edit_Desc, fparser.two.Format_Item ) or (fparser.two.Format_Item, fparser.two.Control_Edit_Desc) or (fparser.two.Format_Item, fparser.two.Format_Item)

tostr()[source]
Returns:

Parsed representation of two format items

Return type:

str

Raises:
  • InternalError – if the length of the internal items list is not 2.

  • InternalError – if the first entry of the internal items list has no content.

  • InternalError – if the second entry of the internal items list has no content.

class fparser.two.Fortran2003.Hollerith_Item(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Hollerith strings take the form nHx, where n is an integer and x is a sequence of characters of length n.

Note, the Hollerith format was deprecated in Fortran77 and removed in Fortran95. However, Fortran compilers still support it. See, for example https://gcc.gnu.org/onlinedocs/gcc-4.8.2/gfortran/Hollerith-constants-support.html

subclass_names = [][source]
use_names = [][source]
match_pattern = '^[1-9][0-9 ]*[hH]'[source]
static match(string)[source]

Implements the matching for a Hollerith string.

Parameters:

string (str) – The string to check for conformance with a Hollerith string

Returns:

String containing the contents of the Hollerith string.

Return type:

str

tostr()[source]
Returns:

Parsed representation of a Hollerith String.

Return type:

str

Raises:
  • InternalError – if the length of the internal items list is not 1.

  • InternalError – if the first entry of the internal items list has no content.

class fparser.two.Fortran2003.Format_Item(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R1003:

format-item is [ r ] data-edit-desc
            or control-edit-desc
            or char-string-edit-desc
            or [ r ] ( format-item-list )
            or format-item-c1002
            or hollerith-item
subclass_names = ['Hollerith_Item', 'Control_Edit_Desc', 'Char_String_Edit_Desc', 'Format_Item_C1002'][source]
use_names = ['R', 'Format_Item_List', 'Data_Edit_Desc'][source]
static match(string)[source]

Implements the matching of a Format Item. This method matches ‘[ r ] data-edit-desc’ and ‘[ r ] ( format-item-list )’. The remaining options are matched via subclasses specified in the subclass_names variable.

Parameters:

string (str) – A string or the Fortran reader containing the line of code that we are trying to match.

Returns:

None if there is no match or a tuple of size 2 containing an instance of the R class followed by an instance of either the Format_Item_List or the Data_Edit_Desc class.

Return type:

None or ( fparser.two.Fortran2003.R, fparser.two.Fortran2003.Format_Item_List or fparser.two.Fortran2003.Data_Edit_Desc)

tostr()[source]
Returns:

Parsed representation of a Format Item.

Return type:

str

Raises:
  • InternalError – if the length of the internal items list is not 2.

  • InternalError – if the first entry of the internal items list has no content.

class fparser.two.Fortran2003.R(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<r> = <int-literal-constant>

Notes:

C1003, C1004: <r> shall be positive and without kind parameter specified.
subclass_names = ['Digit_String'][source]
class fparser.two.Fortran2003.Data_Edit_Desc_C1002(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

This class helps implement the matching for the first part of the Fortran 2003 Constraint C1002 which constrains rule R1002. In particular it matches with the subset of edit descriptors that can follow a P edit descriptor without needing a comma, see below.

C1002 (applied to R1002) The comma used to separate format-items in a format-item-list may be omitted

(1) Between a P edit descriptor and an immediately following F, E, EN, ES, D, or G edit descriptor, possibly preceded by a repeat specifier.

[Remaining constraint clauses ommitted as they are not relevant here.]

data-edit-desc is F w . d
               or E w . d [ E e ]
               or EN w . d [ E e ]
               or ES w . d [ E e]
               or G w . d [ E e ]
               or D w . d
subclass_names = [][source]
use_names = ['W', 'D', 'E'][source]
static match(string)[source]

Check whether the input matches the rule.

param str string: contains the Fortran that we are trying to match. :return: None if there is no match, otherwise a tuple of size 4, the first entry containing a string with one of [‘F’, ‘E’, ‘EN’, ‘ES’, ‘G’, ‘D’], the second entry containing a W class instance, the third entry containing D class instance and the fourth entry containing either None or an E class instance. :rtype: NoneType, (str, fparser.two.W, fparser.two.D, NoneType) or, (str, fparser.two.W, fparser.two.D, fparser.two.E)

tostr()[source]
Returns:

parsed representation of a Data Edit Descriptor conforming to constraint C1002.

Return type:

str

Raises:
  • InternalError – if the length of the internal items list is not 4.

  • InternalError – if the first, second or third entry of the internal items list has no content.

  • InternalError – if the value of the first entry is unsupported.

  • InternalError – if the value of the first entry is ‘F’ or ‘D’ and the fourth entry has content.

  • InternalError – if the value of the first entry is ‘E’, ‘EN’, ‘ES’ or ‘G’ and the fourth entry is empty or None.

class fparser.two.Fortran2003.Data_Edit_Desc(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<data-edit-desc> =   I <w> [ . <m> ]
                   | B <w> [ . <m> ]
                   | O <w> [ . <m> ]
                   | Z <w> [ . <m> ]
                   | L <w>
                   | A [ <w> ]
                   | DT [ <char-literal-constant> ] [ ( <v-list> ) ]
                   | <data-edit-desc-c1002>
subclass_names = ['Data_Edit_Desc_C1002'][source]
use_names = ['W', 'M', 'Char_Literal_Constant', 'V_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.W(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

w is int-literal-constant == digit-string

Subject to constraints:

C1006, C1007: w is zero or postive and without kind parameters.
subclass_names = ['Digit_String'][source]
class fparser.two.Fortran2003.M(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

m = int-literal-constant

Subject to the constraint:

C1007: m is without kind parameters.
subclass_names = ['Int_Literal_Constant'][source]
class fparser.two.Fortran2003.D(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

d = int-literal-constant

Subject to the constraint:

C1007: d is without kind parameters.
subclass_names = ['Int_Literal_Constant'][source]
class fparser.two.Fortran2003.E(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

e is int-literal-constant

Subject to the constraints:

C1005, C1007: e is postive and without kind parameters.
subclass_names = ['Digit_String'][source]
class fparser.two.Fortran2003.V(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

v is signed-int-literal-constant

Subject to the constraint:

C1007: w is without kind parameters.
subclass_names = ['Signed_Int_Literal_Constant'][source]
class fparser.two.Fortran2003.Control_Edit_Desc(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R1011:

control-edit-desc is position-edit-desc
                  or [ r ] /
                  or :
                  or sign-edit-desc
                  or k P
                  or blank-interp-edit-desc
                  or round-edit-desc
                  or decimal-edit-desc
                  or $

‘$’ is used to suppress the carriage return on output. Note that this is an extension to the Fortran standard.

subclass_names = ['Position_Edit_Desc', 'Sign_Edit_Desc', 'Blank_Interp_Edit_Desc', 'Round_Edit_Desc',...[source]
use_names = ['R', 'K'][source]
static match(string)[source]

Check whether the input matches the rule.

param str string: contains the Fortran that we are trying to match. :return: None if there is no match, otherwise a tuple of size 2 containing, None and a string with one of ‘/’, ‘:’, or ‘$’, an R class and a string containing ‘/’ or a K class and a string containing ‘P’. :rtype: NoneType, (NoneType, str), (fparser.two.Fortran2003.R, str), or (fparser.two.Fortran2003.K, str)

tostr()[source]
Returns:

parsed representation of a Control Edit Descriptor

Return type:

str

Raises:
  • InternalError – if the length of the internal items list is not 2.

  • InternalError – if the second entry of the internal items list has no content.

class fparser.two.Fortran2003.K(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<k> = <signed-int-literal-constant>

Notes:

C1009: <k> is without kind parameters.
subclass_names = ['Signed_Int_Literal_Constant'][source]
class fparser.two.Fortran2003.Position_Edit_Desc(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2003 rule R1013:

position-edit-desc is T n
                   or TL n
                   or TR n
                   or n X

where n is a positive integer.

If the extensions list includes the string ‘x-format’ then ‘X’ without a preceeding integer is also matched. This is a common extension in Fortran compilers.

subclass_names = [][source]
use_names = ['N'][source]
static match(string)[source]

Check whether the input matches the rule.

param str string: contains the Fortran that we are trying to match. :return: None if there is no match, otherwise a tuple of size 2 either containing a string which is one of “T”, “TL” or “TR”, followed by an N class, or containing an N class, or None, followed by an “X”. :rtype: NoneType, (str, fparser.two.Fortran2003.N), (fparser.two.Fortran2003.N, str) or (NoneType, str)

tostr()[source]
Returns:

parsed representation of a Position Edit Descriptor

Return type:

str

Raises:
  • InternalError – if the length of the internal items list is not 2.

  • InternalError – if the second entry of the internal items list has no content.

class fparser.two.Fortran2003.N(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<n> = <int-literal-constant> == <digit-string>

Subject to:

C1010, C1011: <n> is positive and without kind parameter.
subclass_names = ['Digit_String'][source]
class fparser.two.Fortran2003.Sign_Edit_Desc(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<sign-edit-desc> = SS
                   | SP
                   | S
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Blank_Interp_Edit_Desc(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<blank-interp-edit-desc> = BN
                         | BZ
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Round_Edit_Desc(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<round-edit-desc> = RU
                    | RD
                    | RZ
                    | RN
                    | RC
                    | RP
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Decimal_Edit_Desc(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<decimal-edit-desc> = DC
DP
subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Char_String_Edit_Desc(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<char-string-edit-desc> = <char-literal-constant>

subclass_names = ['Char_Literal_Constant'][source]
class fparser.two.Fortran2003.Main_Program(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

Fortran 2003 rule R1101:

main-program is program-stmt
                [ specification-part ]
                [ execution-part ]
                [ internal-subprogram-part ]
                end-program-stmt

This class does not cater for the case where there is no program-stmt. The separate Main_Program0() class matches this situation. See Class Program() method match() for how this is implemented.

C1101 In a main-program, the execution-part shall not contain a RETURN statement or an ENTRY statement. This is currently not checked, see issue #140.

C1102 The program-name may be included in the end-program-stmt only if the optional program-stmt is used and, if included, shall be identical to the program-name specified in the program-stmt.

C1103 An automatic object shall not appear in the specification-part (R204) of a main program. This is currently not checked, see issue #140.

subclass_names = [][source]
use_names = ['Program_Stmt', 'Specification_Part', 'Execution_Part', 'Internal_Subprogram_Part', 'End_Program_Stmt'][source]
static match(reader)[source]

Implements the matching of a main program which has a Program statement. See class Main_Program0 for matching without a Program Statement. Matching uses BlockBase as it conforms to the start/end with optional content pattern. match_names is set to True so that different names e.g. program x and end program y will not match.

Parameters:

reader (fparser.common.readfortran.FortranReaderBase) – the Fortran reader containing the line(s) of code that we are trying to match

Returns:

None if there is not match or, if there is a match, a tuple containing a single list, with minimum size 2 and maximum size 5, which contains instances of the classes that have matched. The first entry in the list will be a Program_Stmt and the last entry in the list will be an End_Program_Stmt. In-between these two instances will be an optional Specification_Part followed by an optional Execution_Part followed by an optional Internal_Subprogram_Part.

Return type:

NoneType or ([fparser.two.Fortran2003.Program_Stmt, optional fparser.two.Fortran2003.Specification_Part, optional fparser.two.Fortran2003.Execution_Part, optional fparser.two.Fortran2003.Internal_Subprogram_Part, fparser.two.Fortran2003.End_Program_Stmt])

class fparser.two.Fortran2003.Main_Program0(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

Rule 1101 specifies that the opening ‘program-stmt’ is optional. This class handles the special case when it is not supplied and thus matches on:

<main-program> =
                 [ <specification-part> ]
                 [ <execution-part> ]
                 [ <internal-subprogram-part> ]
                 <end-program-stmt>

C1102 The program-name may be included in the end-program-stmt only if the optional program-stmt is used and, if included, shall be identical to the program-name specified in the program-stmt.

In this class an end program name is not allowed due to C1102.

subclass_names = [][source]
use_names = ['Program_Stmt', 'Specification_Part', 'Execution_Part', 'Internal_Subprogram_Part', 'End_Program_Stmt'][source]
static match(reader)[source]

Attempts to match the content in the reader with a program that is missing the optional opening program-stmt (R1101). If the match is successful, a symbol table named “fparser2:main_program” is also created.

Parameters:

reader (str or instance of FortranReaderBase) – Content to check for match

Returns:

2-tuple of (list of matched classes, None) or None if no match is found.

Return type:

(list of matched classes, None) or NoneType

class fparser.two.Fortran2003.Program_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase, fparser.two.utils.ScopingRegionMixin

Fortran 2003 rule R1102:

program-stmt is PROGRAM program-name
subclass_names = [][source]
use_names = ['Program_Name'][source]
static match(string)[source]

Implements the matching for a Program Statement. Makes use of WORDClsBase, as the required match is a string followed by a class. The class is made compulsory for the match as the PROGRAM keyword is not valid without a program name.

Parameters:

string (str) – Fortran code to check for a match

Returns:

None if there is no match or, if there is a match, a tuple of size 2 with the first entry being the string ‘PROGRAM’ and the second entry being a Name class containing the name of the program.

Return type:

NoneType or ( str, fparser.two.Fortran2003.Name )

get_name()[source]

Provides the program name as an instance of the Name class.

Returns:

the program name as a Name class

Return type:

Name

get_start_name()[source]

Provides the program name as a string. This is used for matching with the equivalent end program name if there is one.

Returns:

the program name as a string

Return type:

str

class fparser.two.Fortran2003.End_Program_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-program-stmt> = END [ PROGRAM [ <program-name> ] ]

subclass_names = [][source]
use_names = ['Program_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Module(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<module> = <module-stmt>
               [ <specification-part> ]
               [ <module-subprogram-part> ]
               <end-module-stmt>
subclass_names = [][source]
use_names = ['Module_Stmt', 'Specification_Part', 'Module_Subprogram_Part', 'End_Module_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Module_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase, fparser.two.utils.ScopingRegionMixin

<module-stmt> = MODULE <module-name>

subclass_names = [][source]
use_names = ['Module_Name'][source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

get_name()[source]
class fparser.two.Fortran2003.End_Module_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-module-stmt> = END [ MODULE [ <module-name> ] ]

subclass_names = [][source]
use_names = ['Module_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Module_Subprogram_Part(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<module-subprogram-part> = <contains-stmt>
                               <module-subprogram>
                               [ <module-subprogram> ]...
subclass_names = [][source]
use_names = ['Contains_Stmt', 'Module_Subprogram'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Module_Subprogram(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<module-subprogram> = <function-subprogram>
                      | <subroutine-subprogram>
subclass_names = ['Function_Subprogram', 'Subroutine_Subprogram'][source]
class fparser.two.Fortran2003.Use_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

Fortran 2003 rule R1109:

use-stmt is USE [ [ , module-nature ] :: ] module-name [ , rename-list ]
         or USE [ [ , module-nature ] :: ] module-name ,
             ONLY : [ only-list ]
subclass_names = [][source]
use_names = ['Module_Nature', 'Module_Name', 'Rename_List', 'Only_List'][source]
static match(string)[source]

Wrapper for the match method that captures any successfully-matched use statements in the symbol table associated with the current scope (if there is one).

TODO #379 - currently operator imports/renaming are not captured in

the symbol table.

Parameters:

string (str) – Fortran code to check for a match.

Returns:

5-tuple containing strings and instances of the classes describing a module (optional module nature, optional double colon delimiter, mandatory module name, optional “ONLY” specification and optional “Rename” or “Only” list) or None if the match fails.

Return type:

5-tuple of objects (module name and 4 optional) or NoneType

Raises:

InternalError – if an Only_List is found to contain anything other than Name or Rename objects.

static _match(string)[source]
Parameters:

string (str) – Fortran code to check for a match.

Returns:

5-tuple containing strings and instances of the classes describing a module (optional module nature, optional double colon delimiter, mandatory module name, optional “ONLY” specification and optional “Rename” or “Only” list).

Return type:

5-tuple of objects (module name and 4 optional)

tostr()[source]
Returns:

parsed representation of “USE” statement

Return type:

string

Raises:
  • InternalError – if items array is not the expected size

  • InternalError – if items array[2] is not a string or is an empty string

  • InternalError – if items array[3] is ‘None’ as it should be a string

class fparser.two.Fortran2003.Module_Nature(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

R1110:

<module-nature> = INTRINSIC
                  | NON_INTRINSIC
subclass_names = [][source]
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

keyword describing module nature (“INTRINSIC” or “NON_INTRINSIC”) or nothing if no match is found

Return type:

string

class fparser.two.Fortran2003.Rename(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Class defining Rule #R1111:

rename is local-name => use-name
       or OPERATOR(local-defined-operator) => OPERATOR(use-defined-operator)

where:

local-defined-operator is defined-uary-op or defined-binary-op
defined-binary-op is .letter [letter] ... .
subclass_names = [][source]
use_names = ['Local_Name', 'Use_Name', 'Local_Defined_Operator', 'Use_Defined_Operator'][source]
static match(string)[source]
Parameters:

string (str) – the string to attempt to match.

Returns:

three tuple containing description, local name, remote name.

Return type:

Optional[ Tuple[Optional[str], fparser.two.Fortran2003.Local_Name | fparser.two.Fortran2003.Local_Defined_Operator, fparser.two.Fortran2003.Use_Name | fparser.two.Fortran2003.Use_Defined_Operator]]

tostr()[source]
Returns:

the string representation of this Rename object.

Return type:

str

class fparser.two.Fortran2003.Only(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<only> = <generic-spec>
         | <only-use-name>
         | <rename>
subclass_names = ['Generic_Spec', 'Only_Use_Name', 'Rename'][source]
class fparser.two.Fortran2003.Only_Use_Name(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<only-use-name> = <name>
subclass_names = ['Name'][source]
class fparser.two.Fortran2003.Local_Defined_Operator(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<local-defined-operator> = <defined-unary-op>
                           | <defined-binary-op>
subclass_names = ['Defined_Unary_Op', 'Defined_Binary_Op'][source]
class fparser.two.Fortran2003.Use_Defined_Operator(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<use-defined-operator> = <defined-unary-op>
                         | <defined-binary-op>
subclass_names = ['Defined_Unary_Op', 'Defined_Binary_Op'][source]
class fparser.two.Fortran2003.Block_Data(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

::
<block-data> = <block-data-stmt>

[ <specification-part> ] <end-block-data-stmt>

subclass_names = [][source]
use_names = ['Block_Data_Stmt', 'Specification_Part', 'End_Block_Data_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Block_Data_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<block-data-stmt> = BLOCK DATA [ <block-data-name> ]
subclass_names = [][source]
use_names = ['Block_Data_Name'][source]
static match(string)[source]
tostr()[source]
get_name()[source]
class fparser.two.Fortran2003.End_Block_Data_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-block-data-stmt> = END [ BLOCK DATA [ <block-data-name> ] ]
subclass_names = [][source]
use_names = ['Block_Data_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Interface_Block(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<interface-block> = <interface-stmt>
                        [ <interface-specification> ]...
                        <end-interface-stmt>
subclass_names = [][source]
use_names = ['Interface_Stmt', 'Interface_Specification', 'End_Interface_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Interface_Specification(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<interface-specification> = <interface-body>
                            | <procedure-stmt>
subclass_names = ['Interface_Body', 'Procedure_Stmt'][source]
class fparser.two.Fortran2003.Interface_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<interface-stmt> = INTERFACE [ <generic-spec> ]
                   | ABSTRACT INTERFACE

Attributes:

items : ({Generic_Spec, 'ABSTRACT'},)
subclass_names = [][source]
use_names = ['Generic_Spec'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.End_Interface_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-interface-stmt> = END INTERFACE [ <generic-spec> ]

Attributes:

items : (Generic_Spec, )
subclass_names = [][source]
use_names = ['Generic_Spec'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Function_Body(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<function-body> = <function-stmt>
                    [ <specification-part> ]
                  <end-function-stmt>
subclass_names = [][source]
use_names = ['Function_Stmt', 'Specification_Part', 'End_Function_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Subroutine_Body(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<subroutine-body> = <subroutine-stmt>
                    [ <specification-part> ]
                  <end-subroutine-stmt>
subclass_names = [][source]
use_names = ['Subroutine_Stmt', 'Specification_Part', 'End_Subroutine_Stmt'][source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Interface_Body(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<interface-body> = <function-body> | <subroutine-body>

See also fparser.two.Fortran2003.Function_Body and fparser.two.Fortran2003.Subroutine_Body

subclass_names = ['Function_Body', 'Subroutine_Body'][source]
use_names = [][source]
class fparser.two.Fortran2003.Procedure_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<procedure-stmt> = [ MODULE ] PROCEDURE <procedure-name-list>

Attributes:

items : (Procedure_Name_List, )
subclass_names = [][source]
use_names = ['Procedure_Name_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Generic_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<generic-spec> = <generic-name>
                 | OPERATOR ( <defined-operator> )
                 | ASSIGNMENT ( = )
                 | <dtio-generic-spec>

Attributes:

items : ({'OPERATOR', 'ASSIGNMENT'}, {Defined_Operator, '='})
subclass_names = ['Generic_Name', 'Dtio_Generic_Spec'][source]
use_names = ['Defined_Operator'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Dtio_Generic_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<dtio-generic-spec> = READ ( FORMATTED )
                      | READ ( UNFORMATTED )
                      | WRITE ( FORMATTED )
                      | WRITE ( UNFORMATTED )

Attributes:

items : (str, )
subclass_names = [][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Import_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

Fortran 2003 rule R1209:

import-stmt is IMPORT [[ :: ] import-name-list ]

C1210 (R1209) The IMPORT statement is allowed only in an interface-body. Note, this constraint is not currently enforced.

C1211 (R1209) Each import-name shall be the name of an entity in the host scoping unit. This constraint is not currently enforced and can not be generally enforced as the name may come from a use statement without an only clause.

subclass_names = [][source]
use_names = ['Import_Name_List'][source]
tostr[source]
static match(string)[source]

Implements the matching for the import-stmt rule.

Makes use of the WORDClsBase base class.

Parameters:

string (str) – the string to match.

Returns:

None if there is no match, otherwise a tuple of size 2 containing the string IMPORT as the first entry and an object of type Import_Name_List if names are specified in the string or None if not.

Return type:

None, or (str, fparser.two.Fortran2003.Import_Name_List) or (str, None)

class fparser.two.Fortran2003.External_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<external-stmt> = EXTERNAL [ :: ] <external-name-list>
subclass_names = [][source]
use_names = ['External_Name_List'][source]
tostr[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Procedure_Declaration_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<procedure-declaration-stmt> = PROCEDURE ( [ <proc-interface> ] )
    [ [ , <proc-attr-spec> ]... :: ] <proc-decl-list>

Attributes:

items : (Proc_Interface, Proc_Attr_Spec_List, Proc_Decl_List)
subclass_names = [][source]
use_names = ['Proc_Interface', 'Proc_Attr_Spec_List', 'Proc_Decl_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Proc_Interface(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<proc-interface> = <interface-name>
                   | <declaration-type-spec>
subclass_names = ['Interface_Name', 'Declaration_Type_Spec'][source]
class fparser.two.Fortran2003.Proc_Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<proc-attr-spec> = <access-spec>
                   | <proc-language-binding-spec>
                   | INTENT ( <intent-spec> )
                   | OPTIONAL
                   | POINTER
                   | PROTECTED
                   | SAVE

Attributes:

items : ({'INTENT', 'OPTIONAL', 'POINTER', 'PROTECTED', 'SAVE'}, Intent_Spec)
subclass_names = ['Access_Spec', 'Proc_Language_Binding_Spec'][source]
use_names = ['Intent_Spec'][source]
static match(string)[source]

Matches procedure arguments.

Parameters:

string (str) – Candidate string.

Returns:

Discovered arguments.

Return type:

tuple, str or None

tostr()[source]
class fparser.two.Fortran2003.Proc_Decl(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<proc-decl> = <procedure-entity-name> [ => <null-init> ]

Attributes:

items : (Procedure_Entity_Name, Null_Init)
subclass_names = ['Procedure_Entity_Name'][source]
use_names = ['Null_Init'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Interface_Name(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<interface-name> = <name>

subclass_names = ['Name'][source]
class fparser.two.Fortran2003.Intrinsic_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

<intrinsic-stmt> = INTRINSIC [ :: ] <intrinsic-procedure-name-list>
subclass_names = [][source]
use_names = ['Intrinsic_Procedure_Name_List'][source]
tostr[source]
static match(string)[source]

Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.

Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.

The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.

Parameters:
  • keyword (fparser.two.pattern_tools.Pattern, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.

  • cls (a subclass of fparser.two.utils.Base) – the class to match.

  • string (str) – Text that we are trying to match.

  • colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.

  • require_cls (bool) – whether content for cls is required or not.

Returns:

None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).

Return type:

Optional[Tupe[Str, Optional[Cls]]]

class fparser.two.Fortran2003.Function_Reference(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

<function-reference> = <procedure-designator>

( [ <actual-arg-spec-list> ] )

subclass_names = [][source]
use_names = ['Procedure_Designator', 'Actual_Arg_Spec_List'][source]
static match(string)[source]
Parameters:
  • lhs_cls (str | class) – the class to match with the lhs.

  • rhs_cls (str | class) – the class to match with the rhs.

  • string (str) – the string to attempt to match.

  • upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.

  • require_rhs (bool) – whether the rhs (the part within parentheses) must be present.

Returns:

a tuple containing the lhs and rhs matches or None if there is no match.

Return type:

Optional[Tuple[fparser.two.utils.Base, Optional[fparser.two.utils.Base]]]

class fparser.two.Fortran2003.Intrinsic_Name(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

Represents the name of a Fortran intrinsic function.

All generic intrinsic names are specified as keys in the generic_function_names dictionary, with their values indicating the minimum and maximum number of arguments allowed for this intrinsic function. A -1 indicates an unlimited number of arguments. The names are split into the categories specified in the Fortran2003 specification document.

All specific intrinsic names (which have a different name to their generic counterpart) are specified as keys in the specific_function_names dictionary, with their values indicating which generic function they are associated with.

numeric_names[source]
mathematical_names[source]
character_names[source]
kind_names[source]
miscellaneous_type_conversion_names[source]
numeric_inquiry_names[source]
array_inquiry_names[source]
other_inquiry_names[source]
bit_manipulation_names[source]
floating_point_manipulation_names[source]
vector_and_matrix_multiply_names[source]
array_reduction_names[source]
array_construction_names[source]
array_location_names[source]
null_names[source]
allocation_transfer_names[source]
random_number_names[source]
system_environment_names[source]
specific_function_names[source]
generic_function_names[source]
function_names[source]
subclass_names = [][source]
static match(string)[source]

Attempt to match the input string with the intrinsic function names defined in generic_function_names or specific_function_names. If there is a match the resultant string will be converted to upper case.

Parameters:

string (str) – The pattern to be matched.

Returns:

A tuple containing the matched string (converted to upper case) if there is a match or None if there is not.

Return type:

(str,) or NoneType

class fparser.two.Fortran2003.Intrinsic_Function_Reference(string, parent_cls=None)[source]

Bases: fparser.two.utils.CallBase

Represents Fortran intrinsics:

function-reference is intrinsic-name ( [ actual-arg-spec-list ] )
subclass_names = [][source]
use_names = ['Intrinsic_Name', 'Actual_Arg_Spec_List'][source]
static match(string)[source]

Match the string as an intrinsic function. Also check that the number of arguments provided matches the number expected by the intrinsic.

Parameters:

string (str) – the string to match with the pattern rule.

Returns:

a tuple of size 2 containing the name of the intrinsic and its arguments if there is a match, or None if there is not.

Return type:

Tuple[fparser.two.Fortran2003.Intrinsic_Name, fparser.two.Fortran2003.Actual_Arg_Spec_List] | NoneType

Raises:

InternalSyntaxError – If the number of arguments provided does not match the number of arguments expected by the intrinsic and there are no wildcard imports that could be bringing a routine (that overrides it) into scope.

class fparser.two.Fortran2003.Call_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<call-stmt> = CALL <procedure-designator>
              [ ( [ <actual-arg-spec-list> ] ) ]

Attributes:

items : (Procedure_Designator, Actual_Arg_Spec_List)
subclass_names = [][source]
use_names = ['Procedure_Designator', 'Actual_Arg_Spec_List'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Procedure_Designator(string, parent_cls=None)[source]

Bases: fparser.two.utils.BinaryOpBase

<procedure-designator> = <procedure-name>
                         | <proc-component-ref>
                         | <data-ref> % <binding-name>
subclass_names = ['Procedure_Name', 'Proc_Component_Ref'][source]
use_names = ['Data_Ref', 'Binding_Name'][source]
static match(string)[source]

Matches the binary-op-base rule.

If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.

If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.

if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.

Parameters:
  • lhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the lhs text.

  • op_pattern (str or fparser.two.pattern_tools.Pattern) – the pattern to match.

  • rhs_cls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched to the rhs text.

  • string (str) – the string to match with the pattern and lhs and rhs rules.

  • right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).

  • exclude_op_pattern (fparser.two.pattern_tools.Pattern) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.

Returns:

a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.

Return type:

(fparser.two.utils.Base, str, fparser.two.utils.Base) or NoneType

class fparser.two.Fortran2003.Actual_Arg_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.KeywordValueBase

<actual-arg-spec> = [ <keyword> = ] <actual-arg>

subclass_names = ['Actual_Arg'][source]
use_names = ['Keyword'][source]
static match(string)[source]

Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.

Parameters:
  • lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.

  • rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.

  • string (str) – text to be matched.

  • require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.

  • upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.

Returns:

instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.

Return type:

2-tuple of objects or NoneType

class fparser.two.Fortran2003.Actual_Arg(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<actual-arg> = <expr>
             | <variable>
             | <procedure-name>
             | <proc-component-ref>
             | <alt-return-spec>
subclass_names = ['Expr', 'Procedure_Name', 'Proc_Component_Ref', 'Alt_Return_Spec', 'Variable'][source]
class fparser.two.Fortran2003.Alt_Return_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<alt-return-spec> = * <label>
subclass_names = [][source]
use_names = ['Label'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Function_Subprogram(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<function-subprogram> = <function-stmt>
                           [ <specification-part> ]
                           [ <execution-part> ]
                           [ <internal-subprogram-part> ]
                        <end-function-stmt>
subclass_names = [][source]
use_names = ['Function_Stmt', 'Specification_Part', 'Execution_Part', 'Internal_Subprogram_Part',...[source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

class fparser.two.Fortran2003.Function_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.ScopingRegionMixin

<function-stmt> = [ <prefix> ] FUNCTION <function-name>
                  ( [ <dummy-arg-name-list> ] ) [ <suffix> ]

C1242 (R1227) A prefix shall not specify ELEMENTAL if proc-language-binding-spec appears in the function-stmt or subroutine-stmt. The spec associates this constraint with R1227 but it needs to be checked here.

subclass_names = [][source]
use_names = ['Prefix', 'Function_Name', 'Dummy_Arg_Name_List', 'Suffix'][source]
static match(string)[source]
tostr()[source]
get_name()[source]
Returns:

the function name.

Return type:

Name

class fparser.two.Fortran2003.Proc_Language_Binding_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<proc-language-binding-spec> = <language-binding-spec>

subclass_names = ['Language_Binding_Spec'][source]
class fparser.two.Fortran2003.Dummy_Arg_Name(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<dummy-arg-name> = <name>

subclass_names = ['Name'][source]
class fparser.two.Fortran2003.Prefix(string, parent_cls=None)[source]

Bases: fparser.two.utils.SequenceBase

Fortran2003 rule R1227:

prefix is prefix-spec [ prefix-spec ] ...

C1240 (R1227) A prefix shall contain at most one of each prefix-spec. Checked below.

C1241 (R1227) A prefix shall not specify both ELEMENTAL and RECURSIVE. Checked below.

C1242 (R1227) A prefix shall not specify ELEMENTAL if proc-language-binding-spec appears in the function-stmt or subroutine-stmt. This constraint can not be checked here, it is checked in R1224 and R1232.

subclass_names = [][source]
static match(string)[source]

Match a space separated list of Prefix_Spec objects. Objects may be separated by 1 or more spaces.

Returns:

A tuple of size 2 containing the separator and a tuple containing one or more Prefix_Spec objects if there is a match and None if not.

Return type:

Optional[Tuple[Str, Tuple[fparser.two.Fortran2003.Prefix_Spec, …]]]

class fparser.two.Fortran2003.Prefix_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.STRINGBase

<prefix-spec> = <declaration-type-spec>
                | ELEMENTAL
                | IMPURE
                | MODULE
                | PURE
                | RECURSIVE
subclass_names = ['Declaration_Type_Spec'][source]
keywords = ['ELEMENTAL', 'IMPURE', 'MODULE', 'PURE', 'RECURSIVE'][source]
static match(string)[source]

Matches procedure prefixes.

Parameters:

string (str) – Candidate string.

Returns:

Discovered prefix.

Return type:

str

class fparser.two.Fortran2003.Suffix(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

<suffix> = <proc-language-binding-spec> [ RESULT ( <result-name> ) ]
           | RESULT ( <result-name> ) [ <proc-language-binding-spec> ]
subclass_names = ['Proc_Language_Binding_Spec'][source]
use_names = ['Result_Name'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.End_Function_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-function-stmt> = END [ FUNCTION [ <function-name> ] ]

subclass_names = [][source]
use_names = ['Function_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Subroutine_Subprogram(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

<subroutine-subprogram> = <subroutine-stmt>
                             [ <specification-part> ]
                             [ <execution-part> ]
                             [ <internal-subprogram-part> ]
                          <end-subroutine-stmt>
subclass_names = [][source]
use_names = ['Subroutine_Stmt', 'Specification_Part', 'Execution_Part', 'Internal_Subprogram_Part',...[source]
static match(reader)[source]

Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)

Parameters:
  • startcls (type) – the class marking the beginning of the block

  • subclasses (list) – list of classes that can be children of the block.

  • endcls (type) – the class marking the end of the block.

  • reader (str or instance of FortranReaderBase) – content to check for match.

  • match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.

  • match_names (bool) – TBD

  • match_name_classes (tuple) – TBD

  • enable_do_label_construct_hook (bool) – TBD

  • enable_if_construct_hook (bool) – TBD

  • enable_where_construct_hook (bool) – TBD

  • strict_order (bool) – whether to enforce the order of the given subclasses.

  • strict_match_names (bool) – if start name present, end name must exist and match.

Returns:

instance of startcls or None if no match is found

Return type:

startcls

fparser.two.Fortran2003.c1242_valid(prefix, binding_spec)[source]

If prefix and binding-spec exist then check whether they conform to constraint C1242 - “A prefix shall not specify ELEMENTAL if proc-language-binding-spec appears in the function-stmt or subroutine-stmt.”

Parameters:
Type:

fparser.two.Fortran2003.Prefix or NoneType

Returns:

False if prefix and binding-spec break constraint C1242, otherwise True.

Return type:

bool

class fparser.two.Fortran2003.Subroutine_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.ScopingRegionMixin

Fortran2003 rule R1232:

subroutine-stmt is [ prefix ] SUBROUTINE subroutine-name [ ( [ dummy-arg-list ] ) [ proc-language-binding-spec ] ]

C1242 (R1227) A prefix shall not specify ELEMENTAL if proc-language-binding-spec appears in the function-stmt or subroutine-stmt. The spec associates this constraint with R1227 but it needs to be checked here.

subclass_names = [][source]
use_names = ['Prefix', 'Subroutine_Name', 'Dummy_Arg_List', 'Proc_Language_Binding_Spec'][source]
static match(string)[source]
get_name()[source]
tostr()[source]
class fparser.two.Fortran2003.Dummy_Arg(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

<dummy-arg> = <dummy-arg-name>
              | *
subclass_names = ['Dummy_Arg_Name'][source]
static match(string)[source]
class fparser.two.Fortran2003.End_Subroutine_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

<end-subroutine-stmt> = END [ SUBROUTINE [ <subroutine-name> ] ]

subclass_names = [][source]
use_names = ['Subroutine_Name'][source]
static match(string)[source]

Attempts to match the supplied string as a form of ‘END xxx’ statement.

Parameters:
  • stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.

  • stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).

  • string (str) – the string to attempt to match.

  • require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.

Returns:

2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.

Return type:

Optional[ Tuple[Optional[str],

class fparser.two.Fortran2003.Entry_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<entry-stmt> = ENTRY <entry-name> [ ( [ <dummy-arg-list> ] ) [ <suffix> ] ]

Attributes:

items : (Entry_Name, Dummy_Arg_List, Suffix)
subclass_names = [][source]
use_names = ['Entry_Name', 'Dummy_Arg_List', 'Suffix'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Return_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<return-stmt> = RETURN [ <scalar-int-expr> ]

subclass_names = [][source]
use_names = ['Scalar_Int_Expr'][source]
static match(string)[source]
tostr()[source]
class fparser.two.Fortran2003.Contains_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.STRINGBase

<contains-stmt> = CONTAINS

subclass_names = [][source]
static match(string)[source]

Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.

The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:

from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)

Parameters:
  • pattern (list, tuple, str or an re expression) – the pattern to match

  • string (str) – the string to match with the pattern

Returns:

None if there is no match, or a tuple containing the matched string in upper case.

Return type:

NoneType or ( str )

class fparser.two.Fortran2003.Stmt_Function_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase

<stmt-function-stmt>
= <function-name> ( [ <dummy-arg-name-list> ] ) = Scalar_Expr
subclass_names = [][source]
use_names = ['Function_Name', 'Dummy_Arg_Name_List', 'Scalar_Expr'][source]
static match(string)[source]
tostr()[source]
fparser.two.Fortran2003.ClassType[source]
fparser.two.Fortran2003._names[source]
fparser.two.Fortran2003.my_cls[source]
fparser.two.Fortran2003.classes[source]
fparser.two.Fortran2003.__all__[source]